From 37fda4967a5f3451e74b191f6f4a60b6e0d34604 Mon Sep 17 00:00:00 2001 From: Vince Darley Date: Wed, 10 Dec 2025 22:35:22 +0000 Subject: [PATCH] Fix transparent border rendering and ALIGNVCENTER text alignment - Skip drawing borders when color has alpha channel = 00 (transparent) - Parse ALIGNVCENTER from textFormat element and vertically center text in frame - Fixes cover page text rendering issues where transparent borders appeared black and text was not centered despite ALIGNVCENTER attribute --- cewe2pdf.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/cewe2pdf.py b/cewe2pdf.py index bef8683..db7f690 100755 --- a/cewe2pdf.py +++ b/cewe2pdf.py @@ -449,6 +449,11 @@ def processDecorationBorders(decoration, areaHeight, areaWidth, pdf): bcolor = reportlab.lib.colors.blue if "color" in border.attrib: colorAttrib = border.get('color') + # Check if color has alpha channel (8 hex digits) and if it's transparent + # Format: #RRGGBBAA where AA is alpha (00 = transparent, FF = opaque) + if len(colorAttrib) == 9 and colorAttrib[7:9] == '00': + # Transparent border - don't draw it + return bcolor = reportlab.lib.colors.HexColor(colorAttrib) adjustment = 0 @@ -637,6 +642,16 @@ def processAreaTextTag(textTag, additional_fonts, area, areaHeight, areaRot, are bottomPad = mcf2rl * tablebmarg topPad = mcf2rl * tabletmarg + # Parse textFormat element for vertical centering alignment + verticallyCenter = False + textFormatElement = textTag.find('textFormat') + if textFormatElement is not None: + # Read alignment attribute to check for ALIGNVCENTER + alignmentAttrib = textFormatElement.get('Alignment') + if alignmentAttrib is not None: + if 'ALIGNVCENTER' in alignmentAttrib: + verticallyCenter = True + # if this is text art, then we do the whole thing differently. cwtextart = area.findall('decoration/cwtextart') if len(cwtextart) > 0: @@ -835,7 +850,19 @@ def processAreaTextTag(textTag, additional_fonts, area, areaHeight, areaRot, are frameWidth = max(frameWidth, finalTotalWidth) - newFrame = ColorFrame(frameBottomLeft_x, frameBottomLeft_y, + # Apply vertical centering if ALIGNVCENTER is specified + # When vertically centering, shrink frame to fit text exactly and position it centered + verticalCenterOffset = 0 + if verticallyCenter and finalTotalHeight < (mcf2rl * areaHeight): + # Original area height from XML + originalFrameHeight = mcf2rl * areaHeight + # Use exact text height for the frame + frameHeight = finalTotalHeight + # Calculate offset to center this smaller frame in the original area + emptySpace = originalFrameHeight - finalTotalHeight + verticalCenterOffset = -emptySpace / 2.0 # Negative = move down + + newFrame = ColorFrame(frameBottomLeft_x, frameBottomLeft_y + verticalCenterOffset, frameWidth, frameHeight, leftPadding=leftPad, bottomPadding=bottomPad, rightPadding=rightPad, topPadding=topPad,