EPUB Input: Fix page margins specified in Adobe page template files with incorrect mime-types not being removed.

This commit is contained in:
Kovid Goyal 2013-05-02 09:24:54 +05:30
parent c504bbab3d
commit 9ea1c45ab4
2 changed files with 10 additions and 9 deletions

View File

@ -206,8 +206,10 @@ class EPUBInput(InputFormatPlugin):
not_for_spine = set()
for y in opf.itermanifest():
id_ = y.get('id', None)
if id_ and y.get('media-type', None) in \
('application/vnd.adobe-page-template+xml','application/text'):
if id_ and y.get('media-type', None) in {
'application/vnd.adobe-page-template+xml', 'application/vnd.adobe.page-template+xml',
'application/adobe-page-template+xml', 'application/adobe.page-template+xml',
'application/text'}:
not_for_spine.add(id_)
seen = set()

View File

@ -20,9 +20,10 @@ class RemoveAdobeMargins(object):
self.oeb, self.opts, self.log = oeb, opts, log
for item in self.oeb.manifest:
if (item.media_type in ('application/vnd.adobe-page-template+xml',
'application/vnd.adobe.page-template+xml') and
hasattr(item.data, 'xpath')):
if item.media_type in {
'application/vnd.adobe-page-template+xml', 'application/vnd.adobe.page-template+xml',
'application/adobe-page-template+xml', 'application/adobe.page-template+xml',
} and hasattr(item.data, 'xpath'):
self.log('Removing page margins specified in the'
' Adobe page template')
for elem in item.data.xpath(
@ -84,13 +85,12 @@ class RemoveFakeMargins(object):
except:
pass
else:
if ( (hasattr(ti, 'startswith') and ti.startswith('-')) or
if ((hasattr(ti, 'startswith') and ti.startswith('-')) or
isinstance(ti, (int, float)) and ti < 0):
raise NegativeTextIndent()
return style.marginLeft, style.marginRight, style
return '', '', None
def process_level(self, level):
elems = self.levels[level]
self.stats[level+'_left'] = Counter()
@ -107,7 +107,6 @@ class RemoveFakeMargins(object):
remove_left = self.analyze_stats(self.stats[level+'_left'])
remove_right = self.analyze_stats(self.stats[level+'_right'])
if remove_left:
mcl = self.stats[level+'_left'].most_common(1)[0][0]
self.log('Removing level %s left margin of:'%level, mcl)