######################################################################### # # # # # copyright 2002 Paul Henry Tremblay # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # # General Public License for more details. # # # # # ######################################################################### import sys, os from ebook_converter.ebooks.rtf2xml import copy from ebook_converter.ptempfile import better_mktemp from . import open_for_read, open_for_write class Pict: """Process graphic information""" def __init__(self, in_file, bug_handler, out_file, copy=None, orig_file=None, run_level=1, ): self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy self.__run_level = run_level self.__write_to = better_mktemp() self.__bracket_count = 0 self.__ob_count = 0 self.__cb_count = 0 self.__pict_count = 0 self.__in_pict = False self.__already_found_pict = False self.__orig_file = orig_file self.__initiate_pict_dict() self.__out_file = out_file def __initiate_pict_dict(self): self.__pict_dict = { 'ob 1: sys.stderr.write('Removing files from old pict directory...\n') all_files = os.listdir(self.__dir_name) for the_file in all_files: the_file = os.path.join(self.__dir_name, the_file) try: os.remove(the_file) except OSError: pass if self.__run_level > 1: sys.stderr.write('Files removed.\n') def __create_pict_file(self): """Create a file for all the pict data to be written to. """ self.__pict_file = os.path.join(self.__dir_name, 'picts.rtf') self.__write_pic_obj = open_for_write(self.__pict_file, append=True) def __in_pict_func(self, line): if self.__cb_count == self.__pict_br_count: self.__in_pict = False self.__write_pic_obj.write("}\n") return True else: action = self.__pict_dict.get(self.__token_info) if action: self.__write_pic_obj.write(action(line)) return False def __default(self, line, write_obj): """Determine if each token marks the beginning of pict data. If it does, create a new file to write data to (if that file has not already been created.) Set the self.__in_pict flag to true. If the line does not contain pict data, return 1 """ """ $pict_count++; $pict_count = sprintf("%03d", $pict_count); print OUTPUT "dv$pict_count\n"; """ if self.__token_info == 'cw%03d\n" % self.__pict_count) write_obj.write('mi%03d\n' % self.__pict_count) write_obj.write('mi