From 8d5ccf5d27763c931ae24668d08702572252c34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Mon, 4 Mar 2013 11:36:57 +0100 Subject: [PATCH] Landscape mode support - EPUB part. Code create proper landscape enabled EPUB file. Rewritten itemref function (#198) ensures that splited pages will be displayed together. --- kcc/comic2ebook.py | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 2805525..60fb549 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -86,6 +86,21 @@ def buildHTML(path, imgfile): f.close() return path, imgfile +def buildBlankHTML(path): + f = open(os.path.join(path, 'blank.html'), "w") + f.writelines(["\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ]) + f.close() + return path def buildNCX(dstdir, title, chapters): ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx') @@ -121,8 +136,14 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): imgres = str(deviceres[0]) + "x" + str(deviceres[1]) if righttoleft: writingmode = "horizontal-rl" + facing = "right" + facing1 = "right" + facing2 = "left" else: writingmode = "horizontal-lr" + facing = "left" + facing1 = "left" + facing2 = "right" from uuid import uuid4 uuid = str(uuid4()) uuid = uuid.encode('utf-8') @@ -140,11 +161,11 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", - "\n", + "\n", "\n\n\n" ]) @@ -171,9 +192,25 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): mt = 'image/jpeg' f.write("\n") + f.write("\n") f.write("\n\n") for entry in reflist: - f.write("\n") + if entry.endswith("-1"): + if (righttoleft and facing == 'left') or (not righttoleft and facing == 'right'): + f.write("\n") + f.write("\n") + elif entry.endswith("-2"): + f.write("\n") + if righttoleft: + facing = "right" + else: + facing = "left" + else: + f.write("\n") + if facing == 'right': + facing = 'left' + else: + facing = 'right' f.write("\n\n\n\n") f.close() # finish with standard ePub folders @@ -278,6 +315,7 @@ def genEpubStruct(path): alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] filelist.sort(key=lambda name: (alphanum_key(name[0].lower()), alphanum_key(name[1].lower()))) buildOPF(options.profile, path, options.title, filelist, cover, options.righttoleft) + filelist.append(buildBlankHTML(os.path.join(path, 'OEBPS', 'Text'))) def getWorkFolder(afile):