@@ -504,7 +504,11 @@ def processAreaImageTag(imageTag, area, areaHeight, areaRot, areaWidth, imagedir
504504 if frameClipartFileName is not None :
505505 # we set the transx, transy, and areaRot for the clipart to zero, because our current pdf object
506506 # already has these transformations applied. So don't do it twice.
507- insertClipartFile (frameClipartFileName , [], 0 , areaWidth , areaHeight , frameAlpha , pdf , 0 , 0 , False , False )
507+ # flipX and flipY are also set to false because it cause an exception in PIL
508+ # therefore, even if the CEWE software offers the possibility to flip the clipart frame, cewe2pdf
509+ # remains unable to render it
510+ colorreplacements , flipX , flipY = getClipConfig (imageTag )
511+ insertClipartFile (frameClipartFileName , colorreplacements , 0 , areaWidth , areaHeight , frameAlpha , pdf , 0 , 0 , False , False , None )
508512
509513 for decorationTag in area .findall ('decoration' ):
510514 processAreaDecorationTag (decorationTag , areaHeight , areaWidth , pdf )
@@ -983,27 +987,11 @@ def loadClipart(fileName) -> ClpFile:
983987 return newClpFile
984988
985989
986- def processAreaClipartTag (clipartElement , areaHeight , areaRot , areaWidth , pdf , transx , transy , alpha ):
987- clipartID = int (clipartElement .get ('designElementId' ))
988- # print("Warning: clip-art elements are not supported. (designElementId = {})".format(clipartID))
989-
990- # designElementId 0 seems to be a special empty placeholder
991- if clipartID == 0 :
992- return
993-
994- # Load the clipart
995- fileName = None
996- if clipartID in clipartDict :
997- fileName = clipartDict [clipartID ]
998- # verify preconditions to avoid exception loading the clip art file, which would break the page count
999- if not fileName :
1000- logging .error (f"Problem getting file name for clipart ID: { clipartID } " )
1001- return
1002-
990+ def getClipConfig (Element ):
1003991 colorreplacements = []
1004992 flipX = False
1005993 flipY = False
1006- for clipconfig in clipartElement .findall ('ClipartConfiguration' ):
994+ for clipconfig in Element .findall ('ClipartConfiguration' ):
1007995 for clipcolors in clipconfig .findall ('colors' ):
1008996 for clipcolor in clipcolors .findall ('color' ):
1009997 source = '#' + clipcolor .get ('source' ).upper ()[1 :7 ]
@@ -1017,11 +1005,36 @@ def processAreaClipartTag(clipartElement, areaHeight, areaRot, areaWidth, pdf, t
10171005 flipX = True
10181006 if mirror in ('x' , 'both' ):
10191007 flipY = True
1008+ return colorreplacements , flipX , flipY
1009+
1010+
1011+ def processAreaClipartTag (clipartElement , areaHeight , areaRot , areaWidth , pdf , transx , transy , clipArtDecoration ):
1012+ clipartID = int (clipartElement .get ('designElementId' ))
1013+
1014+ # designElementId 0 seems to be a special empty placeholder
1015+ if clipartID == 0 :
1016+ return
1017+
1018+ # Load the clipart
1019+ fileName = None
1020+ if clipartID in clipartDict :
1021+ fileName = clipartDict [clipartID ]
1022+ # verify preconditions to avoid exception loading the clip art file, which would break the page count
1023+ if not fileName :
1024+ logging .error (f"Problem getting file name for clipart ID: { clipartID } " )
1025+ return
1026+
1027+ alpha = 255
1028+ if clipArtDecoration is not None :
1029+ alphatext = clipArtDecoration .get ('alpha' ) # alpha attribute
1030+ if alphatext is not None :
1031+ alpha = int ((float (alphatext )) * 255 )
10201032
1021- insertClipartFile (fileName , colorreplacements , transx , areaWidth , areaHeight , alpha , pdf , transy , areaRot , flipX , flipY )
1033+ colorreplacements , flipX , flipY = getClipConfig (clipartElement )
1034+ insertClipartFile (fileName , colorreplacements , transx , areaWidth , areaHeight , alpha , pdf , transy , areaRot , flipX , flipY , clipArtDecoration )
10221035
10231036
1024- def insertClipartFile (fileName :str , colorreplacements , transx , areaWidth , areaHeight , alpha , pdf , transy , areaRot , flipX , flipY ):
1037+ def insertClipartFile (fileName :str , colorreplacements , transx , areaWidth , areaHeight , alpha , pdf , transy , areaRot , flipX , flipY , decoration ):
10251038 img_transx = transx
10261039
10271040 res = image_res # use the foreground resolution setting for clipart
@@ -1048,6 +1061,8 @@ def insertClipartFile(fileName:str, colorreplacements, transx, areaWidth, areaHe
10481061 pdf .drawImage (ImageReader (clipart .pngMemFile ),
10491062 f * - 0.5 * areaWidth , f * - 0.5 * areaHeight ,
10501063 width = f * areaWidth , height = f * areaHeight , mask = 'auto' )
1064+ if decoration is not None :
1065+ processAreaDecorationTag (decoration , areaHeight , areaWidth , pdf )
10511066 pdf .rotate (areaRot )
10521067 pdf .translate (- img_transx , - transy )
10531068
@@ -1103,15 +1118,11 @@ def processElements(additional_fonts, fotobook, imagedir,
11031118 # Clip-Art
11041119 # In the clipartarea there are two similar elements, the <designElementIDs> and the <clipart>.
11051120 # We are using the <clipart> element here
1106- if area .get ('areatype' ) == 'clipartarea' : # only look for alpha and clipart within clipartarea tags
1107- alpha = 255
1108- decoration = area .find ('decoration' ) # decoration tag
1109- if decoration is not None :
1110- alphatext = decoration .get ('alpha' ) # alpha attribute
1111- if alphatext is not None :
1112- alpha = int ((float (alphatext )) * 255 )
1121+ if area .get ('areatype' ) == 'clipartarea' :
1122+ # within clipartarea tags we need the decoration for alpha and border information
1123+ decoration = area .find ('decoration' )
11131124 for clipartElement in area .findall ('clipart' ):
1114- processAreaClipartTag (clipartElement , areaHeight , areaRot , areaWidth , pdf , transx , transy , alpha )
1125+ processAreaClipartTag (clipartElement , areaHeight , areaRot , areaWidth , pdf , transx , transy , decoration )
11151126 return
11161127
11171128
0 commit comments