From 4fa52d1ade03c311366bb7bd24bba0a5c7459eab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Jun 2012 14:51:20 +0530 Subject: [PATCH] MOBI Output: When using the insert metadata at start of book, do not use a table to layout the metadata, as the Kindle Fire crashes when rendering the table. Fixes #1002119 (calibre created mobi crashes on k fire if insert metadata jacket used) --- .../ebooks/conversion/plugins/mobi_output.py | 14 ++++++++++++++ src/calibre/ebooks/oeb/transforms/jacket.py | 1 + 2 files changed, 15 insertions(+) diff --git a/src/calibre/ebooks/conversion/plugins/mobi_output.py b/src/calibre/ebooks/conversion/plugins/mobi_output.py index a32a4444f8..f07e01a53c 100644 --- a/src/calibre/ebooks/conversion/plugins/mobi_output.py +++ b/src/calibre/ebooks/conversion/plugins/mobi_output.py @@ -223,6 +223,8 @@ class MOBIOutput(OutputFormatPlugin): else: # Add rasterized SVG images resources.add_extra_images() + if hasattr(self.oeb, 'inserted_metadata_jacket'): + self.workaround_fire_bugs(self.oeb.inserted_metadata_jacket) mobimlizer = MobiMLizer(ignore_tables=opts.linearize_tables) mobimlizer(oeb, opts) write_page_breaks_after_item = input_plugin is not plugin_for_input_format('cbz') @@ -236,6 +238,18 @@ class MOBIOutput(OutputFormatPlugin): from calibre.ebooks.mobi.writer8.cleanup import CSSCleanup CSSCleanup(log, opts)(item, stylizer) + def workaround_fire_bugs(self, jacket): + # The idiotic Fire crashes when trying to render the table used to + # layout the jacket + from calibre.ebooks.oeb.base import XHTML + for table in jacket.data.xpath('//*[local-name()="table"]'): + table.tag = XHTML('div') + for tr in table.xpath('descendant::*[local-name()="tr"]'): + cols = tr.xpath('descendant::*[local-name()="td"]') + tr.tag = XHTML('div') + for td in cols: + td.tag = XHTML('span' if cols else 'div') + class AZW3Output(OutputFormatPlugin): name = 'AZW3 Output' diff --git a/src/calibre/ebooks/oeb/transforms/jacket.py b/src/calibre/ebooks/oeb/transforms/jacket.py index 79524c19eb..5947087535 100644 --- a/src/calibre/ebooks/oeb/transforms/jacket.py +++ b/src/calibre/ebooks/oeb/transforms/jacket.py @@ -72,6 +72,7 @@ class Jacket(object): item = self.oeb.manifest.add(id, href, guess_type(href)[0], data=root) self.oeb.spine.insert(0, item, True) + self.oeb.inserted_metadata_jacket = item def remove_existing_jacket(self): for x in self.oeb.spine[:4]: