From 9ea1c45ab4fad17c8c01ff6027ab4920957e6596 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 May 2013 09:24:54 +0530 Subject: [PATCH] EPUB Input: Fix page margins specified in Adobe page template files with incorrect mime-types not being removed. --- src/calibre/ebooks/conversion/plugins/epub_input.py | 8 +++++--- src/calibre/ebooks/oeb/transforms/page_margin.py | 11 +++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/epub_input.py b/src/calibre/ebooks/conversion/plugins/epub_input.py index b6024c9b84..5ccf00c643 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_input.py +++ b/src/calibre/ebooks/conversion/plugins/epub_input.py @@ -206,9 +206,11 @@ 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'): - not_for_spine.add(id_) + 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() for x in list(opf.iterspine()): diff --git a/src/calibre/ebooks/oeb/transforms/page_margin.py b/src/calibre/ebooks/oeb/transforms/page_margin.py index 67ba490a81..382f0c8f53 100644 --- a/src/calibre/ebooks/oeb/transforms/page_margin.py +++ b/src/calibre/ebooks/oeb/transforms/page_margin.py @@ -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)