• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / z3c.rml / 16098868126

14 Apr 2025 06:50AM UTC coverage: 87.385%. Remained the same
16098868126

push

github

icemac
Back to development: 5.1

561 of 792 branches covered (70.83%)

Branch coverage included in aggregate %.

3990 of 4416 relevant lines covered (90.35%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.18
/src/z3c/rml/platypus.py
1
##############################################################################
2
#
3
# Copyright (c) 2007 Zope Foundation and Contributors.
4
# All Rights Reserved.
5
#
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14
"""Style Related Element Processing
15
"""
16
import reportlab.platypus.flowables
1✔
17
import reportlab.rl_config
1✔
18
import zope.interface
1✔
19
from reportlab.rl_config import overlapAttachedSpace
1✔
20

21
from z3c.rml import interfaces
1✔
22

23

24
# Fix problem with reportlab 3.1.44
25
class KeepInFrame(reportlab.platypus.flowables.KeepInFrame):
1✔
26
    pass
1✔
27

28
    def __init__(self, maxWidth, maxHeight, content=[], mergeSpace=1,
1✔
29
                 mode='shrink', name='', hAlign='LEFT', vAlign='BOTTOM',
30
                 fakeWidth=None):
31

32
        self.name = name
1✔
33
        self.maxWidth = maxWidth
1✔
34
        self.maxHeight = maxHeight
1✔
35
        self.mode = mode
1✔
36
        assert mode in ('error', 'overflow', 'shrink', 'truncate'), \
1✔
37
            f'{self.identity()} invalid mode value {mode}'
38
        # This is an unnecessary check, since wrap() handles None just fine!
39
        # assert maxHeight>=0,  \
40
        #       '%s invalid maxHeight value %s' % (self.identity(),maxHeight)
41
        if mergeSpace is None:
1!
42
            mergeSpace = overlapAttachedSpace
×
43
        self.mergespace = mergeSpace
1✔
44
        self._content = content or []
1✔
45
        self.vAlign = vAlign
1✔
46
        self.hAlign = hAlign
1✔
47
        self.fakeWidth = fakeWidth
1✔
48

49

50
class BaseFlowable(reportlab.platypus.flowables.Flowable):
1✔
51
    def __init__(self, *args, **kw):
1✔
52
        reportlab.platypus.flowables.Flowable.__init__(self)
1✔
53
        self.args = args
1✔
54
        self.kw = kw
1✔
55

56
    def wrap(self, *args):
1✔
57
        return (0, 0)
1✔
58

59
    def draw(self):
1✔
60
        pass
×
61

62

63
class Illustration(reportlab.platypus.flowables.Flowable):
1✔
64
    def __init__(self, processor, width, height):
1✔
65
        self.processor = processor
1✔
66
        self.width = width
1✔
67
        self.height = height
1✔
68

69
    def wrap(self, *args):
1✔
70
        return (self.width, self.height)
1✔
71

72
    def draw(self):
1✔
73
        # Import here to avoid recursive imports
74
        from z3c.rml import canvas
1✔
75
        self.canv.saveState()
1✔
76
        drawing = canvas.Drawing(
1✔
77
            self.processor.element, self.processor)
78
        zope.interface.alsoProvides(drawing, interfaces.ICanvasManager)
1✔
79
        drawing.canvas = self.canv
1✔
80
        drawing.process()
1✔
81
        self.canv.restoreState()
1✔
82

83

84
class BookmarkPage(BaseFlowable):
1✔
85
    def draw(self):
1✔
86
        self.canv.bookmarkPage(*self.args, **self.kw)
1✔
87

88

89
class Bookmark(BaseFlowable):
1✔
90
    def draw(self):
1✔
91
        self.canv.bookmarkHorizontal(*self.args, **self.kw)
1✔
92

93

94
class OutlineAdd(BaseFlowable):
1✔
95
    def draw(self):
1✔
96
        if self.kw.get('key', None) is None:
1!
97
            self.kw['key'] = str(hash(self))
1✔
98
        self.canv.bookmarkPage(self.kw['key'])
1✔
99
        self.canv.addOutlineEntry(**self.kw)
1✔
100

101

102
class Link(reportlab.platypus.flowables._Container,
1✔
103
           reportlab.platypus.flowables.Flowable):
104

105
    def __init__(self, content, **args):
1✔
106
        self._content = content
1✔
107
        self.args = args
1✔
108

109
    def wrap(self, availWidth, availHeight):
1✔
110
        self.width, self.height = reportlab.platypus.flowables._listWrapOn(
1✔
111
            self._content, availWidth, self.canv)
112
        return self.width, self.height
1✔
113

114
    def drawOn(self, canv, x, y, _sW=0, scale=1.0, content=None, aW=None):
1✔
115
        '''we simulate being added to a frame'''
116
        pS = 0
1✔
117
        if aW is None:
1!
118
            aW = self.width
1✔
119
        aW = scale * (aW + _sW)
1✔
120
        if content is None:
1!
121
            content = self._content
1✔
122
        y += self.height * scale
1✔
123

124
        startX = x
1✔
125
        startY = y
1✔
126
        totalWidth = 0
1✔
127
        totalHeight = 0
1✔
128

129
        for c in content:
1✔
130
            w, h = c.wrapOn(canv, aW, 0xfffffff)
1✔
131
            if w < reportlab.rl_config._FUZZ or h < reportlab.rl_config._FUZZ:
1!
132
                continue
×
133
            if c is not content[0]:
1!
134
                h += max(c.getSpaceBefore() - pS, 0)
×
135
            y -= h
1✔
136
            c.drawOn(canv, x, y, _sW=aW - w)
1✔
137
            if c is not content[-1]:
1!
138
                pS = c.getSpaceAfter()
×
139
                y -= pS
×
140
            totalWidth += w
1✔
141
            totalHeight += h
1✔
142
        rectangle = [startX, startY - totalHeight,
1✔
143
                     startX + totalWidth, startY]
144
        if 'url' in self.args:
1✔
145
            canv.linkURL(rect=rectangle, **self.args)
1✔
146
        else:
147
            canv.linkAbsolute('', Rect=rectangle, **self.args)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc