mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix crash on nested tables and make autorotate anti-clockwise.
This commit is contained in:
parent
4f79193b17
commit
0ade1a3e64
@ -33,7 +33,7 @@ You may have to adjust the GROUP and the location of the rules file to
|
|||||||
suit your distribution.
|
suit your distribution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "0.3.36"
|
__version__ = "0.3.37"
|
||||||
__docformat__ = "epytext"
|
__docformat__ = "epytext"
|
||||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||||
|
|
||||||
|
@ -298,6 +298,7 @@ class HTMLConverter(object):
|
|||||||
em = {"font-style" :"italic"},
|
em = {"font-style" :"italic"},
|
||||||
small = {'font-size' :'small'},
|
small = {'font-size' :'small'},
|
||||||
pre = {'font-family' :'monospace' },
|
pre = {'font-family' :'monospace' },
|
||||||
|
tt = {'font-family' :'monospace'},
|
||||||
center = {'text-align' : 'center'}
|
center = {'text-align' : 'center'}
|
||||||
)
|
)
|
||||||
self.profile = profile #: Defines the geometry of the display device
|
self.profile = profile #: Defines the geometry of the display device
|
||||||
@ -325,6 +326,7 @@ class HTMLConverter(object):
|
|||||||
# point to the previous element
|
# point to the previous element
|
||||||
self.anchor_to_previous = None
|
self.anchor_to_previous = None
|
||||||
self.cover = cover
|
self.cover = cover
|
||||||
|
self.in_table = False
|
||||||
self.memory = [] #: Used to ensure that duplicate CSS unhandled erros are not reported
|
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.in_ol = False #: Flag indicating we're in an <ol> element
|
||||||
self.book = book #: The Book object representing a BBeB book
|
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:
|
if not self.disable_autorotation and width > self.profile.page_width and width > height:
|
||||||
pt = PersistentTemporaryFile(suffix='.jpeg')
|
pt = PersistentTemporaryFile(suffix='.jpeg')
|
||||||
im = im.rotate(-90)
|
im = im.rotate(90)
|
||||||
im.convert('RGB').save(pt, 'JPEG')
|
im.convert('RGB').save(pt, 'JPEG')
|
||||||
path = pt.name
|
path = pt.name
|
||||||
pt.close()
|
pt.close()
|
||||||
@ -854,9 +856,9 @@ class HTMLConverter(object):
|
|||||||
pass
|
pass
|
||||||
elif tagname == 'a' and self.max_link_levels >= 0:
|
elif tagname == 'a' and self.max_link_levels >= 0:
|
||||||
if tag.has_key('name'):
|
if tag.has_key('name'):
|
||||||
|
print tag, self.anchor_to_previous
|
||||||
if self.anchor_to_previous:
|
if self.anchor_to_previous:
|
||||||
self.process_children(tag, tag_css)
|
self.process_children(tag, tag_css)
|
||||||
return
|
|
||||||
for c in self.anchor_to_previous.contents:
|
for c in self.anchor_to_previous.contents:
|
||||||
if isinstance(c, (TextBlock, ImageBlock)):
|
if isinstance(c, (TextBlock, ImageBlock)):
|
||||||
self.targets[tag['name']] = c
|
self.targets[tag['name']] = c
|
||||||
@ -1049,7 +1051,7 @@ class HTMLConverter(object):
|
|||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
if tagname.startswith('h'):
|
if tagname.startswith('h'):
|
||||||
self.current_block.append(CR())
|
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)
|
self.process_children(tag, tag_css)
|
||||||
elif tagname == 'font':
|
elif tagname == 'font':
|
||||||
if tag.has_key('face'):
|
if tag.has_key('face'):
|
||||||
@ -1057,12 +1059,15 @@ class HTMLConverter(object):
|
|||||||
self.process_children(tag, tag_css)
|
self.process_children(tag, tag_css)
|
||||||
elif tagname in ['br']:
|
elif tagname in ['br']:
|
||||||
self.current_para.append(CR())
|
self.current_para.append(CR())
|
||||||
elif tagname == 'hr':
|
elif tagname in ['hr', 'tr']: # tr needed for nested tables
|
||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
self.current_block.append(CR())
|
self.current_block.append(CR())
|
||||||
self.end_current_block()
|
self.end_current_block()
|
||||||
self.current_page.RuledLine(linelength=self.profile.page_width)
|
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
|
tag_css = self.tag_css(tag) # Table should not inherit CSS
|
||||||
self.process_table(tag, tag_css)
|
self.process_table(tag, tag_css)
|
||||||
else:
|
else:
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<br/>
|
<br/>
|
||||||
<p>
|
<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>
|
</p>
|
||||||
<br />
|
<br />
|
||||||
<p>
|
<p>
|
||||||
|
@ -88,7 +88,6 @@ class Cell(object):
|
|||||||
|
|
||||||
pp = conv.current_page
|
pp = conv.current_page
|
||||||
conv.book.allow_new_page = False
|
conv.book.allow_new_page = False
|
||||||
conv.anchor_to_previous = pp
|
|
||||||
conv.current_page = conv.book.create_page()
|
conv.current_page = conv.book.create_page()
|
||||||
conv.parse_tag(cell, css)
|
conv.parse_tag(cell, css)
|
||||||
conv.end_current_block()
|
conv.end_current_block()
|
||||||
@ -96,8 +95,7 @@ class Cell(object):
|
|||||||
if isinstance(item, TextBlock):
|
if isinstance(item, TextBlock):
|
||||||
self.text_blocks.append(item)
|
self.text_blocks.append(item)
|
||||||
conv.current_page = pp
|
conv.current_page = pp
|
||||||
conv.book.allow_new_page = True
|
conv.book.allow_new_page = True
|
||||||
conv.anchor_to_previous = None
|
|
||||||
if not self.text_blocks:
|
if not self.text_blocks:
|
||||||
tb = conv.book.create_text_block()
|
tb = conv.book.create_text_block()
|
||||||
tb.Paragraph(' ')
|
tb.Paragraph(' ')
|
||||||
@ -223,9 +221,14 @@ class Table(object):
|
|||||||
self.rowpad = rowpad
|
self.rowpad = rowpad
|
||||||
self.colpad = colpad
|
self.colpad = colpad
|
||||||
rows = table.findAll('tr')
|
rows = table.findAll('tr')
|
||||||
|
conv.anchor_to_previous = conv.current_page
|
||||||
|
conv.in_table = True
|
||||||
for row in rows:
|
for row in rows:
|
||||||
rcss = conv.tag_css(row, css)
|
rcss = conv.tag_css(row, css)
|
||||||
self.rows.append(Row(conv, row, rcss, colpad))
|
self.rows.append(Row(conv, row, rcss, colpad))
|
||||||
|
conv.in_table = False
|
||||||
|
conv.anchor_to_previous = None
|
||||||
|
|
||||||
|
|
||||||
def number_of_columns(self):
|
def number_of_columns(self):
|
||||||
max = 0
|
max = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user