Skip to content

Commit ff5cd09

Browse files
Merge pull request #205 from AnEnglishmanInNorway/emptypageone
Fixes #203, the issue of an empty page one going missing. Also fixes background issues
2 parents 599a3a5 + 27aa708 commit ff5cd09

File tree

10 files changed

+304
-25
lines changed

10 files changed

+304
-25
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ nosetests.xml
4242

4343
*.mcf~
4444
*.xml~
45+
* - Copy.*
4546

4647
/cewe_folder.txt
47-
/cewe2pdf - Copy.py
4848
/cewe2pdf.iss
4949
/cewe2pdf.pyproj.user
5050
/cewe2pdf.spec
@@ -69,3 +69,4 @@ nosetests.xml
6969
/tests/testClipartColorReplacement/test_clipart_colorreplacement.mcfx.pdf
7070
/tests/testClipartColorReplacement/test_clipart_colorreplacement.mcf.pdf
7171
/tests/testbackgrounds/allblackbackgrounds.mcf.pdf
72+
/tests/testEmptyPageOne/test_emptyPageOne.mcf.pdf

cewe2pdf.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ def processBackground(backgroundTags, bg_notFoundDirList, cewe_folder, backgroun
368368
backgroundTag = curTag
369369
break
370370

371+
if pagetype == PageType.Normal and isAlbumDoubleSide(productstyle) and backgroundTag.get('alignment') == "3":
372+
areaWidth = areaWidth / 2
373+
areaXOffset = areaXOffset + areaWidth
374+
371375
if (cewe_folder and backgroundTag is not None
372376
and backgroundTag.get('designElementId') is not None):
373377
bg = backgroundTag.get('designElementId')
@@ -392,17 +396,8 @@ def processBackground(backgroundTags, bg_notFoundDirList, cewe_folder, backgroun
392396
try:
393397
bgPath = ""
394398
bgPath = findFileInDirs([bg + '.bmp', bg + '.webp', bg + '.jpg'], backgroundLocations)
395-
396-
# Feb 2025, removed single/double side differentiation here, which basically cured
397-
# issue https://github.com/bash0/cewe2pdf/issues/198. I can only imagine that we have
398-
# tried to cure single/double page problems with "partial fixes" through the years
399-
# without understanding or testing all the cases. It is true that this solution does
400-
# not show the "forced empty pages" on the inside of the covers as white, a la CEWE,
401-
# but rather uses the background colour of the cover page. This whiteness is what
402-
# issue 198 is really complaining about, and I agree with it. Cover page colour is
403-
# a better choice when we are creating a pdf.
404-
405399
logging.debug(f"Reading background file: {bgPath}")
400+
406401
# webp doesn't work with PIL.Image.open in Anaconda 5.3.0 on Win10
407402
imObj = PIL.Image.open(bgPath)
408403
# create a in-memory byte array of the image file
@@ -411,10 +406,11 @@ def processBackground(backgroundTags, bg_notFoundDirList, cewe_folder, backgroun
411406
imObj = imObj.convert("RGB")
412407
imObj.save(memFileHandle, 'jpeg')
413408
memFileHandle.seek(0)
414-
# im = imread(bgpath) #does not work with 1-bit images
415-
pdf.drawImage(ImageReader(
416-
memFileHandle), f * areaXOffset, 0, width=f * areaWidth, height=f * areaHeight)
409+
417410
# pdf.drawImage(ImageReader(bgpath), f * ax, 0, width=f * aw, height=f * ah)
411+
# but im = ImageReader(bgpath) does not work with 1-bit images,so ...
412+
pdf.drawImage(ImageReader(memFileHandle), f * areaXOffset, 0, width=f * areaWidth, height=f * areaHeight)
413+
418414
except Exception:
419415
if bgPath not in bg_notFoundDirList:
420416
logging.error("Could not find background or error when adding to pdf")
@@ -1741,7 +1737,8 @@ def convertMcf(albumname, keepDoublePages: bool, pageNumbers=None, mcfxTmpDir=No
17411737
# cover pages. Add 2 so that pagecount represents the actual number of printed pdf pages we expect in the normal single sided
17421738
# pdf print (a basic album is 26 inside pages, plus front and back cover, i.e. 28). If we use keepDoublePages, then we'll
17431739
# actually be producing 2 more (the inside covers) but halving the number of final output pdf pages, making 15 double pages.
1744-
# There is also a totalpages attribute in the mcf, but oddly in my files it is 3 more than the normalpages value. Why not 4 more?
1740+
# There is also a totalpages attribute in the mcf, but in my files it is 5 more than the normalpages value. Why not 4 more? I
1741+
# guess that may be because it is a count of the <page> elements and not actually related to the number of printed pages.
17451742
imagedir = fotobook.get('imagedir')
17461743

17471744
# generate a list of available clip-arts
@@ -1779,7 +1776,7 @@ def IsOddPage(n):
17791776
lastpage = IsLastPage(n) # bool assign is clearer with parens so pylint: disable=superfluous-parens
17801777

17811778
# The <page> sections all have a pagenr attribute. The normal pages run from pagenr 1 to pagenr 26 while there are
1782-
# actually FIVE page elements with pagenr 0 in an album file, 4 coming before pagenr 1 and 1 after pagenr 26
1779+
# actually FIVE page elements with pagenr 0 in a default album file, 4 coming before pagenr 1 and 1 after pagenr 26
17831780
if isAlbumProduct(productstyle) and ((n == 0) or IsBackCover(n)): # clearest like this so pylint: disable=consider-using-in
17841781
fullcoverpages = [i for i in
17851782
fotobook.findall("./page[@pagenr='0'][@type='FULLCOVER']")
@@ -1807,14 +1804,15 @@ def IsOddPage(n):
18071804
page = [i for i in
18081805
fotobook.findall("./page[@pagenr='0'][@type='EMPTY']")
18091806
+ fotobook.findall("./page[@pagenr='0'][@type='emptypage']")
1810-
if i.find("./area") is not None]
1807+
if i.find("./area") is not None or i.find("./background[@alignment='1']") is not None]
18111808
if len(page) >= 1:
18121809
page = page[0]
18131810
# If there is on page 1 only text, the area-tag is still on page 0.
18141811
# So this will either include the text (which is put in page 0),
18151812
# or the packground which is put in page 1.
18161813
else:
1817-
page = None # if we find no empty page with an area tag, we need to set this to None to prevent an exception later.
1814+
logging.error(f'Failed to locate initial emptypage when processing page {n}')
1815+
page = None
18181816

18191817
# Look for the the first page and set it up for processing
18201818
realFirstPageList = fotobook.findall("./page[@pagenr='1'][@type='normalpage']")
@@ -1845,14 +1843,15 @@ def IsOddPage(n):
18451843
page = [i for i in
18461844
fotobook.findall("./page[@pagenr='0'][@type='EMPTY']")
18471845
+ fotobook.findall("./page[@pagenr='0'][@type='emptypage']")
1848-
if i.find("./area") is None]
1846+
if i.find("./area") is None or i.find("./background[@alignment='3']") is not None]
18491847
if len(page) >= 1:
18501848
# set up to process the special section for the inside cover
18511849
page = page[0]
18521850
pageNumber = n + 1
18531851
oddpage = IsOddPage(pageNumber)
18541852
pagetype = PageType.BackInsideCover
18551853
else:
1854+
logging.error(f'Failed to locate final emptypage when processing last page {n}')
18561855
page = None # catastrophe
18571856

18581857
else:

cewe2pdf.pyproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@
9696
<Content Include="tests\testClipartColorReplacement\test_clipart_colorreplacement_mcf-Dateien\folderid.xml" />
9797
<Content Include="tests\testClipart\cewe2pdf.ini" />
9898
<Content Include="tests\testClipart\testClipart.mcf" />
99-
<Content Include="tests\testClipart\__pycache__\test_drawClipart.cpython-37-pytest-5.4.1.pyc" />
99+
<Content Include="tests\testEmptyPageOne\additional_fonts.txt" />
100+
<Content Include="tests\testEmptyPageOne\cewe2pdf.ini" />
101+
<Content Include="tests\testEmptyPageOne\test_emptyPageOne.mcf" />
102+
<Content Include="tests\testEmptyPageOne\test_emptyPageOne_mcf-Dateien\folderid.xml" />
100103
<Content Include="tests\testFontDoesNotExist\additional_fonts.txt" />
101104
<Content Include="tests\testFontDoesNotExist\cewe2pdf.ini" />
102105
<Content Include="tests\testFontDoesNotExist\testFontDoesNotExist.mcf" />
103-
<Content Include="tests\testFontDoesNotExist\__pycache__\test_fontDoesNotExist.cpython-37-pytest-5.4.1.pyc" />
104106
<Content Include="tests\testMcfxExtraction\McfOriginals\testMcfxExtraction.mcf" />
105107
<Content Include="tests\testMcfxExtraction\McfOriginals\testMcfxExtraction_mcf-Dateien\20200306_111748.jpg" />
106108
<Content Include="tests\testMcfxExtraction\McfOriginals\testMcfxExtraction_mcf-Dateien\folderid.xml" />
@@ -130,6 +132,8 @@
130132
<Compile Include="runAllTests.py" />
131133
<Compile Include="tests\testClipartColorReplacement\test_clipartColorReplacement.py" />
132134
<Compile Include="tests\testbackgrounds\test_backgrounds.py" />
135+
<Compile Include="tests\testClipart\test_drawClipart.py" />
136+
<Compile Include="tests\testEmptyPageOne\test_emptyPageOne.py" />
133137
<Compile Include="tests\testFontDoesNotExist\test_fontDoesNotExist.py" />
134138
<Compile Include="tests\testMcfxExtraction\test_McfxExtraction.py" />
135139
<Compile Include="tests\test_simpleBook.py" />
@@ -170,9 +174,9 @@
170174
<Folder Include="tests\testClipartColorReplacement\" />
171175
<Folder Include="tests\testClipartColorReplacement\test_clipart_colorreplacement_mcf-Dateien\" />
172176
<Folder Include="tests\testClipart\" />
173-
<Folder Include="tests\testClipart\__pycache__\" />
177+
<Folder Include="tests\testEmptyPageOne\" />
178+
<Folder Include="tests\testEmptyPageOne\test_emptyPageOne_mcf-Dateien\" />
174179
<Folder Include="tests\testFontDoesNotExist\" />
175-
<Folder Include="tests\testFontDoesNotExist\__pycache__\" />
176180
<Folder Include="tests\testMcfxExtraction\" />
177181
<Folder Include="tests\testMcfxExtraction\McfOriginals\" />
178182
<Folder Include="tests\testMcfxExtraction\McfOriginals\testMcfxExtraction_mcf-Dateien\" />

tests/testClipart/test_drawClipart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def tryToBuildBook(keepDoublePages):
3232
# we could also test more sophisticated things, like colors or compare images.
3333
readPdf = Pdf.open(outFile)
3434
numPages = len(readPdf.pages)
35-
assert numPages == 5
35+
assert numPages == 6, f"Expected 6 pages (4 normal plus 2 covers), found {numPages}"
3636

3737
#os.remove(outFile)
3838

tests/testEmptyPageOne/additional_fonts.txt

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[DEFAULT]
2+
cewe_folder = tests/
3+
hpsFolder = tests/hps
4+
extraBackgroundFolders = ../Resources/photofun/backgrounds/201.jpg
5+
6+
insideCoverWhite = True

0 commit comments

Comments
 (0)