/usr/share/pyshared/z3c/rml/stylesheet.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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | ##############################################################################
#
# 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: stylesheet.py 128798 2012-12-20 04:07:15Z srichter $
"""
__docformat__ = "reStructuredText"
import copy
import reportlab.lib.styles
import reportlab.lib.enums
import reportlab.platypus
from z3c.rml import attr, directive, interfaces, occurence, special
class IInitialize(interfaces.IRMLDirectiveSignature):
"""Do some RML processing initialization."""
occurence.containing(
occurence.ZeroOrMore('name', special.IName),
occurence.ZeroOrMore('alias', special.IAlias),
)
class Initialize(directive.RMLDirective):
signature = IInitialize
factories = {
'name': special.Name,
'alias': special.Alias,
}
class IBaseParagraphStyle(interfaces.IRMLDirectiveSignature):
fontName = attr.String(
title=u'Font Name',
description=u'The name of the font for the paragraph.',
required=False)
fontSize = attr.Measurement(
title=u'Font Size',
description=u'The font size for the text of the paragraph.',
required=False)
leading = attr.Measurement(
title=u'Leading',
description=(u'The height of a single paragraph line. It includes '
u'character height.'),
required=False)
leftIndent = attr.Measurement(
title=u'Left Indentation',
description=u'General indentation on the left side.',
required=False)
rightIndent = attr.Measurement(
title=u'Right Indentation',
description=u'General indentation on the right side.',
required=False)
firstLineIndent = attr.Measurement(
title=u'First Line Indentation',
description=u'The indentation of the first line in the paragraph.',
required=False)
alignment = attr.Choice(
title=u'Alignment',
description=u'The text alignment.',
choices=interfaces.ALIGN_CHOICES,
required=False)
spaceBefore = attr.Measurement(
title=u'Space Before',
description=u'The vertical space before the paragraph.',
required=False)
spaceAfter = attr.Measurement(
title=u'Space After',
description=u'The vertical space after the paragraph.',
required=False)
bulletFontName = attr.String(
title=u'Bullet Font Name',
description=u'The font in which the bullet character will be rendered.',
required=False)
bulletFontSize = attr.Measurement(
title=u'Bullet Font Size',
description=u'The font size of the bullet character.',
required=False)
bulletIndent = attr.Measurement(
title=u'Bullet Indentation',
description=u'The indentation that is kept for a bullet point.',
required=False)
textColor = attr.Color(
title=u'Text Color',
description=u'The color in which the text will appear.',
required=False)
backColor = attr.Color(
title=u'Background Color',
description=u'The background color of the paragraph.',
required=False)
wordWrap = attr.String(
title=u'Word Wrap Method',
description=(u'When set to "CJK", invoke CJK word wrapping'),
required=False)
borderWidth = attr.Measurement(
title=u'Paragraph Border Width',
description=u'The width of the paragraph border.',
required=False)
borderPadding = attr.Padding(
title=u'Paragraph Border Padding',
description=u'Padding of the paragraph.',
required=False)
borderColor = attr.Color(
title=u'Border Color',
description=u'The color in which the paragraph border will appear.',
required=False)
borderRadius = attr.Measurement(
title=u'Paragraph Border Radius',
description=u'The radius of the paragraph border.',
required=False)
allowWidows = attr.Boolean(
title=u'Allow Widows',
description=(u'Allow widows.'),
required=False)
allowOrphans = attr.Boolean(
title=u'Allow Orphans',
description=(u'Allow orphans.'),
required=False)
textTransforms = attr.Choice(
title=u'Text Transforms',
description=u'Text transformations.',
choices=interfaces.TEXT_TRANSFORM_CHOICES,
required=False)
endDots = attr.String(
title=u'End Dots',
description=u'Characters/Dots at the end of a paragraph.',
required=False)
# Attributes not part of the official style attributes, but are accessed
# by the paragraph renderer.
keepWithNext = attr.Boolean(
title=u'Keep with Next',
description=(u'When set, this paragraph will always be in the same '
u'frame as the following flowable.'),
required=False)
pageBreakBefore = attr.Boolean(
title=u'Page Break Before',
description=(u'Specifies whether a page break should be inserted '
u'before the directive.'),
required=False)
frameBreakBefore = attr.Boolean(
title=u'Frame Break Before',
description=(u'Specifies whether a frame break should be inserted '
u'before the directive.'),
required=False)
class IParagraphStyle(IBaseParagraphStyle):
"""Defines a paragraph style and gives it a name."""
name = attr.String(
title=u'Name',
description=u'The name of the style.',
required=True)
alias = attr.String(
title=u'Alias',
description=u'An alias under which the style will also be known as.',
required=False)
parent = attr.Style(
title=u'Parent',
description=(u'The apragraph style that will be used as a base for '
u'this one.'),
required=False)
class ParagraphStyle(directive.RMLDirective):
signature = IParagraphStyle
def process(self):
kwargs = dict(self.getAttributeValues())
parent = kwargs.pop(
'parent', reportlab.lib.styles.getSampleStyleSheet()['Normal'])
name = kwargs.pop('name')
style = copy.deepcopy(parent)
style.name = name[6:] if name.startswith('style.') else name
for name, value in kwargs.items():
setattr(style, name, value)
manager = attr.getManager(self)
manager.styles[style.name] = style
class ITableStyleCommand(interfaces.IRMLDirectiveSignature):
start = attr.Sequence(
title=u'Start Coordinates',
description=u'The start table coordinates for the style instruction',
value_type=attr.Combination(
value_types=(attr.Integer(),
attr.Choice(choices=interfaces.SPLIT_CHOICES))
),
default=[0, 0],
min_length=2,
max_length=2,
required=True)
stop = attr.Sequence(
title=u'End Coordinates',
description=u'The end table coordinates for the style instruction',
value_type=attr.Combination(
value_types=(attr.Integer(),
attr.Choice(choices=interfaces.SPLIT_CHOICES))
),
default=[-1, -1],
min_length=2,
max_length=2,
required=True)
class TableStyleCommand(directive.RMLDirective):
name = None
def process(self):
args = [self.name]
args += self.getAttributeValues(valuesOnly=True)
self.parent.style.add(*args)
class IBlockFont(ITableStyleCommand):
"""Set the font properties for the texts."""
name = attr.String(
title=u'Font Name',
description=u'The name of the font for the cell.',
required=False)
size = attr.Measurement(
title=u'Font Size',
description=u'The font size for the text of the cell.',
required=False)
leading = attr.Measurement(
title=u'Leading',
description=(u'The height of a single text line. It includes '
u'character height.'),
required=False)
class BlockFont(TableStyleCommand):
signature = IBlockFont
name = 'FONT'
class IBlockLeading(ITableStyleCommand):
"""Set the text leading."""
length = attr.Measurement(
title=u'Length',
description=(u'The height of a single text line. It includes '
u'character height.'),
required=True)
class BlockLeading(TableStyleCommand):
signature = IBlockLeading
name = 'LEADING'
class IBlockTextColor(ITableStyleCommand):
"""Set the text color."""
colorName = attr.Color(
title=u'Color Name',
description=u'The color in which the text will appear.',
required=True)
class BlockTextColor(TableStyleCommand):
signature = IBlockTextColor
name = 'TEXTCOLOR'
class IBlockAlignment(ITableStyleCommand):
"""Set the text alignment."""
value = attr.Choice(
title=u'Text Alignment',
description=u'The text alignment within the cell.',
choices=interfaces.ALIGN_TEXT_CHOICES,
required=True)
class BlockAlignment(TableStyleCommand):
signature = IBlockAlignment
name = 'ALIGNMENT'
class IBlockLeftPadding(ITableStyleCommand):
"""Set the left padding of the cells."""
length = attr.Measurement(
title=u'Length',
description=u'The size of the padding.',
required=True)
class BlockLeftPadding(TableStyleCommand):
signature = IBlockLeftPadding
name = 'LEFTPADDING'
class IBlockRightPadding(ITableStyleCommand):
"""Set the right padding of the cells."""
length = attr.Measurement(
title=u'Length',
description=u'The size of the padding.',
required=True)
class BlockRightPadding(TableStyleCommand):
signature = IBlockRightPadding
name = 'RIGHTPADDING'
class IBlockBottomPadding(ITableStyleCommand):
"""Set the bottom padding of the cells."""
length = attr.Measurement(
title=u'Length',
description=u'The size of the padding.',
required=True)
class BlockBottomPadding(TableStyleCommand):
signature = IBlockBottomPadding
name = 'BOTTOMPADDING'
class IBlockTopPadding(ITableStyleCommand):
"""Set the top padding of the cells."""
length = attr.Measurement(
title=u'Length',
description=u'The size of the padding.',
required=True)
class BlockTopPadding(TableStyleCommand):
signature = IBlockTopPadding
name = 'TOPPADDING'
class IBlockBackground(ITableStyleCommand):
"""Define the background color of the cells.
It also supports alternating colors.
"""
colorName = attr.Color(
title=u'Color Name',
description=u'The color to use as the background for every cell.',
required=False)
colorsByRow = attr.Sequence(
title=u'Colors By Row',
description=u'A list of colors to be used circularly for rows.',
value_type=attr.Color(acceptNone=True),
required=False)
colorsByCol = attr.Sequence(
title=u'Colors By Column',
description=u'A list of colors to be used circularly for columns.',
value_type=attr.Color(acceptNone=True),
required=False)
class BlockBackground(TableStyleCommand):
signature = IBlockBackground
name = 'BACKGROUND'
def process(self):
args = [self.name]
if 'colorsByRow' in self.element.keys():
args = [BlockRowBackground.name]
elif 'colorsByCol' in self.element.keys():
args = [BlockColBackground.name]
args += self.getAttributeValues(valuesOnly=True)
self.parent.style.add(*args)
class IBlockRowBackground(ITableStyleCommand):
"""Define the background colors for rows."""
colorNames = attr.Sequence(
title=u'Colors By Row',
description=u'A list of colors to be used circularly for rows.',
value_type=attr.Color(),
required=True)
class BlockRowBackground(TableStyleCommand):
signature = IBlockRowBackground
name = 'ROWBACKGROUNDS'
class IBlockColBackground(ITableStyleCommand):
"""Define the background colors for columns."""
colorNames = attr.Sequence(
title=u'Colors By Row',
description=u'A list of colors to be used circularly for rows.',
value_type=attr.Color(),
required=True)
class BlockColBackground(TableStyleCommand):
signature = IBlockColBackground
name = 'COLBACKGROUNDS'
class IBlockValign(ITableStyleCommand):
"""Define the vertical alignment of the cells."""
value = attr.Choice(
title=u'Vertical Alignment',
description=u'The vertical alignment of the text with the cells.',
choices=interfaces.VALIGN_TEXT_CHOICES,
required=True)
class BlockValign(TableStyleCommand):
signature = IBlockValign
name = 'VALIGN'
class IBlockSpan(ITableStyleCommand):
"""Define a span over multiple cells (rows and columns)."""
class BlockSpan(TableStyleCommand):
signature = IBlockSpan
name = 'SPAN'
class ILineStyle(ITableStyleCommand):
"""Define the border line style of each cell."""
kind = attr.Choice(
title=u'Kind',
description=u'The kind of line actions to be taken.',
choices=('GRID', 'BOX', 'OUTLINE', 'INNERGRID',
'LINEBELOW', 'LINEABOVE', 'LINEBEFORE', 'LINEAFTER'),
required=True)
thickness = attr.Measurement(
title=u'Thickness',
description=u'Line Thickness',
default=1,
required=True)
colorName = attr.Color(
title=u'Color',
description=u'The color of the border line.',
default=None,
required=True)
cap = attr.Choice(
title=u'Cap',
description=u'The cap at the end of a border line.',
choices=interfaces.CAP_CHOICES,
default=1,
required=True)
dash = attr.Sequence(
title=u'Dash-Pattern',
description=u'The dash-pattern of a line.',
value_type=attr.Measurement(),
default=None,
required=False)
join = attr.Choice(
title=u'Join',
description=u'The way lines are joined together.',
choices=interfaces.JOIN_CHOICES,
default=1,
required=False)
count = attr.Integer(
title=u'Count',
description=(u'Describes whether the line is a single (1) or '
u'double (2) line.'),
default=1,
required=False)
class LineStyle(TableStyleCommand):
signature = ILineStyle
def process(self):
name = self.getAttributeValues(select=('kind',), valuesOnly=True)[0]
args = [name]
args += self.getAttributeValues(ignore=('kind',), valuesOnly=True)
self.parent.style.add(*args)
class IBlockTableStyle(interfaces.IRMLDirectiveSignature):
"""A style defining the look of a table."""
occurence.containing(
occurence.ZeroOrMore('blockFont', IBlockFont),
occurence.ZeroOrMore('blockLeading', IBlockLeading),
occurence.ZeroOrMore('blockTextColor', IBlockTextColor),
occurence.ZeroOrMore('blockAlignment', IBlockAlignment),
occurence.ZeroOrMore('blockLeftPadding', IBlockLeftPadding),
occurence.ZeroOrMore('blockRightPadding', IBlockRightPadding),
occurence.ZeroOrMore('blockBottomPadding', IBlockBottomPadding),
occurence.ZeroOrMore('blockTopPadding', IBlockTopPadding),
occurence.ZeroOrMore('blockBackground', IBlockBackground),
occurence.ZeroOrMore('blockRowBackground', IBlockRowBackground),
occurence.ZeroOrMore('blockColBackground', IBlockColBackground),
occurence.ZeroOrMore('blockValign', IBlockValign),
occurence.ZeroOrMore('blockSpan', IBlockSpan),
occurence.ZeroOrMore('lineStyle', ILineStyle)
)
id = attr.String(
title=u'Id',
description=u'The name/id of the style.',
required=True)
keepWithNext = attr.Boolean(
title=u'Keep with Next',
description=(u'When set, this paragraph will always be in the same '
u'frame as the following flowable.'),
required=False)
class BlockTableStyle(directive.RMLDirective):
signature = IBlockTableStyle
factories = {
'blockFont': BlockFont,
'blockLeading': BlockLeading,
'blockTextColor': BlockTextColor,
'blockAlignment': BlockAlignment,
'blockLeftPadding': BlockLeftPadding,
'blockRightPadding': BlockRightPadding,
'blockBottomPadding': BlockBottomPadding,
'blockTopPadding': BlockTopPadding,
'blockBackground': BlockBackground,
'blockRowBackground': BlockRowBackground,
'blockColBackground': BlockColBackground,
'blockValign': BlockValign,
'blockSpan': BlockSpan,
'lineStyle': LineStyle,
}
def process(self):
kw = dict(self.getAttributeValues())
id = kw.pop('id')
# Create Style
self.style = reportlab.platypus.tables.TableStyle()
for name, value in kw.items():
setattr(self.style, name, value)
# Fill style
self.processSubDirectives()
# Add style to the manager
manager = attr.getManager(self)
manager.styles[id] = self.style
class IMinimalListStyle(interfaces.IRMLDirectiveSignature):
leftIndent = attr.Measurement(
title=u'Left Indentation',
description=u'General indentation on the left side.',
required=False)
rightIndent = attr.Measurement(
title=u'Right Indentation',
description=u'General indentation on the right side.',
required=False)
bulletColor = attr.Color(
title=u'Bullet Color',
description=u'The color in which the bullet will appear.',
required=False)
bulletFontName = attr.String(
title=u'Bullet Font Name',
description=u'The font in which the bullet character will be rendered.',
required=False)
bulletFontSize = attr.Measurement(
title=u'Bullet Font Size',
description=u'The font size of the bullet character.',
required=False)
bulletOffsetY = attr.Measurement(
title=u'Bullet Y-Offset',
description=u'The vertical offset of the bullet.',
required=False)
bulletDedent = attr.StringOrInt(
title=u'Bullet Dedent',
description=u'Either pixels of dedent or auto (default).',
required=False)
bulletDir = attr.Choice(
title=u'Bullet Layout Direction',
description=u'The layout direction of the bullet.',
choices=('ltr', 'rtl'),
required=False)
bulletFormat = attr.String(
title=u'Bullet Format',
description=u'A formatting expression for the bullet text.',
required=False)
class IBaseListStyle(IMinimalListStyle):
start = attr.Combination(
title=u'Start Value',
description=u'The counter start value.',
value_types=(attr.Integer(),
attr.Choice(choices=interfaces.UNORDERED_BULLET_VALUES)),
required=False)
class IListStyle(IBaseListStyle):
"""Defines a list style and gives it a name."""
name = attr.String(
title=u'Name',
description=u'The name of the style.',
required=True)
parent = attr.Style(
title=u'Parent',
description=(u'The list style that will be used as a base for '
u'this one.'),
required=False)
class ListStyle(directive.RMLDirective):
signature = IListStyle
def process(self):
kwargs = dict(self.getAttributeValues())
parent = kwargs.pop(
'parent', reportlab.lib.styles.ListStyle(name='List'))
name = kwargs.pop('name')
style = copy.deepcopy(parent)
style.name = name[6:] if name.startswith('style.') else name
for name, value in kwargs.items():
setattr(style, name, value)
manager = attr.getManager(self)
manager.styles[style.name] = style
class IStylesheet(interfaces.IRMLDirectiveSignature):
"""A styleheet defines the styles that can be used in the document."""
occurence.containing(
occurence.ZeroOrOne('initialize', IInitialize),
occurence.ZeroOrMore('paraStyle', IParagraphStyle),
occurence.ZeroOrMore('blockTableStyle', IBlockTableStyle),
occurence.ZeroOrMore('listStyle', IListStyle),
# TODO:
#occurence.ZeroOrMore('boxStyle', IBoxStyle),
)
class Stylesheet(directive.RMLDirective):
signature = IStylesheet
factories = {
'initialize': Initialize,
'paraStyle': ParagraphStyle,
'blockTableStyle': BlockTableStyle,
'listStyle': ListStyle,
}
|