Skip to content

Commit

Permalink
Allow frame on cliparts
Browse files Browse the repository at this point in the history
  • Loading branch information
AnEnglishmanInNorway committed Jan 5, 2025
1 parent 9b0c706 commit 3bf11a4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cewe2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def processAreaImageTag(imageTag, area, areaHeight, areaRot, areaWidth, imagedir
# therefore, even if the CEWE software offers the possibility to flip the clipart frame, cewe2pdf
# remains unable to render it
colorreplacements, flipX, flipY = getClipConfig(imageTag)
insertClipartFile(frameClipartFileName, colorreplacements, 0, areaWidth, areaHeight, frameAlpha, pdf, 0, 0, False, False)
insertClipartFile(frameClipartFileName, colorreplacements, 0, areaWidth, areaHeight, frameAlpha, pdf, 0, 0, False, False, None)

for decorationTag in area.findall('decoration'):
processAreaDecorationTag(decorationTag, areaHeight, areaWidth, pdf)
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def getClipConfig(Element):
return colorreplacements, flipX, flipY


def processAreaClipartTag(clipartElement, areaHeight, areaRot, areaWidth, pdf, transx, transy, alpha):
def processAreaClipartTag(clipartElement, areaHeight, areaRot, areaWidth, pdf, transx, transy, clipArtDecoration):
clipartID = int(clipartElement.get('designElementId'))
# print("Warning: clip-art elements are not supported. (designElementId = {})".format(clipartID))

Expand All @@ -1025,12 +1025,17 @@ def processAreaClipartTag(clipartElement, areaHeight, areaRot, areaWidth, pdf, t
logging.error(f"Problem getting file name for clipart ID: {clipartID}")
return

colorreplacements, flipX, flipY = getClipConfig(clipartElement)
alpha = 255
if clipArtDecoration is not None:
alphatext = clipArtDecoration.get('alpha') # alpha attribute
if alphatext is not None:
alpha = int((float(alphatext)) * 255)

insertClipartFile(fileName, colorreplacements, transx, areaWidth, areaHeight, alpha, pdf, transy, areaRot, flipX, flipY)
colorreplacements, flipX, flipY = getClipConfig(clipartElement)
insertClipartFile(fileName, colorreplacements, transx, areaWidth, areaHeight, alpha, pdf, transy, areaRot, flipX, flipY, clipArtDecoration)


def insertClipartFile(fileName:str, colorreplacements, transx, areaWidth, areaHeight, alpha, pdf, transy, areaRot, flipX, flipY):
def insertClipartFile(fileName:str, colorreplacements, transx, areaWidth, areaHeight, alpha, pdf, transy, areaRot, flipX, flipY, decoration):
img_transx = transx

res = image_res # use the foreground resolution setting for clipart
Expand All @@ -1057,6 +1062,8 @@ def insertClipartFile(fileName:str, colorreplacements, transx, areaWidth, areaHe
pdf.drawImage(ImageReader(clipart.pngMemFile),
f * -0.5 * areaWidth, f * -0.5 * areaHeight,
width=f * areaWidth, height=f * areaHeight, mask='auto')
if decoration is not None:
processAreaDecorationTag(decoration, areaHeight, areaWidth, pdf)
pdf.rotate(areaRot)
pdf.translate(-img_transx, -transy)

Expand Down Expand Up @@ -1113,14 +1120,9 @@ def processElements(additional_fonts, fotobook, imagedir,
# In the clipartarea there are two similar elements, the <designElementIDs> and the <clipart>.
# We are using the <clipart> element here
if area.get('areatype') == 'clipartarea': # only look for alpha and clipart within clipartarea tags
alpha = 255
decoration = area.find('decoration') # decoration tag
if decoration is not None:
alphatext = decoration.get('alpha') # alpha attribute
if alphatext is not None:
alpha = int((float(alphatext)) * 255)
for clipartElement in area.findall('clipart'):
processAreaClipartTag(clipartElement, areaHeight, areaRot, areaWidth, pdf, transx, transy, alpha)
processAreaClipartTag(clipartElement, areaHeight, areaRot, areaWidth, pdf, transx, transy, decoration)
return


Expand Down

0 comments on commit 3bf11a4

Please sign in to comment.