From 0cabbfde961393d9cf8a4cc5b650a74d6760e916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Sun, 10 Mar 2013 10:43:34 +0100 Subject: [PATCH] Additional tweaks of Landscape mode --- kcc/comic2ebook.py | 61 +++++++++++++++++++++++++++++++--------------- kcc/image.py | 6 ++--- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 8328867..cb21c7e 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -130,7 +130,6 @@ def buildNCX(dstdir, title, chapters): def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): opffile = os.path.join(dstdir, 'OEBPS', 'content.opf') - # read the first file resolution profilelabel, deviceres, palette, gamma = image.ProfileData.Profiles[profile] imgres = str(deviceres[0]) + "x" + str(deviceres[1]) if righttoleft: @@ -159,16 +158,22 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): "\n", "\n", "\n", - "\n", - "\n", - "\n", + "\n" + ]) + if options.landscapemode: + f.writelines(["\n", + "\n" + ]) + else: + f.writelines(["\n", + "\n" + ]) + f.writelines(["\n", "\n", "\n", - "\n", "\n\n\n" ]) - # set cover if cover is not None: filename = getImageFileName(cover.replace(os.path.join(dstdir, 'OEBPS'), '').lstrip('/').lstrip('\\\\')) if '.png' == filename[1]: @@ -191,7 +196,7 @@ 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 splitCount > 0: + if options.landscapemode and splitCount > 0: splitCountUsed = 1 while splitCountUsed <= splitCount: f.write("\n") splitCountUsed += 1 - f.write("\n") + if options.landscapemode: + f.write("\n") + else: + f.write("\n") elif entry.endswith("-2"): - f.write("\n") + if options.landscapemode: + f.write("\n") + else: + f.write("\n") if righttoleft: facing = "right" else: facing = "left" else: - f.write("\n") + if options.landscapemode: + f.write("\n") + 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 os.mkdir(os.path.join(dstdir, 'META-INF')) f = open(os.path.join(dstdir, 'mimetype'), 'w') f.write('application/epub+zip') @@ -355,7 +367,6 @@ def genEpubStruct(path): for afile in filenames: filename = getImageFileName(afile) if filename is not None: - # put credits at the end if "credit" in afile.lower(): os.rename(os.path.join(dirpath, afile), os.path.join(dirpath, 'ZZZ999_' + afile)) afile = 'ZZZ999_' + afile @@ -371,12 +382,11 @@ def genEpubStruct(path): cover = os.path.join(filelist[-1][0], 'cover' + getImageFileName(filelist[-1][1])[1]) copyfile(os.path.join(filelist[-1][0], filelist[-1][1]), cover) buildNCX(path, options.title, chapterlist) - # ensure we're sorting files alphabetically convert = lambda text: int(text) if text.isdigit() else text 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 splitCount > 0: + if options.landscapemode and splitCount > 0: filelist.append(buildBlankHTML(os.path.join(path, 'OEBPS', 'Text'))) @@ -456,8 +466,7 @@ def main(argv=None): parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output [Default=False]") options, args = parser.parse_args(argv) - if options.fakepanelview = True and options.profile = "KHD": - options.fakepanelview = False + checkOptions() if len(args) != 1: parser.print_help() return @@ -470,7 +479,6 @@ def main(argv=None): dirImgProcess(path + "/OEBPS/Images/") print "\nCreating ePub structure..." genEpubStruct(path) - # actually zip the ePub if options.output is not None: if options.output.endswith('.epub'): epubpath = os.path.abspath(options.output) @@ -488,6 +496,21 @@ def main(argv=None): rmtree(path) return epubpath +def checkOptions(): + global options + if options.profile == 'K4' or options.profile == 'KHD': + options.landscapemode = True + else: + options.landscapemode = False + if options.fakepanelview and options.profile == 'KHD': + options.fakepanelview = False + if options.fakepanelview and options.landscapemode: + options.landscapemode = False + if options.fakepanelview: + options.imgproc = True + options.rotate = False + options.nosplitrotate = False + def getEpubPath(): global epub_path diff --git a/kcc/image.py b/kcc/image.py index 8eeae69..725956f 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -147,7 +147,7 @@ class ComicPage: fill = 'white' if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]: if not upscale: - if isSplit and (self.profile == 'K4' or self.profile == 'KHD'): + if isSplit and options.landscapemode: borderw = (self.size[0] - self.image.size[0]) borderh = (self.size[1] - self.image.size[1]) / 2 self.image = ImageOps.expand(self.image, border=(0, borderh), fill=fill) @@ -165,14 +165,14 @@ class ComicPage: else: method = Image.NEAREST - if stretch: # if stretching call directly resize() without other considerations. + if stretch: self.image = self.image.resize(self.size, method) return self.image ratioDev = float(self.size[0]) / float(self.size[1]) if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev: diff = int(self.image.size[1] * ratioDev) - self.image.size[0] - if isSplit and (self.profile == 'K4' or self.profile == 'KHD'): + if isSplit and options.landscapemode: diff = 2 self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill) elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev: