From 1ae5b210b03aa71da0dfc45c53a2070bbb73fefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Wed, 12 Jun 2013 11:09:20 +0200 Subject: [PATCH] Implemented screen size override --- README.md | 2 ++ kcc/comic2ebook.py | 31 ++++++++++++++++++++++++------- kcc/image.py | 3 +-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9a55f04..4672c99 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ Options: --nocutpagenumbers Do not try to cut page numbering on images [Default=True] -o OUTPUT, --output=OUTPUT Output generated file (EPUB or CBZ) to specified directory or file + --customwidth=WIDTH Replace screen width provided by device profile [Default=0] + --customheight=HEIGHT Replace screen height provided by device profile [Default=0] -v, --verbose Verbose output [Default=False] ``` diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 233b88c..ddd2d34 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -181,10 +181,10 @@ def buildNCX(dstdir, title, chapters): return -def buildOPF(profile, dstdir, title, filelist, cover=None): +def buildOPF(dstdir, title, filelist, cover=None): opffile = os.path.join(dstdir, 'OEBPS', 'content.opf') # read the first file resolution - profilelabel, deviceres, palette, gamma, panelviewsize = image.ProfileData.Profiles[profile] + profilelabel, deviceres, palette, gamma, panelviewsize = options.profileData imgres = str(deviceres[0]) + "x" + str(deviceres[1]) if options.righttoleft: writingmode = "horizontal-rl" @@ -381,7 +381,7 @@ def fileImgProcess(work): else: print ".", fileImgProcess.queue.put(".") - img = image.ComicPage(os.path.join(dirpath, afile), options.profile) + img = image.ComicPage(os.path.join(dirpath, afile), options.profileData) if options.nosplitrotate: split = None else: @@ -396,10 +396,10 @@ def fileImgProcess(work): toRight1 = True toRight2 = False output = pagenumber - img0 = image.ComicPage(split[0], options.profile) + img0 = image.ComicPage(split[0], options.profileData) applyImgOptimization(img0, True, toRight1, options) img0.saveToDir(dirpath, options.forcepng, options.forcecolor) - img1 = image.ComicPage(split[1], options.profile) + img1 = image.ComicPage(split[1], options.profileData) applyImgOptimization(img1, True, toRight2, options) img1.saveToDir(dirpath, options.forcepng, options.forcecolor) else: @@ -413,7 +413,7 @@ def genEpubStruct(path): filelist = [] chapterlist = [] cover = None - _, deviceres, _, _, panelviewsize = image.ProfileData.Profiles[options.profile] + _, deviceres, _, _, panelviewsize = options.profileData sanitizeTree(os.path.join(path, 'OEBPS', 'Images')) os.mkdir(os.path.join(path, 'OEBPS', 'Text')) f = open(os.path.join(path, 'OEBPS', 'Text', 'style.css'), 'w') @@ -553,7 +553,7 @@ def genEpubStruct(path): 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) + buildOPF(path, options.title, filelist, cover) if options.landscapemode and splitCount > 0: filelist.append(buildBlankHTML(os.path.join(path, 'OEBPS', 'Text'))) @@ -665,6 +665,10 @@ def main(argv=None, qtGUI=None): help="Do not try to cut page numbering on images [Default=True]") parser.add_option("-o", "--output", action="store", dest="output", default=None, help="Output generated file (EPUB or CBZ) to specified directory or file") + parser.add_option("--customwidth", type="int", dest="customwidth", default=0, + help="Replace screen width provided by device profile [Default=0]") + parser.add_option("--customheight", type="int", dest="customheight", default=0, + help="Replace screen height provided by device profile [Default=0]") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output [Default=False]") options, args = parser.parse_args(argv) @@ -754,6 +758,19 @@ def checkOptions(): if options.rotate: options.panelview = True options.landscapemode = False + # Override profile data + if options.customwidth != 0 or options.customheight != 0: + X = image.ProfileData.Profiles[options.profile][1][0] + Y = image.ProfileData.Profiles[options.profile][1][1] + if options.customwidth != 0: + X = options.customwidth + if options.customheight != 0: + Y = options.customheight + newProfile = ("Custom", (X, Y), image.ProfileData.Palette16, image.ProfileData.Profiles[options.profile][3], + (int(X*1.5), int(Y*1.5))) + image.ProfileData.Profiles["Custom"] = newProfile + options.profile = "Custom" + options.profileData = image.ProfileData.Profiles[options.profile] def getEpubPath(): diff --git a/kcc/image.py b/kcc/image.py index c5af9b4..6d69a6f 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -108,8 +108,7 @@ class ProfileData: class ComicPage: def __init__(self, source, device): try: - self.profile = device - self.profile_label, self.size, self.palette, self.gamma, self.panelviewsize = ProfileData.Profiles[device] + self.profile_label, self.size, self.palette, self.gamma, self.panelviewsize = device except KeyError: raise RuntimeError('Unexpected output device %s' % device) try: