Skip to content

Commit

Permalink
Implemented pageNumber for draw*String.
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Dec 19, 2012
1 parent 0f2b124 commit 8999c7e
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 21 deletions.
6 changes: 4 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ CHANGES

- Implemented ``codesnippet`` directive.

- Implemented ``pageBreakBefore`` and ``frameBreakBefore`` attributes for
paragraph styles.
- Implemented ``pageBreakBefore``, ``frameBreakBefore``, ``textTransform``,
and ``endDots`` attributes for paragraph styles.

- Added ``maxLineLength`` and ``newLineChars`` attributes to the ``pre``
directive.

- Implemented ``pageNumber`` element for all ``draw*String`` elements.

- Don't show "doc" namespace in reference snippets.

- Create a list of RML2PDF and z3c.rml differences.
Expand Down
23 changes: 22 additions & 1 deletion src/z3c/rml/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class IDrawString(interfaces.IRMLDirectiveSignature):
u'string.'),
required=True)

text = attr.TextNode(
text = attr.RawXMLContent(
title=u'Text',
description=(u'The string/text that is put onto the canvas.'),
required=True)
Expand All @@ -100,6 +100,27 @@ class DrawString(CanvasRMLDirective):
signature = IDrawString
callable = 'drawString'

def getPageNumber(self, elem, canvas):
return str(canvas.getPageNumber() + int(elem.get('countingFrom', 1)) - 1)

handleElements = {'pageNumber': getPageNumber}

def _getText(self, node, canvas):
text = node.text or u''
for sub in node.iterdescendants():
if sub.tag in self.handleElements:
text += self.handleElements[sub.tag](self, sub, canvas)
else:
self._getText(sub, canvas)
text += node.tail or u''
return text

def process(self):
canvas = attr.getManager(self, interfaces.ICanvasManager).canvas
kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping))
kwargs['text'] = self._getText(self.element, canvas).strip()
getattr(canvas, self.callable)(**kwargs)

class IDrawRightString(IDrawString):
"""Draws a simple string (right aligned) onto the canvas at the specified
location."""
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/rml/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
VALIGN_TEXT_CHOICES = {
'top': 'TOP', 'middle': 'MIDDLE', 'bottom': 'BOTTOM'}
SPLIT_CHOICES = ('splitfirst', 'splitlast')

TEXT_TRANSFORM_CHOICES = ('uppercase', 'lowercase')

class IRML2PDF(zope.interface.Interface):
"""This is the main public API of z3c.rml"""
Expand Down
58 changes: 41 additions & 17 deletions src/z3c/rml/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class IBaseParagraphStyle(interfaces.IRMLDirectiveSignature):
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.',
Expand All @@ -81,12 +87,6 @@ class IBaseParagraphStyle(interfaces.IRMLDirectiveSignature):
description=u'The vertical space after the paragraph.',
required=False)

alignment = attr.Choice(
title=u'Alignment',
description=u'The text alignment.',
choices=interfaces.ALIGN_CHOICES,
required=False)

bulletFontName = attr.String(
title=u'Bullet Font Name',
description=u'The font in which the bullet character will be rendered.',
Expand All @@ -112,22 +112,11 @@ class IBaseParagraphStyle(interfaces.IRMLDirectiveSignature):
description=u'The background color of the paragraph.',
required=False)

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)

wordWrap = attr.String(
title=u'Word Wrap Method',
description=(u'When set to "CJK", invoke CJK word wrapping'),
required=False)

borderColor = attr.Color(
title=u'Border Color',
description=u'The color in which the paragraph border will appear.',
required=False)

borderWidth = attr.Measurement(
title=u'Paragraph Border Width',
description=u'The width of the paragraph border.',
Expand All @@ -138,11 +127,46 @@ class IBaseParagraphStyle(interfaces.IRMLDirectiveSignature):
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 '
Expand Down
Binary file not shown.
Binary file modified src/z3c/rml/tests/expected/rml-examples-049-pre.pdf
Binary file not shown.
Binary file modified src/z3c/rml/tests/expected/rml-guide-example-09.pdf
Binary file not shown.
Binary file modified src/z3c/rml/tests/expected/tag-mergePage.pdf
Binary file not shown.
Binary file modified src/z3c/rml/tests/expected/tag-para.pdf
Binary file not shown.
Binary file modified src/z3c/rml/tests/expected/tag-pre.pdf
Binary file not shown.

0 comments on commit 8999c7e

Please sign in to comment.