mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Display covers when viewing lit and mobi files
This commit is contained in:
parent
4c351035c5
commit
db4ff1e605
@ -145,6 +145,20 @@ def resize_cover(im, opts):
|
||||
im = im.resize((int(nwidth), int(nheight)), PILImage.ANTIALIAS)
|
||||
return im
|
||||
|
||||
TITLEPAGE = '''\
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Cover</title>
|
||||
<style type="text/css">@page {padding: 0pt; margin:0pt}</style>
|
||||
</head>
|
||||
<body style="padding: 0pt; margin: 0pt">
|
||||
<div style="text-align:center">
|
||||
<img style="text-align: center" src="%s" alt="cover" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
|
||||
def process_title_page(mi, filelist, htmlfilemap, opts, tdir):
|
||||
old_title_page = None
|
||||
f = lambda x : os.path.normcase(os.path.normpath(x))
|
||||
@ -188,19 +202,7 @@ def process_title_page(mi, filelist, htmlfilemap, opts, tdir):
|
||||
cover = metadata_cover if specified_cover is None or (opts.prefer_metadata_cover and metadata_cover is not None) else specified_cover
|
||||
|
||||
if hasattr(cover, 'save'):
|
||||
titlepage = '''\
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Cover</title>
|
||||
<style type="text/css">@page {padding: 0pt; margin:0pt}</style>
|
||||
</head>
|
||||
<body style="padding: 0pt; margin: 0pt">
|
||||
<div style="text-align:center">
|
||||
<img style="text-align: center" src="%s" alt="cover" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
'''%cpath
|
||||
titlepage = TITLEPAGE%cpath
|
||||
tp = 'calibre_title_page.html' if old_title_page is None else old_title_page
|
||||
tppath = os.path.join(tdir, 'content', tp)
|
||||
with open(tppath, 'wb') as f:
|
||||
|
@ -8,6 +8,7 @@ Iterate over the HTML files in an ebook. Useful for writing viewers.
|
||||
import re, os, math, copy
|
||||
|
||||
from calibre.ebooks.epub.from_any import MAP
|
||||
from calibre.ebooks.epub.from_html import TITLEPAGE
|
||||
from calibre.ebooks.epub import config
|
||||
from calibre.ebooks.metadata.opf2 import OPF
|
||||
from calibre.ptempfile import TemporaryDirectory
|
||||
@ -83,16 +84,28 @@ class EbookIterator(object):
|
||||
self.pathtoopf = self.to_opf(self.pathtoebook, self.base, opts)
|
||||
self.opf = OPF(self.pathtoopf, os.path.dirname(self.pathtoopf))
|
||||
self.spine = [SpineItem(i.path) for i in self.opf.spine]
|
||||
|
||||
cover = self.opf.cover
|
||||
if os.path.splitext(self.pathtoebook)[1].lower() in ('.lit', '.mobi', '.prc') and cover:
|
||||
cfile = os.path.join(os.path.dirname(self.spine[0]), 'calibre_ei_cover.html')
|
||||
open(cfile, 'wb').write(TITLEPAGE%cover)
|
||||
self.spine[0:0] = [SpineItem(cfile)]
|
||||
|
||||
sizes = [i.character_count for i in self.spine]
|
||||
self.pages = [math.ceil(i/float(self.CHARACTERS_PER_PAGE)) for i in sizes]
|
||||
for p, s in zip(self.pages, self.spine):
|
||||
s.pages = p
|
||||
start = 1
|
||||
|
||||
|
||||
for s in self.spine:
|
||||
s.start_page = start
|
||||
start += s.pages
|
||||
s.max_page = s.start_page + s.pages - 1
|
||||
self.toc = self.opf.toc
|
||||
|
||||
|
||||
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
|
Loading…
x
Reference in New Issue
Block a user