Support for the padding attribute and version bump.

This commit is contained in:
Kovid Goyal 2007-08-17 07:31:28 +00:00
parent 4d7101c591
commit a07bbf0fe9
3 changed files with 62 additions and 24 deletions

View File

@ -13,7 +13,7 @@
## with this program; if not, write to the Free Software Foundation, Inc., ## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
''' E-book management software''' ''' E-book management software'''
__version__ = "0.3.96" __version__ = "0.3.97"
__docformat__ = "epytext" __docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>" __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
__appname__ = 'libprs500' __appname__ = 'libprs500'

View File

@ -950,6 +950,56 @@ class HTMLConverter(object):
self.logger.debug('Forcing page break at %s', tagname) self.logger.debug('Forcing page break at %s', tagname)
return end_page 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): def parse_tag(self, tag, parent_css):
try: try:
tagname = tag.name.lower() tagname = tag.name.lower()
@ -1214,26 +1264,8 @@ class HTMLConverter(object):
self.current_block.append(CR()) self.current_block.append(CR())
self.process_children(tag, tag_css) self.process_children(tag, tag_css)
return return
self.lstrip_toggle = True self.lstrip_toggle = True
if tag_css.has_key('text-indent'): self.process_block(tag, tag_css, tkey)
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.process_children(tag, tag_css) self.process_children(tag, tag_css)
self.end_current_para() self.end_current_para()
if tagname.startswith('h') or self.blank_after_para: if tagname.startswith('h') or self.blank_after_para:

View File

@ -4,6 +4,7 @@
.toc { page-break-after: always; text-indent: 0em; } .toc { page-break-after: always; text-indent: 0em; }
.tocpn {text-align: right; } .tocpn {text-align: right; }
.tocchr {text-align: right;} .tocchr {text-align: right;}
.hanging_indent { padding-left:40px; text-indent:-40px }
</style> </style>
</head> </head>
<h1>Demo of <span style='font-family:monospace'>html2lrf</span></h1> <h1>Demo of <span style='font-family:monospace'>html2lrf</span></h1>
@ -18,7 +19,7 @@
<li><a href='#text'>Text formatting and ruled lines</a></li> <li><a href='#text'>Text formatting and ruled lines</a></li>
<li><a href='#images'>Inline images</a></li> <li><a href='#images'>Inline images</a></li>
<li><a href='#fonts'>Embedded Fonts</a></li> <li><a href='#fonts'>Embedded Fonts</a></li>
<li><a href='#dropcaps'>Dropcaps and Small-Caps</a></li> <li><a href='#dropcaps'>Paragraph Emphasis</a></li>
<li><a href='#recursive'>Recursive link following</a></li> <li><a href='#recursive'>Recursive link following</a></li>
</ul> </ul>
@ -123,13 +124,14 @@
<hr/> <hr/>
<p style='text-indent:30em'>A very indented paragraph</p> <p style='text-indent:30em'>A very indented paragraph</p>
<p style='text-indent:0em'>An unindented paragraph</p> <p style='text-indent:0em'>An unindented paragraph</p>
<p>A default indented paragrpah</p> <p>A default indented paragraph</p><br/>
<hr/> <hr/>
<p class='toc'> <p class='toc'>
<hr /> <hr />
<a href='#toc'>Table of Contents</a> <a href='#toc'>Table of Contents</a>
</p> </p>
<h2><a name='images'>Inline images</a></h2> <h2><a name='images'>Inline images</a></h2>
<p> <p>
Here I demonstrate the use of inline images in the midst of text. Here is a small image <img src='small.jpg' /> embedded in a sentence. Now we have a slightly larger image that is automatically put in its own block <img style="text-align:center" src='medium.jpg' /> 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. <img align='center' src='large.jpg' /> Here I demonstrate the use of inline images in the midst of text. Here is a small image <img src='small.jpg' /> embedded in a sentence. Now we have a slightly larger image that is automatically put in its own block <img style="text-align:center" src='medium.jpg' /> 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. <img align='center' src='large.jpg' />
@ -157,7 +159,7 @@
<a href='#toc'>Table of Contents</a> <a href='#toc'>Table of Contents</a>
</p> </p>
<h2><a name='dropcaps'>Dropcaps and Small-Caps</a></h2> <h2><a name='dropcaps'>Paragraph Emphasis</a></h2>
<br/> <br/>
<p><img class='libprs500_dropcaps' src='a.png' /> beautiful image based dropcaps to emphasize this <p><img class='libprs500_dropcaps' src='a.png' /> beautiful image based dropcaps to emphasize this
paragraph. Image based dropcaps are specified by adding the <code>class = 'libprs500_dropcaps'</code> paragraph. Image based dropcaps are specified by adding the <code>class = 'libprs500_dropcaps'</code>
@ -171,7 +173,11 @@
<br/> <br/>
<p><span style="font-variant: small-caps">This is an Example</span> of small-caps. <p><span style="font-variant: small-caps">This is an Example</span> of small-caps.
It can also be used to highlight the start of a paragraph very effectively. It can also be used to highlight the start of a paragraph very effectively.
<br/>
</p> </p>
<p class='hanging_indent'>A paragraph with a hanging indent. This is especially
useful for highly structured text like verse, or dialogue.
The world is not all prose!<br/></p>
<p class='toc'> <p class='toc'>
<hr /> <hr />
<a href='#toc'>Table of Contents</a> <a href='#toc'>Table of Contents</a>