EPUB Input: Fix EPUB2 files that specify a cover image via a <meta> tag but not in the <guide> not getting a cover when converted to PDF

This commit is contained in:
Kovid Goyal 2016-12-28 10:09:26 +05:30
parent 551bf6d74b
commit 92da68945a

View File

@ -128,6 +128,7 @@ class EPUBInput(InputFormatPlugin):
means, at most one entry with type="cover" that points to a raster
cover and at most one entry with type="titlepage" that points to an
HTML titlepage. '''
from calibre.ebooks.oeb.base import OPF
removed = None
from lxml import etree
guide_cover, guide_elem = None, None
@ -136,6 +137,16 @@ class EPUBInput(InputFormatPlugin):
guide_cover = guide_elem.get('href', '').partition('#')[0]
break
if not guide_cover:
raster_cover = opf.raster_cover
if raster_cover:
if guide_elem is None:
g = opf.root.makeelement(OPF('guide'))
opf.root.append(g)
else:
g = guide_elem.getparent()
guide_cover = raster_cover
guide_elem = g.makeelement(OPF('reference'), attrib={'href':raster_cover, 'type':'cover'})
g.append(guide_elem)
return
spine = list(opf.iterspine())
if not spine:
@ -174,8 +185,6 @@ class EPUBInput(InputFormatPlugin):
# entry will be used by the epub output plugin, the raster cover entry
# by other output plugins.
from calibre.ebooks.oeb.base import OPF
# Search for a raster cover identified in the OPF
raster_cover = opf.raster_cover