From 8ad2ed33c42f4a8d3c3c06fa166247fa2864cb32 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 15 Sep 2009 11:00:37 -0600 Subject: [PATCH] IGN:RTF Input: Make it a little more efficient --- src/calibre/ebooks/rtf/input.py | 18 +++--------------- src/calibre/ebooks/rtf2xml/pict.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/calibre/ebooks/rtf/input.py b/src/calibre/ebooks/rtf/input.py index e1c1fd4a22..d749fbe797 100644 --- a/src/calibre/ebooks/rtf/input.py +++ b/src/calibre/ebooks/rtf/input.py @@ -19,17 +19,10 @@ class InlineClass(etree.XSLTExtension): self.colors = [] def execute(self, context, self_node, input_node, output_parent): - classes = [] + classes = ['none'] for x in self.FMTS: - cls = x if input_node.get(x, None) == 'true' else 'no-'+x - classes.append(cls) - none = True - for x in self.FMTS: - if 'no-'+x not in classes: - none = False - break - if none: - classes = ['none'] + if input_node.get(x, None) == 'true': + classes.append(x) fs = input_node.get('font-size', False) if fs: if fs not in self.font_sizes: @@ -142,19 +135,14 @@ class RTFInput(InputFormatPlugin): } span.italics { font-style: italic } - span.no-italics { font-style: normal } span.bold { font-weight: bold } - span.no-bold { font-weight: normal } span.small-caps { font-variant: small-caps } - span.no-small-caps { font-variant: normal } span.underlined { text-decoration: underline } - span.no-underlined { text-decoration: none } span.strike-through { text-decoration: line-through } - span.no-strike-through { text-decoration: none } ''') css += '\n'+'\n'.join(font_size_classes) diff --git a/src/calibre/ebooks/rtf2xml/pict.py b/src/calibre/ebooks/rtf2xml/pict.py index 767efda273..3a1044520e 100755 --- a/src/calibre/ebooks/rtf2xml/pict.py +++ b/src/calibre/ebooks/rtf2xml/pict.py @@ -43,21 +43,26 @@ class Pict: self.__out_file = out_file # this is left over self.__no_ask = 1 + def __initiate_pict_dict(self): self.__pict_dict = { 'ob 1: sys.stderr.write('Files removed.\n') + def __create_pict_file(self): """Create a file for all the pict data to be written to. """ @@ -104,6 +110,7 @@ class Pict: write_pic_obj = open(self.__pict_file, 'w') write_pic_obj.close() self.__write_pic_obj = open(self.__pict_file, 'a') + def __in_pict_func(self, line): if self.__cb_count == self.__pict_br_count: self.__in_pict = 0 @@ -115,6 +122,7 @@ class Pict: line = action(line) self.__write_pic_obj.write(line) return 0 + 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 @@ -142,6 +150,7 @@ class Pict: self.__write_pic_obj.write("{\\pict\n") return 0 return 1 + def __print_rtf_header(self): """Print to pict file the necessary RTF data for the file to be recognized as an RTF file. @@ -150,6 +159,7 @@ class Pict: self.__write_pic_obj.write("{\\fonttbl\\f0\\null;} \n") self.__write_pic_obj.write("{\\colortbl\\red255\\green255\\blue255;} \n") self.__write_pic_obj.write("\\pard \n") + def process_pict(self): self.__make_dir() read_obj = open(self.__file)