From f805984c1cee6fdc33ec639878bdcab50ce5e5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Tue, 5 Mar 2013 16:28:22 +0100 Subject: [PATCH] Fixed logic - Inserting blank-page records Variable "facing" could be bool but this way code is more readable. --- kcc/comic2ebook.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 7ef52fc..fac39f2 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -187,16 +187,21 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): mt = 'image/jpeg' f.write("\n") - if (options.profile == 'K4' or options.profile == 'KHD') and splittedSomething: - f.write("\n") + if (options.profile == 'K4' or options.profile == 'KHD') and splitCount > 0: + splitCountUsed = 1 + while (splitCountUsed <= splitCount): + f.write("\n") + splitCountUsed += 1 f.write("\n\n") + splitCountUsed = 1 for entry in reflist: if entry.endswith("-1"): if (righttoleft and facing == 'left') or (not righttoleft and facing == 'right') and \ (options.profile == 'K4' or options.profile == 'KHD'): - f.write("\n") + f.write("\n") + splitCountUsed += 1 f.write("\n") elif entry.endswith("-2"): f.write("\n") @@ -258,8 +263,12 @@ def applyImgOptimization(img, isSplit=False, toRight=False): def dirImgProcess(path): global options - global splittedSomething - splittedSomething = False + global splitCount + splitCount = 0 + if options.righttoleft: + facing = "right" + else: + facing = "left" for (dirpath, dirnames, filenames) in os.walk(path): for afile in filenames: @@ -270,8 +279,7 @@ def dirImgProcess(path): print ".", img = image.ComicPage(os.path.join(dirpath, afile), options.profile) split = img.splitPage(dirpath, options.righttoleft, options.rotate) - if split is not None: - splittedSomething = True + if split is not None: if options.verbose: print "Splitted " + afile if options.righttoleft: @@ -280,6 +288,14 @@ def dirImgProcess(path): else: toRight1 = True toRight2 = False + if options.righttoleft: + if facing == "left": + splitCount += 1 + facing = "right" + else: + if facing == "right": + splitCount += 1 + facing = "left" img0 = image.ComicPage(split[0], options.profile) applyImgOptimization(img0, True, toRight1) img0.saveToDir(dirpath) @@ -287,6 +303,10 @@ def dirImgProcess(path): applyImgOptimization(img1, True, toRight2) img1.saveToDir(dirpath) else: + if facing == "right": + facing = "left" + else: + facing = "right" applyImgOptimization(img) img.saveToDir(dirpath) @@ -323,7 +343,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) - if (options.profile == 'K4' or options.profile == 'KHD') and splittedSomething: + if (options.profile == 'K4' or options.profile == 'KHD') and splitCount > 0: filelist.append(buildBlankHTML(os.path.join(path, 'OEBPS', 'Text')))