mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion pipeline: Remove the attempt to detect and autocorrect if text will go off the left edge of the page, as it was a rather crude heuristic. Also do not remove fake margins if the book uses negative text indents on the margined elements
This commit is contained in:
parent
08f6719019
commit
8b5dfb98a5
@ -221,7 +221,7 @@ class CSSFlattener(object):
|
|||||||
value = 0.0
|
value = 0.0
|
||||||
cssdict[property] = "%0.5fem" % (value / fsize)
|
cssdict[property] = "%0.5fem" % (value / fsize)
|
||||||
|
|
||||||
def flatten_node(self, node, stylizer, names, styles, psize, item_id, left=0):
|
def flatten_node(self, node, stylizer, names, styles, psize, item_id):
|
||||||
if not isinstance(node.tag, basestring) \
|
if not isinstance(node.tag, basestring) \
|
||||||
or namespace(node.tag) != XHTML_NS:
|
or namespace(node.tag) != XHTML_NS:
|
||||||
return
|
return
|
||||||
@ -316,16 +316,6 @@ class CSSFlattener(object):
|
|||||||
if cssdict:
|
if cssdict:
|
||||||
if self.lineh and self.fbase and tag != 'body':
|
if self.lineh and self.fbase and tag != 'body':
|
||||||
self.clean_edges(cssdict, style, psize)
|
self.clean_edges(cssdict, style, psize)
|
||||||
margin = asfloat(style['margin-left'], 0)
|
|
||||||
indent = asfloat(style['text-indent'], 0)
|
|
||||||
left += margin
|
|
||||||
if (left + indent) < 0:
|
|
||||||
try:
|
|
||||||
percent = (margin - indent) / style['width']
|
|
||||||
cssdict['margin-left'] = "%d%%" % (percent * 100)
|
|
||||||
except ZeroDivisionError:
|
|
||||||
pass
|
|
||||||
left -= indent
|
|
||||||
if 'display' in cssdict and cssdict['display'] == 'in-line':
|
if 'display' in cssdict and cssdict['display'] == 'in-line':
|
||||||
cssdict['display'] = 'inline'
|
cssdict['display'] = 'inline'
|
||||||
if self.unfloat and 'float' in cssdict \
|
if self.unfloat and 'float' in cssdict \
|
||||||
@ -378,7 +368,7 @@ class CSSFlattener(object):
|
|||||||
if 'style' in node.attrib:
|
if 'style' in node.attrib:
|
||||||
del node.attrib['style']
|
del node.attrib['style']
|
||||||
for child in node:
|
for child in node:
|
||||||
self.flatten_node(child, stylizer, names, styles, psize, item_id, left)
|
self.flatten_node(child, stylizer, names, styles, psize, item_id)
|
||||||
|
|
||||||
def flatten_head(self, item, href, global_href):
|
def flatten_head(self, item, href, global_href):
|
||||||
html = item.data
|
html = item.data
|
||||||
|
@ -32,6 +32,8 @@ class RemoveAdobeMargins(object):
|
|||||||
attr = 'margin-'+margin
|
attr = 'margin-'+margin
|
||||||
elem.attrib.pop(attr, None)
|
elem.attrib.pop(attr, None)
|
||||||
|
|
||||||
|
class NegativeTextIndent(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class RemoveFakeMargins(object):
|
class RemoveFakeMargins(object):
|
||||||
|
|
||||||
@ -66,13 +68,25 @@ class RemoveFakeMargins(object):
|
|||||||
self.find_levels()
|
self.find_levels()
|
||||||
|
|
||||||
for level in self.levels:
|
for level in self.levels:
|
||||||
self.process_level(level)
|
try:
|
||||||
|
self.process_level(level)
|
||||||
|
except NegativeTextIndent:
|
||||||
|
self.log.debug('Negative text indent detected at level '
|
||||||
|
' %s, ignoring this level'%level)
|
||||||
|
|
||||||
def get_margins(self, elem):
|
def get_margins(self, elem):
|
||||||
cls = elem.get('class', None)
|
cls = elem.get('class', None)
|
||||||
if cls:
|
if cls:
|
||||||
style = self.selector_map.get('.'+cls, None)
|
style = self.selector_map.get('.'+cls, None)
|
||||||
if style:
|
if style:
|
||||||
|
try:
|
||||||
|
ti = style['text-indent']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if ( (hasattr(ti, 'startswith') and ti.startswith('-')) or
|
||||||
|
isinstance(ti, (int, float)) and ti < 0):
|
||||||
|
raise NegativeTextIndent()
|
||||||
return style.marginLeft, style.marginRight, style
|
return style.marginLeft, style.marginRight, style
|
||||||
return '', '', None
|
return '', '', None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user