Fix crash on nested tables and make autorotate anti-clockwise.

This commit is contained in:
Kovid Goyal 2007-05-22 19:24:04 +00:00
parent 4f79193b17
commit 0ade1a3e64
4 changed files with 18 additions and 10 deletions

View File

@ -33,7 +33,7 @@ You may have to adjust the GROUP and the location of the rules file to
suit your distribution.
"""
__version__ = "0.3.36"
__version__ = "0.3.37"
__docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"

View File

@ -298,6 +298,7 @@ class HTMLConverter(object):
em = {"font-style" :"italic"},
small = {'font-size' :'small'},
pre = {'font-family' :'monospace' },
tt = {'font-family' :'monospace'},
center = {'text-align' : 'center'}
)
self.profile = profile #: Defines the geometry of the display device
@ -325,6 +326,7 @@ class HTMLConverter(object):
# point to the previous element
self.anchor_to_previous = None
self.cover = cover
self.in_table = False
self.memory = [] #: Used to ensure that duplicate CSS unhandled erros are not reported
self.in_ol = False #: Flag indicating we're in an <ol> element
self.book = book #: The Book object representing a BBeB book
@ -766,7 +768,7 @@ class HTMLConverter(object):
if not self.disable_autorotation and width > self.profile.page_width and width > height:
pt = PersistentTemporaryFile(suffix='.jpeg')
im = im.rotate(-90)
im = im.rotate(90)
im.convert('RGB').save(pt, 'JPEG')
path = pt.name
pt.close()
@ -854,9 +856,9 @@ class HTMLConverter(object):
pass
elif tagname == 'a' and self.max_link_levels >= 0:
if tag.has_key('name'):
print tag, self.anchor_to_previous
if self.anchor_to_previous:
self.process_children(tag, tag_css)
return
for c in self.anchor_to_previous.contents:
if isinstance(c, (TextBlock, ImageBlock)):
self.targets[tag['name']] = c
@ -1049,7 +1051,7 @@ class HTMLConverter(object):
self.end_current_para()
if tagname.startswith('h'):
self.current_block.append(CR())
elif tagname in ['b', 'strong', 'i', 'em', 'span']:
elif tagname in ['b', 'strong', 'i', 'em', 'span', 'tt']:
self.process_children(tag, tag_css)
elif tagname == 'font':
if tag.has_key('face'):
@ -1057,12 +1059,15 @@ class HTMLConverter(object):
self.process_children(tag, tag_css)
elif tagname in ['br']:
self.current_para.append(CR())
elif tagname == 'hr':
elif tagname in ['hr', 'tr']: # tr needed for nested tables
self.end_current_para()
self.current_block.append(CR())
self.end_current_block()
self.current_page.RuledLine(linelength=self.profile.page_width)
elif tagname == 'table':
elif tagname == 'td': # Needed for nested tables
self.current_para.append(" ")
self.process_children(tag, tag_css)
elif tagname == 'table' and not self.in_table:
tag_css = self.tag_css(tag) # Table should not inherit CSS
self.process_table(tag, tag_css)
else:

View File

@ -62,7 +62,7 @@
</p>
<br/>
<p>
Not that if you have custom fonts on your reader, the table may not be properly aligned.
Not that if you have custom fonts on your reader, the table may not be properly aligned. Also html2lrf does not support nested tables.
</p>
<br />
<p>

View File

@ -88,7 +88,6 @@ class Cell(object):
pp = conv.current_page
conv.book.allow_new_page = False
conv.anchor_to_previous = pp
conv.current_page = conv.book.create_page()
conv.parse_tag(cell, css)
conv.end_current_block()
@ -96,8 +95,7 @@ class Cell(object):
if isinstance(item, TextBlock):
self.text_blocks.append(item)
conv.current_page = pp
conv.book.allow_new_page = True
conv.anchor_to_previous = None
conv.book.allow_new_page = True
if not self.text_blocks:
tb = conv.book.create_text_block()
tb.Paragraph(' ')
@ -223,9 +221,14 @@ class Table(object):
self.rowpad = rowpad
self.colpad = colpad
rows = table.findAll('tr')
conv.anchor_to_previous = conv.current_page
conv.in_table = True
for row in rows:
rcss = conv.tag_css(row, css)
self.rows.append(Row(conv, row, rcss, colpad))
conv.in_table = False
conv.anchor_to_previous = None
def number_of_columns(self):
max = 0