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)

This commit is contained in:
Kovid Goyal 2012-06-07 14:51:20 +05:30
parent fc76cae3fa
commit 4fa52d1ade
2 changed files with 15 additions and 0 deletions

View File

@ -223,6 +223,8 @@ class MOBIOutput(OutputFormatPlugin):
else: else:
# Add rasterized SVG images # Add rasterized SVG images
resources.add_extra_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 = MobiMLizer(ignore_tables=opts.linearize_tables)
mobimlizer(oeb, opts) mobimlizer(oeb, opts)
write_page_breaks_after_item = input_plugin is not plugin_for_input_format('cbz') 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 from calibre.ebooks.mobi.writer8.cleanup import CSSCleanup
CSSCleanup(log, opts)(item, stylizer) 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): class AZW3Output(OutputFormatPlugin):
name = 'AZW3 Output' name = 'AZW3 Output'

View File

@ -72,6 +72,7 @@ class Jacket(object):
item = self.oeb.manifest.add(id, href, guess_type(href)[0], data=root) item = self.oeb.manifest.add(id, href, guess_type(href)[0], data=root)
self.oeb.spine.insert(0, item, True) self.oeb.spine.insert(0, item, True)
self.oeb.inserted_metadata_jacket = item
def remove_existing_jacket(self): def remove_existing_jacket(self):
for x in self.oeb.spine[:4]: for x in self.oeb.spine[:4]: