diff --git a/src/libprs500/__init__.py b/src/libprs500/__init__.py index 9627ec5f80..ea0f8fad37 100644 --- a/src/libprs500/__init__.py +++ b/src/libprs500/__init__.py @@ -13,7 +13,7 @@ ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ''' E-book management software''' -__version__ = "0.3.96" +__version__ = "0.3.97" __docformat__ = "epytext" __author__ = "Kovid Goyal " __appname__ = 'libprs500' diff --git a/src/libprs500/ebooks/lrf/html/convert_from.py b/src/libprs500/ebooks/lrf/html/convert_from.py index f7d18ea267..42da6ff1f8 100644 --- a/src/libprs500/ebooks/lrf/html/convert_from.py +++ b/src/libprs500/ebooks/lrf/html/convert_from.py @@ -950,6 +950,56 @@ class HTMLConverter(object): self.logger.debug('Forcing page break at %s', tagname) return end_page + def process_block(self, tag, tag_css, tkey): + ''' Ensure padding and text-indent properties are respected ''' + if tag_css.has_key('text-indent'): + indent = Span.unit_convert(tag_css['text-indent'], self.profile.dpi, pts=True) + if not indent: + indent = 0 + + else: + indent = self.book.defaultTextStyle.attrs['parindent'] + + src = [None for i in range(4)] + if tag_css.has_key('padding'): + msrc = tag_css['padding'].split() + for i in range(len(msrc)): + src[i] = msrc[i] + i = 0 + for c in ('top', 'right', 'bottom', 'left'): + if tag_css.has_key('padding-'+c): + src[i] = tag_css['padding-'+c] + i += 1 + top, right, bottom, left = src + + top = Span.unit_convert(top, self.profile.dpi) if top is not None else 0 + bottom = Span.unit_convert(bottom, self.profile.dpi) if bottom is not None else 0 + left = Span.unit_convert(left, self.profile.dpi) if left is not None else 0 + + if indent != int(self.current_block.textStyle.attrs['parindent']) or \ + top != int(self.current_block.blockStyle.attrs['topskip']) or \ + bottom != int(self.current_block.blockStyle.attrs['footskip']) or \ + left != int(self.current_block.blockStyle.attrs['sidemargin']): + self.current_block.append_to(self.current_page) + ts = self.book.create_text_style(**self.current_block.textStyle.attrs) + ts.attrs['parindent'] = indent + bs = self.book.create_block_style(**self.current_block.blockStyle.attrs) + ba = bs.attrs + ba['topskip'], ba['footskip'], ba['sidemargin'] = top, bottom, left + try: + index = self.text_styles.index(ts) + ts = self.text_styles[index] + except ValueError: + self.text_styles.append(ts) + try: + index = self.block_styles.index(bs) + bs = self.block_styles[index] + except ValueError: + self.block_styles.append(bs) + self.current_block = self.book.create_text_block(blockStyle=bs, + textStyle=ts) + self.targets[tkey] = self.current_block + def parse_tag(self, tag, parent_css): try: tagname = tag.name.lower() @@ -1214,26 +1264,8 @@ class HTMLConverter(object): self.current_block.append(CR()) self.process_children(tag, tag_css) return - self.lstrip_toggle = True - if tag_css.has_key('text-indent'): - indent = Span.unit_convert(tag_css['text-indent'], self.profile.dpi, pts=True) - if not indent: - indent = 0 - - else: - indent = self.book.defaultTextStyle.attrs['parindent'] - if indent != self.current_block.textStyle.attrs['parindent']: - self.current_block.append_to(self.current_page) - ts = self.book.create_text_style(**self.current_block.textStyle.attrs) - ts.attrs['parindent'] = indent - try: - index = self.text_styles.index(ts) - ts = self.text_styles[index] - except ValueError: - self.text_styles.append(ts) - self.current_block = self.book.create_text_block(blockStyle=self.current_block.blockStyle, - textStyle=ts) - self.targets[tkey] = self.current_block + self.lstrip_toggle = True + self.process_block(tag, tag_css, tkey) self.process_children(tag, tag_css) self.end_current_para() if tagname.startswith('h') or self.blank_after_para: diff --git a/src/libprs500/ebooks/lrf/html/demo/demo.html b/src/libprs500/ebooks/lrf/html/demo/demo.html index a9069aa3f4..f399cfb24b 100644 --- a/src/libprs500/ebooks/lrf/html/demo/demo.html +++ b/src/libprs500/ebooks/lrf/html/demo/demo.html @@ -4,6 +4,7 @@ .toc { page-break-after: always; text-indent: 0em; } .tocpn {text-align: right; } .tocchr {text-align: right;} +.hanging_indent { padding-left:40px; text-indent:-40px }

Demo of html2lrf

@@ -18,7 +19,7 @@
  • Text formatting and ruled lines
  • Inline images
  • Embedded Fonts
  • -
  • Dropcaps and Small-Caps
  • +
  • Paragraph Emphasis
  • Recursive link following
  • @@ -123,13 +124,14 @@

    A very indented paragraph

    An unindented paragraph

    -

    A default indented paragrpah

    +

    A default indented paragraph




    Table of Contents

    +

    Inline images

    Here I demonstrate the use of inline images in the midst of text. Here is a small image embedded in a sentence. Now we have a slightly larger image that is automatically put in its own block and finally we have a large image which is put on a page by itself. Try changing sizes from S to M to L and see how the images behave. @@ -157,7 +159,7 @@ Table of Contents

    -

    Dropcaps and Small-Caps

    +

    Paragraph Emphasis


    beautiful image based dropcaps to emphasize this paragraph. Image based dropcaps are specified by adding the class = 'libprs500_dropcaps' @@ -171,7 +173,11 @@

    This is an Example of small-caps. It can also be used to highlight the start of a paragraph very effectively. +

    +

    A paragraph with a hanging indent. This is especially + useful for highly structured text like verse, or dialogue. + The world is not all prose!


    Table of Contents