home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import sys
- import os
- import tempfile
- from calibre.ebooks.rtf2xml import copy
-
- class Fonts:
-
- def __init__(self, in_file, bug_handler, default_font_num, copy = None, run_level = 1):
- self._Fonts__file = in_file
- self._Fonts__bug_handler = bug_handler
- self._Fonts__copy = copy
- self._Fonts__default_font_num = default_font_num
- self._Fonts__write_to = tempfile.mktemp()
- self._Fonts__run_level = run_level
-
-
- def __initiate_values(self):
- self._Fonts__special_font_dict = {
- 'Symbol': 0,
- 'Wingdings': 0,
- 'Zapf Dingbats': 0 }
- self._Fonts__special_font_list = [
- 'Symbol',
- 'Wingdings',
- 'Zapf Dingbats']
- self._Fonts__state = 'default'
- self._Fonts__state_dict = {
- 'default': self._Fonts__default_func,
- 'font_table': self._Fonts__font_table_func,
- 'after_font_table': self._Fonts__after_font_table_func,
- 'font_in_table': self._Fonts__font_in_table_func }
- self._Fonts__font_table = { }
- self._Fonts__wrote_ind_font = 0
-
-
- def __default_func(self, line):
- if self._Fonts__token_info == 'mi<mk<fonttb-beg':
- self._Fonts__state = 'font_table'
-
- self._Fonts__write_obj.write(line)
-
-
- def __font_table_func(self, line):
- if self._Fonts__token_info == 'mi<mk<fonttb-end':
- self._Fonts__state = 'after_font_table'
- elif self._Fonts__token_info == 'mi<mk<fontit-beg':
- self._Fonts__state = 'font_in_table'
- self._Fonts__font_num = self._Fonts__default_font_num
- self._Fonts__text_line = ''
-
-
-
- def __font_in_table_func(self, line):
- if self._Fonts__token_info == 'mi<mk<fontit-end':
- self._Fonts__wrote_ind_font = 1
- self._Fonts__state = 'font_table'
- self._Fonts__text_line = self._Fonts__text_line[:-1]
- self._Fonts__font_table[self._Fonts__font_num] = self._Fonts__text_line
- self._Fonts__write_obj.write('mi<tg<empty-att_<font-in-table<name>%s<num>%s\n' % (self._Fonts__text_line, self._Fonts__font_num))
- elif self._Fonts__token_info == 'cw<ci<font-style':
- self._Fonts__font_num = line[20:-1]
- elif self._Fonts__token_info == 'tx<nu<__________' or self._Fonts__token_info == 'tx<ut<__________':
- self._Fonts__text_line += line[17:-1]
- elif self._Fonts__token_info == 'mi<mk<fonttb-end':
- self._Fonts__found_end_font_table_func()
- self._Fonts__state = 'after_font_table'
-
-
-
- def __found_end_font_table_func(self):
- if not self._Fonts__wrote_ind_font:
- self._Fonts__write_obj.write('mi<tg<empty-att_<font-in-table<name>Times<num>0\n')
-
-
-
- def __after_font_table_func(self, line):
- if self._Fonts__token_info == 'cw<ci<font-style':
- font_num = line[20:-1]
- font_name = self._Fonts__font_table.get(font_num)
- if font_name == None:
- if self._Fonts__run_level > 3:
- msg = 'no value for %s in self.__font_table\n' % font_num
- raise self._Fonts__bug_handler, msg
- self._Fonts__run_level > 3
- elif font_name in self._Fonts__special_font_list:
- self._Fonts__special_font_dict[font_name] = 1
-
- self._Fonts__write_obj.write('cw<ci<font-style<nu<%s\n' % font_name)
- else:
- self._Fonts__write_obj.write(line)
-
-
- def convert_fonts(self):
- self._Fonts__initiate_values()
- read_obj = open(self._Fonts__file, 'r')
- self._Fonts__write_obj = open(self._Fonts__write_to, 'w')
- line_to_read = 1
- while line_to_read:
- line_to_read = read_obj.readline()
- line = line_to_read
- self._Fonts__token_info = line[:16]
- action = self._Fonts__state_dict.get(self._Fonts__state)
- if action == None:
- sys.stderr.write('no no matching state in module fonts.py\n')
- sys.stderr.write(self._Fonts__state + '\n')
-
- action(line)
- read_obj.close()
- self._Fonts__write_obj.close()
- default_font_name = self._Fonts__font_table.get(self._Fonts__default_font_num)
- if not default_font_name:
- default_font_name = 'Not Defined'
-
- self._Fonts__special_font_dict['default-font'] = default_font_name
- copy_obj = copy.Copy(bug_handler = self._Fonts__bug_handler)
- if self._Fonts__copy:
- copy_obj.copy_file(self._Fonts__write_to, 'fonts.data')
-
- copy_obj.rename(self._Fonts__write_to, self._Fonts__file)
- os.remove(self._Fonts__write_to)
- return self._Fonts__special_font_dict
-
-
-