/usr/share/pyshared/z3c/rml/template.py is in python-z3c.rml 2.0.0-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | ##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Style Related Element Processing
$Id: template.py 128839 2012-12-21 03:03:18Z srichter $
"""
__docformat__ = "reStructuredText"
import zope.interface
from reportlab import platypus
from z3c.rml import attr, directive, interfaces, occurence
from z3c.rml import canvas, flowable, stylesheet
class IStory(flowable.IFlow):
"""The story of the PDF file."""
occurence.containing(
*flowable.IFlow.getTaggedValue('directives'))
firstPageTemplate = attr.Text(
title=u'First Page Template',
description=u'The first page template to be used.',
default=None,
required=False)
class Story(flowable.Flow):
signature = IStory
def process(self):
self.parent.flowables = super(Story, self).process()
self.parent.doc._firstPageTemplateIndex = self.getFirstPTIndex()
def getFirstPTIndex(self):
args = dict(self.getAttributeValues(select=('firstPageTemplate',)))
fpt = args.pop('firstPageTemplate', None)
if fpt is None:
return 0
for idx, pageTemplate in enumerate(self.parent.doc.pageTemplates):
if pageTemplate.id == fpt:
return idx
raise ValueError('%r is not a correct page template id.' %fpt)
class IFrame(interfaces.IRMLDirectiveSignature):
"""A frame on a page."""
x1 = attr.Measurement(
title=u'X-Position',
description=u'The X-Position of the lower-left corner of the frame.',
allowPercentage=True,
required=True)
y1 = attr.Measurement(
title=u'Y-Position',
description=u'The Y-Position of the lower-left corner of the frame.',
allowPercentage=True,
required=True)
width = attr.Measurement(
title=u'Width',
description=u'The width of the frame.',
allowPercentage=True,
required=True)
height = attr.Measurement(
title=u'Height',
description=u'The height of the frame.',
allowPercentage=True,
required=True)
id = attr.Text(
title=u'Id',
description=u'The id of the frame.',
required=False)
leftPadding = attr.Measurement(
title=u'Left Padding',
description=u'The left padding of the frame.',
default=0,
required=False)
rightPadding = attr.Measurement(
title=u'Right Padding',
description=u'The right padding of the frame.',
default=0,
required=False)
topPadding = attr.Measurement(
title=u'Top Padding',
description=u'The top padding of the frame.',
default=0,
required=False)
bottomPadding = attr.Measurement(
title=u'Bottom Padding',
description=u'The bottom padding of the frame.',
default=0,
required=False)
showBoundary = attr.Boolean(
title=u'Show Boundary',
description=u'A flag to show the boundary of the frame.',
required=False)
class Frame(directive.RMLDirective):
signature = IFrame
def process(self):
# get the page size
size = self.parent.pt.pagesize
if size is None:
size = self.parent.parent.parent.doc.pagesize
# Get the arguments
args = dict(self.getAttributeValues())
# Deal with percentages
for name, dir in (('x1', 0), ('y1', 1), ('width', 0), ('height', 1)):
if isinstance(args[name], basestring) and args[name].endswith('%'):
args[name] = float(args[name][:-1])/100*size[dir]
frame = platypus.Frame(**args)
self.parent.frames.append(frame)
class IPageGraphics(canvas.IDrawing):
"""Define the page graphics for the page template."""
class PageGraphics(directive.RMLDirective):
zope.interface.implements(interfaces.ICanvasManager)
signature = IPageGraphics
def process(self):
def drawOnCanvas(canv, doc):
canv.saveState()
self.canvas = canv
drawing = canvas.Drawing(self.element, self)
drawing.process()
canv.restoreState()
self.parent.pt.onPage = drawOnCanvas
class IPageTemplate(interfaces.IRMLDirectiveSignature):
"""Define a page template."""
occurence.containing(
occurence.OneOrMore('frame', IFrame),
occurence.ZeroOrOne('pageGraphics', IPageGraphics),
)
id = attr.Text(
title=u'Id',
description=u'The id of the template.',
required=True)
pagesize = attr.PageSize(
title=u'Page Size',
description=u'The Page Size.',
required=False)
autoNextTemplate = attr.String(
title=u'Auto Next Page Template',
description=u'The page template to use automatically for the next page.',
required=False)
class PageTemplate(directive.RMLDirective):
signature = IPageTemplate
attrMapping = {'autoNextTemplate': 'autoNextPageTemplate'}
factories = {
'frame': Frame,
'pageGraphics': PageGraphics,
}
def process(self):
args = dict(self.getAttributeValues(attrMapping=self.attrMapping))
pagesize = args.pop('pagesize', None)
self.frames = []
self.pt = platypus.PageTemplate(**args)
self.processSubDirectives()
self.pt.frames = self.frames
if pagesize:
self.pt.pagesize = pagesize
self.parent.parent.doc.addPageTemplates(self.pt)
class ITemplate(interfaces.IRMLDirectiveSignature):
"""Define a page template."""
occurence.containing(
occurence.OneOrMore('pageTemplate', IPageTemplate),
)
pagesize = attr.PageSize(
title=u'Page Size',
description=u'The Page Size.',
required=False)
rotation = attr.Integer(
title=u'Rotation',
description=u'The rotation of the page in multiples of 90 degrees.',
required=False)
leftMargin = attr.Measurement(
title=u'Left Margin',
description=u'The left margin of the template.',
default=0,
required=False)
rightMargin = attr.Measurement(
title=u'Right Margin',
description=u'The right margin of the template.',
default=0,
required=False)
topMargin = attr.Measurement(
title=u'Top Margin',
description=u'The top margin of the template.',
default=0,
required=False)
bottomMargin = attr.Measurement(
title=u'Bottom Margin',
description=u'The bottom margin of the template.',
default=0,
required=False)
showBoundary = attr.Boolean(
title=u'Show Boundary',
description=u'A flag to show the boundary of the template.',
required=False)
allowSplitting = attr.Boolean(
title=u'Allow Splitting',
description=u'A flag to allow splitting over multiple templates.',
required=False)
title = attr.Text(
title=u'Title',
description=u'The title of the PDF document.',
required=False)
author = attr.Text(
title=u'Author',
description=u'The author of the PDF document.',
required=False)
class Template(directive.RMLDirective):
signature = ITemplate
factories = {
'pageTemplate': PageTemplate,
}
def process(self):
args = self.getAttributeValues()
args += self.parent.getAttributeValues(
select=('debug', 'compression', 'invariant'),
attrMapping={'debug': '_debug', 'compression': 'pageCompression'})
args += (('cropMarks', self.parent.cropMarks),)
self.parent.doc = platypus.BaseDocTemplate(
self.parent.outputFile, **dict(args))
self.processSubDirectives()
|