From 9b400573c8dd19d2faad0853bbb07aa6e2a8f5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Sun, 15 Sep 2013 21:05:53 +0200 Subject: [PATCH] Automatic matching of Panel View layout --- kcc/comic2ebook.py | 195 +++++++++++++++++++++++---------------------- kcc/image.py | 40 +++++++++- 2 files changed, 138 insertions(+), 97 deletions(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index d5aff24..b93eb7e 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -44,11 +44,18 @@ import pdfjpgextract def buildHTML(path, imgfile): filename = getImageFileName(imgfile) if filename is not None: - # All files marked with this sufix need horizontal Panel View. - if "_kccrotated" in str(filename): - rotate = True + if "_kccrot" in str(filename): + rotatedPage = True else: - rotate = False + rotatedPage = False + if "_kccnh" in str(filename): + noHorizontalPV = True + else: + noHorizontalPV = False + if "_kccnv" in str(filename): + noVerticalPV = True + else: + noVerticalPV = False htmlpath = '' postfix = '' backref = 1 @@ -79,64 +86,74 @@ def buildHTML(path, imgfile): imgfile, "\" class=\"singlePage\"/>\n" ]) if options.panelview: - if rotate: - if options.righttoleft: - order = [1, 3, 2, 4] + if not noHorizontalPV and not noVerticalPV: + if rotatedPage: + if options.righttoleft: + order = [1, 3, 2, 4] + else: + order = [2, 4, 1, 3] else: - order = [2, 4, 1, 3] + if options.righttoleft: + order = [2, 1, 4, 3] + else: + order = [1, 2, 3, 4] + boxes = ["BoxTL", "BoxTR", "BoxBL", "BoxBR"] + elif noHorizontalPV and not noVerticalPV: + if rotatedPage: + if options.righttoleft: + order = [2, 1] + else: + order = [1, 2] + else: + order = [1, 2] + boxes = ["BoxT", "BoxB"] + elif not noHorizontalPV and noVerticalPV: + if rotatedPage: + order = [1, 2] + else: + if options.righttoleft: + order = [2, 1] + else: + order = [1, 2] + boxes = ["BoxL", "BoxR"] else: - if options.righttoleft: - order = [2, 1, 4, 3] - else: - order = [1, 2, 3, 4] - f.writelines(["
\n", - "
\n", - "
\n", - "
\n" - ]) + order = [1] + boxes = ["BoxC"] + for i in range(0, len(boxes)): + f.writelines(["
\n"]) if options.quality == 2: imgfilepv = string.split(imgfile, ".") - imgfilepv[0] = imgfilepv[0].split("_kccx")[0] + imgfilepv[0] = imgfilepv[0].split("_kccx")[0].replace("_kccnh", "").replace("_kccnv", "") imgfilepv[0] += "_kcchq" imgfilepv = string.join(imgfilepv, ".") else: imgfilepv = imgfile - if not "_kccx" in filename[0]: - for box in ["BoxTL", "BoxTR", "BoxBL", "BoxBR"]: - f.writelines(["
\""
\n" - ]) + xy = string.split(filename[0], "_kccx")[1] + x = string.split(xy, "_kccy")[0].lstrip("0") + y = string.split(xy, "_kccy")[1].lstrip("0") + if x != "": + x = "-" + str(float(x)/100) + "%" else: - xy = string.split(filename[0], "_kccx")[1] - x = string.split(xy, "_kccy")[0].lstrip("0") - y = string.split(xy, "_kccy")[1].lstrip("0") - if x != "": - x = "-" + str(float(x)/100) + "%" - else: - x = "0%" - if y != "": - y = "-" + str(float(y)/100) + "%" - else: - y = "0%" - f.writelines(["
\""
\n", - "
\""
\n", - "
\""
\n", - "
\""
\n", ]) @@ -445,6 +462,36 @@ def genEpubStruct(path): "height: ", str(panelviewsize[1]), "px;\n", "width: ", str(panelviewsize[0]), "px;\n", "}\n", + "#Generic-Panel {\n", + "top: 0;\n", + "height: 100%;\n", + "width: 100%;\n", + "}\n", + "#BoxC {\n", + "top: 0;\n", + "height: 100%;\n", + "width: 100%;\n", + "}\n", + "#BoxT {\n", + "top: 0;\n", + "height: 50%;\n", + "width: 100%;\n", + "}\n", + "#BoxB {\n", + "bottom: 0;\n", + "height: 50%;\n", + "width: 100%;\n", + "}\n", + "#BoxL {\n", + "left: 0;\n", + "height: 100%;\n", + "width: 50%;\n", + "}\n", + "#BoxR {\n", + "right: 0;\n", + "height: 100%;\n", + "width: 50%;\n", + "}\n", "#BoxTL {\n", "top: 0;\n", "left: 0;\n", @@ -468,47 +515,7 @@ def genEpubStruct(path): "right: 0;\n", "height: 50%;\n", "width: 50%;\n", - "}\n", - "#BoxTL-Panel {\n", - "top: 0;\n", - "left: 0;\n", - "height: 100%;\n", - "width: 100%;\n", - "}\n", - "#BoxTL-Panel img {\n", - "top: 0%;\n", - "left: 0%;\n", - "}\n", - "#BoxTR-Panel {\n", - "top: 0;\n", - "right: 0;\n", - "height: 100%;\n", - "width: 100%;\n", - "}\n", - "#BoxTR-Panel img {\n", - "top: 0%;\n", - "right: 0%;\n", - "}\n", - "#BoxBL-Panel {\n", - "bottom: 0;\n", - "left: 0;\n", - "height: 100%;\n", - "width: 100%;\n", - "}\n", - "#BoxBL-Panel img {\n", - "bottom: 0%;\n", - "left: 0%;\n", - "}\n", - "#BoxBR-Panel {\n", - "bottom: 0;\n", - "right: 0;\n", - "height: 100%;\n", - "width: 100%;\n", - "}\n", - "#BoxBR-Panel img {\n", - "bottom: 0%;\n", - "right: 0%;\n", - "}" + "}", ]) f.close() for (dirpath, dirnames, filenames) in os.walk(os.path.join(path, 'OEBPS', 'Images')): diff --git a/kcc/image.py b/kcc/image.py index b384ba6..31dcba4 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -152,13 +152,17 @@ class ComicPage: if not color: self.image = self.image.convert('L') # convert to grayscale if suffix == "R": - suffix = "_kccrotated" + suffix = "_kccrot" else: suffix = "" if wipe: os.remove(os.path.join(targetdir, self.filename)) else: suffix += "_kcchq" + if self.noHPV: + suffix += "_kccnh" + if self.noVPV: + suffix += "_kccnv" if self.border: suffix += "_kccx" + str(self.border[0]) + "_kccy" + str(self.border[1]) if forcepng: @@ -207,10 +211,20 @@ class ComicPage: borderh = (self.size[1] - self.image.size[1]) / 2 self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill) if generateBorder: - self.border = [int(round(float(borderw)/float(self.image.size[0])*100, 2)*100*1.5), - int(round(float(borderh)/float(self.image.size[1])*100, 2)*100*1.5)] + if (self.image.size[0]-(2*borderw))*1.5 < self.size[0]: + self.noHPV = True + else: + self.noHPV = None + if (self.image.size[1]-(2*borderh))*1.5 < self.size[1]: + self.noVPV = True + else: + self.noVPV = None + self.border = [int(round(float(borderw)/float(self.image.size[0])*100, 2)*100*1.5), + int(round(float(borderh)/float(self.image.size[1])*100, 2)*100*1.5)] else: self.border = None + self.noHPV = None + self.noVPV = None return self.image else: method = Image.BILINEAR @@ -221,10 +235,20 @@ class ComicPage: border = ImageOps.invert(self.image).getbbox() else: border = self.image.getbbox() + if (border[2]-border[0])*1.5 < self.size[0]: + self.noHPV = True + else: + self.noHPV = None + if (border[3]-border[1])*1.5 < self.size[1]: + self.noVPV = True + else: + self.noVPV = None self.border = [int(round(float(border[0])/float(self.image.size[0])*100, 2)*100*1.5), int(round(float(border[1])/float(self.image.size[1])*100, 2)*100*1.5)] else: self.border = None + self.noHPV = None + self.noVPV = None return self.image ratioDev = float(self.size[0]) / float(self.size[1]) if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev: @@ -239,10 +263,20 @@ class ComicPage: border = ImageOps.invert(self.image).getbbox() else: border = self.image.getbbox() + if (border[2]-border[0])*1.5 < self.size[0]: + self.noHPV = True + else: + self.noHPV = None + if (border[3]-border[1])*1.5 < self.size[1]: + self.noVPV = True + else: + self.noVPV = None self.border = [int(round(float(border[0])/float(self.image.size[0])*100, 2)*100*1.5), int(round(float(border[1])/float(self.image.size[1])*100, 2)*100*1.5)] else: self.border = None + self.noHPV = None + self.noVPV = None return self.image def splitPage(self, targetdir, righttoleft=False, rotate=False):