-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathborders.py
More file actions
74 lines (64 loc) · 2.96 KB
/
Copy pathborders.py
File metadata and controls
74 lines (64 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Border-decoration rendering for CEWE areas."""
from math import floor
import reportlab.lib.colors
from reportlab.platypus import Table
from corners import buildCornerPath, hasImplementedCorners
from renderContext import RenderContext
def processDecorationBorders(decoration, areaHeight, areaWidth, pdf,
context: RenderContext, cornersInfo=None):
"""Draw the border decoration for an already-positioned area."""
mcf2rl = context.mcf_to_reportlab
for border in decoration.findall('border'):
if border.get('enabled') is not None and border.get('enabled') != '1':
return
borderWidth = 1
widthText = border.get('width')
if widthText is not None:
borderWidth = mcf2rl * floor(float(widthText))
borderColor = reportlab.lib.colors.blue
colorText = border.get('color')
if colorText is not None:
# CEWE ignores border transparency and sometimes stores a border
# with no visible colour to mean no border.
if colorText == '#00000000':
return
borderColor = reportlab.lib.colors.HexColor(colorText)
adjustment = 0
gap = 0
gapText = border.get('gap')
if gapText is not None:
gap = mcf2rl * floor(float(gapText))
position = border.get('position')
if position == "insideWithGap":
adjustment = -borderWidth * 0.5 - gap
if position == "inside":
adjustment = -borderWidth * 0.5
if position == "outside":
adjustment = borderWidth * 0.5
if position == "outsideWithGap":
adjustment = borderWidth * 0.5 + gap
frameBottomLeftX = -0.5 * (mcf2rl * areaWidth) - adjustment
frameBottomLeftY = -0.5 * (mcf2rl * areaHeight) - adjustment
frameWidth = mcf2rl * areaWidth + 2 * adjustment
frameHeight = mcf2rl * areaHeight + 2 * adjustment
if hasImplementedCorners(cornersInfo):
path = buildCornerPath(pdf, frameBottomLeftX, frameBottomLeftY,
frameWidth, frameHeight, mcf2rl,
cornersInfo, adjustment)
pdf.saveState()
pdf.setLineWidth(borderWidth)
pdf.setStrokeColor(borderColor)
pdf.drawPath(path, stroke=1, fill=0)
pdf.restoreState()
else:
# Preserve the historic Table rendering for rectangular borders so
# existing regression PDFs remain unchanged.
borderTable = Table(
data=[[None]], colWidths=frameWidth, rowHeights=frameHeight,
style=[
('ALIGN', (0, 0), (0, 0), 'CENTER'),
('BOX', (0, 0), (0, 0), borderWidth, borderColor),
('VALIGN', (0, 0), (0, 0), 'MIDDLE'),
])
borderTable.wrapOn(pdf, frameWidth, frameHeight)
borderTable.drawOn(pdf, frameBottomLeftX, frameBottomLeftY)