1
0
mirror of https://github.com/ciromattia/kcc synced 2026-06-01 20:23:15 +00:00

Merge branch 'master' into kcc-fakepanelview

Apply PEP-8 codestyle
This commit is contained in:
Ciro Mattia Gonano
2013-03-13 00:21:09 +01:00
parent 67baf90d04
commit 19dc5cc6f2
2 changed files with 20 additions and 20 deletions
+12 -11
View File
@@ -163,18 +163,15 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False):
]) ])
if options.landscapemode: if options.landscapemode:
f.writelines(["<meta name=\"rendition:orientation\" content=\"auto\"/>\n", f.writelines(["<meta name=\"rendition:orientation\" content=\"auto\"/>\n",
"<meta name=\"orientation-lock\" content=\"none\"/>\n" "<meta name=\"orientation-lock\" content=\"none\"/>\n"])
])
else: else:
f.writelines(["<meta name=\"rendition:orientation\" content=\"portrait\"/>\n", f.writelines(["<meta name=\"rendition:orientation\" content=\"portrait\"/>\n",
"<meta name=\"orientation-lock\" content=\"portrait\"/>\n" "<meta name=\"orientation-lock\" content=\"portrait\"/>\n"])
])
f.writelines(["<meta name=\"original-resolution\" content=\"", imgres, "\"/>\n", f.writelines(["<meta name=\"original-resolution\" content=\"", imgres, "\"/>\n",
"<meta name=\"primary-writing-mode\" content=\"", writingmode, "\"/>\n", "<meta name=\"primary-writing-mode\" content=\"", writingmode, "\"/>\n",
"<meta name=\"rendition:layout\" content=\"pre-paginated\"/>\n", "<meta name=\"rendition:layout\" content=\"pre-paginated\"/>\n",
"</metadata>\n<manifest>\n<item id=\"ncx\" href=\"toc.ncx\" ", "</metadata>\n<manifest>\n<item id=\"ncx\" href=\"toc.ncx\" ",
"media-type=\"application/x-dtbncx+xml\"/>\n" "media-type=\"application/x-dtbncx+xml\"/>\n"])
])
if cover is not None: if cover is not None:
filename = getImageFileName(cover.replace(os.path.join(dstdir, 'OEBPS'), '').lstrip('/').lstrip('\\\\')) filename = getImageFileName(cover.replace(os.path.join(dstdir, 'OEBPS'), '').lstrip('/').lstrip('\\\\'))
if '.png' == filename[1]: if '.png' == filename[1]:
@@ -207,7 +204,8 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False):
splitCountUsed = 1 splitCountUsed = 1
for entry in reflist: for entry in reflist:
if entry.endswith("-1"): if entry.endswith("-1"):
if ((righttoleft and facing == 'left') or (not righttoleft and facing == 'right')) and options.landscapemode: if ((righttoleft and facing == 'left') or (not righttoleft and facing == 'right')) and\
options.landscapemode:
f.write("<itemref idref=\"blank-page" + str(splitCountUsed) + "\" properties=\"layout-blank\"/>\n") f.write("<itemref idref=\"blank-page" + str(splitCountUsed) + "\" properties=\"layout-blank\"/>\n")
splitCountUsed += 1 splitCountUsed += 1
if options.landscapemode: if options.landscapemode:
@@ -227,7 +225,7 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False):
if options.landscapemode: if options.landscapemode:
f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing + "\"/>\n") f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing + "\"/>\n")
else: else:
f.write("<itemref idref=\"page_" + entry + "\"/>\n") f.write("<itemref idref=\"page_" + entry + "\"/>\n")
if facing == 'right': if facing == 'right':
facing = 'left' facing = 'left'
else: else:
@@ -317,8 +315,10 @@ def dirImgProcess(path):
if options.fakepanelview or options.fakepanelviewlandscape: if options.fakepanelview or options.fakepanelviewlandscape:
img0 = image.ComicPage(split[0], options.profile) img0 = image.ComicPage(split[0], options.profile)
img1 = image.ComicPage(split[1], options.profile) img1 = image.ComicPage(split[1], options.profile)
splitA = img0.splitPageFakePanelView(dirpath, options.righttoleft, options.fakepanelviewlandscape) splitA = img0.splitPageFakePanelView(dirpath, options.righttoleft,
splitB = img1.splitPageFakePanelView(dirpath, options.righttoleft, options.fakepanelviewlandscape) options.fakepanelviewlandscape)
splitB = img1.splitPageFakePanelView(dirpath, options.righttoleft,
options.fakepanelviewlandscape)
for img in splitA: for img in splitA:
tempImg = image.ComicPage(img, options.profile) tempImg = image.ComicPage(img, options.profile)
applyImgOptimization(tempImg) applyImgOptimization(tempImg)
@@ -326,7 +326,7 @@ def dirImgProcess(path):
for img in splitB: for img in splitB:
tempImg = image.ComicPage(img, options.profile) tempImg = image.ComicPage(img, options.profile)
applyImgOptimization(tempImg) applyImgOptimization(tempImg)
tempImg.saveToDir(dirpath, options.notquantize) tempImg.saveToDir(dirpath, options.notquantize)
else: else:
img0 = image.ComicPage(split[0], options.profile) img0 = image.ComicPage(split[0], options.profile)
applyImgOptimization(img0, True, toRight1) applyImgOptimization(img0, True, toRight1)
@@ -522,6 +522,7 @@ def main(argv=None):
rmtree(path) rmtree(path)
return epubpath return epubpath
def checkOptions(): def checkOptions():
global options global options
if options.profile == 'K4' or options.profile == 'KHD': if options.profile == 'K4' or options.profile == 'KHD':
+8 -9
View File
@@ -141,7 +141,8 @@ class ComicPage:
palImg.putpalette(self.palette) palImg.putpalette(self.palette)
self.image = self.image.quantize(palette=palImg) self.image = self.image.quantize(palette=palImg)
def resizeImage(self, upscale=False, stretch=False, black_borders=False, fakePanelViewLandscape=False, isSplit=False, toRight=False, landscapeMode=False): def resizeImage(self, upscale=False, stretch=False, black_borders=False, fakePanelViewLandscape=False,
isSplit=False, toRight=False, landscapeMode=False):
method = Image.ANTIALIAS method = Image.ANTIALIAS
if black_borders: if black_borders:
fill = 'black' fill = 'black'
@@ -222,12 +223,11 @@ class ComicPage:
else: else:
return None return None
def splitPageFakePanelView(self, targetdir, righttoleft=False, fakePanelWiewLandscape=False): def splitPageFakePanelView(self, targetdir, righttoleft=False, fakePanelWiewLandscape=False):
width, height = self.image.size width, height = self.image.size
if fakePanelWiewLandscape: if fakePanelWiewLandscape:
topbox = (0, 0, width, ((height / 2) + (height/9))) topbox = (0, 0, width, ((height / 2) + (height / 9)))
bottombox = (0, ((height / 2) - (height/9)), width, height) bottombox = (0, ((height / 2) - (height / 9)), width, height)
filename = os.path.splitext(os.path.basename(self.origFileName)) filename = os.path.splitext(os.path.basename(self.origFileName))
file1 = targetdir + '/' + filename[0] + '-1' + filename[1] file1 = targetdir + '/' + filename[0] + '-1' + filename[1]
file2 = targetdir + '/' + filename[0] + '-2' + filename[1] file2 = targetdir + '/' + filename[0] + '-2' + filename[1]
@@ -241,10 +241,10 @@ class ComicPage:
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e)) raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
return file1, file2 return file1, file2
else: else:
topleftbox = (0, 0, ((width / 2) + (width/9)), ((height / 2) + (height/9))) topleftbox = (0, 0, ((width / 2) + (width / 9)), ((height / 2) + (height / 9)))
toprightbox = ((width / 2) - (width/9)), 0, width, ((height / 2) + (height/9)) toprightbox = ((width / 2) - (width / 9)), 0, width, ((height / 2) + (height / 9))
bottomleftbox = (0, ((height / 2) - (height/9)), ((width / 2) + (width/9)), height) bottomleftbox = (0, ((height / 2) - (height / 9)), ((width / 2) + (width / 9)), height)
bototmrightbox = (((width / 2) - (width/9)), ((height / 2) - (height/9)), width, height) bototmrightbox = (((width / 2) - (width / 9)), ((height / 2) - (height / 9)), width, height)
filename = os.path.splitext(os.path.basename(self.origFileName)) filename = os.path.splitext(os.path.basename(self.origFileName))
file0 = targetdir + '/' + filename[0] + '-0' + filename[1] file0 = targetdir + '/' + filename[0] + '-0' + filename[1]
file1 = targetdir + '/' + filename[0] + '-1' + filename[1] file1 = targetdir + '/' + filename[0] + '-1' + filename[1]
@@ -274,7 +274,6 @@ class ComicPage:
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e)) raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
return file0, file1, file2, file3, file4 return file0, file1, file2, file3, file4
# def frameImage(self): # def frameImage(self):
# foreground = tuple(self.palette[:3]) # foreground = tuple(self.palette[:3])
# background = tuple(self.palette[-3:]) # background = tuple(self.palette[-3:])