mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
EPUB Input: Handle the case of the metadata ToC containing a reference to the cover HTML file correctly. Fixes #993812 (Update cover page in toc.ncx when converting)
This commit is contained in:
parent
21c84615de
commit
27d199a74b
@ -65,6 +65,7 @@ class EPUBInput(InputFormatPlugin):
|
||||
return False
|
||||
|
||||
def rationalize_cover(self, opf, log):
|
||||
removed = None
|
||||
from lxml import etree
|
||||
guide_cover, guide_elem = None, None
|
||||
for guide_elem in opf.iterguide():
|
||||
@ -91,6 +92,7 @@ class EPUBInput(InputFormatPlugin):
|
||||
# specially
|
||||
if not self.for_viewer:
|
||||
spine[0].getparent().remove(spine[0])
|
||||
removed = guide_cover
|
||||
guide_elem.set('href', 'calibre_raster_cover.jpg')
|
||||
from calibre.ebooks.oeb.base import OPF
|
||||
t = etree.SubElement(elem[0].getparent(), OPF('item'),
|
||||
@ -109,6 +111,7 @@ class EPUBInput(InputFormatPlugin):
|
||||
if renderer is not None:
|
||||
open('calibre_raster_cover.jpg', 'wb').write(
|
||||
renderer)
|
||||
return removed
|
||||
|
||||
def find_opf(self):
|
||||
from lxml import etree
|
||||
@ -170,7 +173,7 @@ class EPUBInput(InputFormatPlugin):
|
||||
for elem in opf.iterguide():
|
||||
elem.set('href', delta+elem.get('href'))
|
||||
|
||||
self.rationalize_cover(opf, log)
|
||||
self.removed_cover = self.rationalize_cover(opf, log)
|
||||
|
||||
self.optimize_opf_parsing = opf
|
||||
for x in opf.itermanifest():
|
||||
@ -198,3 +201,18 @@ class EPUBInput(InputFormatPlugin):
|
||||
nopf.write(opf.render())
|
||||
|
||||
return os.path.abspath(u'content.opf')
|
||||
|
||||
def postprocess_book(self, oeb, opts, log):
|
||||
rc = getattr(self, 'removed_cover', None)
|
||||
if rc:
|
||||
cover_toc_item = None
|
||||
for item in oeb.toc.iterdescendants():
|
||||
if item.href == rc:
|
||||
cover_toc_item = item
|
||||
break
|
||||
spine = {x.href for x in oeb.spine}
|
||||
if (cover_toc_item is not None and cover_toc_item.count() == 0 and
|
||||
cover_toc_item not in spine):
|
||||
oeb.toc.item_that_refers_to_cover = cover_toc_item
|
||||
|
||||
|
||||
|
@ -1011,6 +1011,13 @@ OptionRecommendation(name='search_replace',
|
||||
pr(0.35)
|
||||
self.flush()
|
||||
|
||||
if self.output_plugin.file_type != 'epub':
|
||||
# Remove the toc reference to the html cover, if any, except for
|
||||
# epub, as the epub output plugin will do the right thing with it.
|
||||
item = getattr(self.oeb.toc, 'item_that_refers_to_cover', None)
|
||||
if item is not None:
|
||||
self.oeb.toc.remove(item)
|
||||
|
||||
from calibre.ebooks.oeb.transforms.flatcss import CSSFlattener
|
||||
fbase = self.opts.base_font_size
|
||||
if fbase < 1e-4:
|
||||
|
@ -167,5 +167,9 @@ class CoverManager(object):
|
||||
self.oeb.guide.refs['cover'].href = item.href
|
||||
if 'titlepage' in self.oeb.guide.refs:
|
||||
self.oeb.guide.refs['titlepage'].href = item.href
|
||||
titem = getattr(self.oeb.toc, 'item_that_refers_to_cover', None)
|
||||
if titem is not None:
|
||||
titem.href = item.href
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user