diff --git a/CHANGES.txt b/CHANGES.txt index c04fdcd..dfb6828 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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. diff --git a/src/z3c/rml/canvas.py b/src/z3c/rml/canvas.py index 94145b8..1db1dfe 100644 --- a/src/z3c/rml/canvas.py +++ b/src/z3c/rml/canvas.py @@ -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) @@ -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.""" diff --git a/src/z3c/rml/interfaces.py b/src/z3c/rml/interfaces.py index 918290a..ab53f1a 100644 --- a/src/z3c/rml/interfaces.py +++ b/src/z3c/rml/interfaces.py @@ -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""" diff --git a/src/z3c/rml/stylesheet.py b/src/z3c/rml/stylesheet.py index 67f4e91..077f5ef 100644 --- a/src/z3c/rml/stylesheet.py +++ b/src/z3c/rml/stylesheet.py @@ -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.', @@ -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.', @@ -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.', @@ -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 ' diff --git a/src/z3c/rml/tests/expected/rml-examples-047-condPageBreak.pdf b/src/z3c/rml/tests/expected/rml-examples-047-condPageBreak.pdf new file mode 100644 index 0000000..386f5ee Binary files /dev/null and b/src/z3c/rml/tests/expected/rml-examples-047-condPageBreak.pdf differ diff --git a/src/z3c/rml/tests/expected/rml-examples-049-pre.pdf b/src/z3c/rml/tests/expected/rml-examples-049-pre.pdf index 79a94ac..8f55bfb 100644 Binary files a/src/z3c/rml/tests/expected/rml-examples-049-pre.pdf and b/src/z3c/rml/tests/expected/rml-examples-049-pre.pdf differ diff --git a/src/z3c/rml/tests/expected/rml-guide-example-09.pdf b/src/z3c/rml/tests/expected/rml-guide-example-09.pdf index a0fb9c4..8612424 100644 Binary files a/src/z3c/rml/tests/expected/rml-guide-example-09.pdf and b/src/z3c/rml/tests/expected/rml-guide-example-09.pdf differ diff --git a/src/z3c/rml/tests/expected/tag-mergePage.pdf b/src/z3c/rml/tests/expected/tag-mergePage.pdf index daa5a8e..09b54dd 100644 Binary files a/src/z3c/rml/tests/expected/tag-mergePage.pdf and b/src/z3c/rml/tests/expected/tag-mergePage.pdf differ diff --git a/src/z3c/rml/tests/expected/tag-para.pdf b/src/z3c/rml/tests/expected/tag-para.pdf index f56c70e..43032de 100644 Binary files a/src/z3c/rml/tests/expected/tag-para.pdf and b/src/z3c/rml/tests/expected/tag-para.pdf differ diff --git a/src/z3c/rml/tests/expected/tag-pre.pdf b/src/z3c/rml/tests/expected/tag-pre.pdf index d2cb0df..03d8579 100644 Binary files a/src/z3c/rml/tests/expected/tag-pre.pdf and b/src/z3c/rml/tests/expected/tag-pre.pdf differ diff --git a/src/z3c/rml/tests/input/rml-examples-047-condPageBreak.rml b/src/z3c/rml/tests/input/rml-examples-047-condPageBreak.rml new file mode 100644 index 0000000..51fa1c0 --- /dev/null +++ b/src/z3c/rml/tests/input/rml-examples-047-condPageBreak.rml @@ -0,0 +1,319 @@ + + + + + + + + + + + + + + + + + + + + + + + +RML (Report Markup Language) is ReportLab's own language for specifying the appearance of a printed page, which is converted into PDF by the utility rml2pdf. +
+These RML samples showcase techniques and features for generating various types of ouput and are distributed within our commercial package as test cases. Each should be self explanatory and stand alone. + + + + +
+ + + KeepWithNext + + The keepWithNext attribute for the + paraStyle tag tells the paragraph, whether it should + always be kept together with the next paragraph or not. This can be useful for + keeping headings together with the following paragraph. The default value is 0. + The code looks as follows: + + + ]]> + + An example with keepWithNext="0". There is a + spacer underneath. + + This is paragraph 1 with the + keepWithNext="0" attribute. + This is paragraph 2. + + + An example with keepWithNext="1". There is a + spacer underneath + + This is paragraph 1, whose style has the + keepWithNext="1" attribute. + This is paragraph 2. + + + condPageBreak + + The <condPageBreak/> tag will move to + the next page if there is not enough space on the page. The length required to + stay on the same page is give by the attribute height + which takes a length in the allowed measurements. + + Blah blah blah blah blah blah Lieutenant + Commander Data Harry Kim blah + blah blah blah blah blah blah blah blah blah blah blah blah. Blah cloaking device + blah blah Lieutenant Commander Data blah Dr. Pulaski blah blah blah USS Enterprise + blah blah blah emergency transponder. Blah blah Ferrengi blah blah blah blah blah + blah blah blah blah blah blah. Blah blah blah blah blah Tom Paris Archer IV blah blah + Archer IV blah blah Soyuz class science vessel blah Betazoid blah blah blah blah + warship blah blah blah blah blah. Blah blah blah Lieutenant Worf blah blah Lieutenant + Worf Vulcan blah blah blah. Blah blah blah blah blah blah blah Tom Paris blah William + Riker blah blah blah blah blah blah blah Klingon blah Admiral Nakamura blah blah blah + blah blah. Blah blah blah blah blah blah blah Romulan ale blah blah blah asteroid + field blah blah blah blah blah blah blah blah. Blah blah blah blah blah Memory Alpha + blah blah blah blah blah blah blah. Blah blah blah Captain Picard blah blah Romulan + blah blah blah blah blah Admiral Nakamura blah blah. Blah blah blah blah blah blah + blah Starfleet Academy blah blah USS Intrepid blah blah blah blah blah blah blah blah + holodeck blah blah blah blah. Blah blah blah blah blah ...with a phaser! blah blah + blah blah blah Romulan Vulcan blah blah blah. Blah blah quantum flux blah blah blah + blah quantum flux Chief O'Brian blah blah blah blah blah blah blah blah blah. Blah + Counsellor Troi blah blah blah blah blah blah USS Intrepid blah blah blah blah blah + Captain Janeway blah asteroid field blah IKV Pagh blah blah. Blah blah blah blah blah + blah Betazoid blah blah blah blah blah IKV Pagh blah blah Captain Janeway blah blah + IKV Pagh. Blah photon torpedo blah blah blah blah blah blah photon torpedo blah blah + blah blah blah blah blah blah blah Ferrengi blah blah blah blah blah. Blah blah blah + blah United Federation of Planets blah blah blah blah blah blah blah Deep Space Nine + blah blah blah blah blah blah blah blah blah. Blah blah "Intruder alert!" Romulan + blah blah blah blah blah blah blah blah blah. Blah blah blah shuttlecraft Ferrengi + Vulcan blah blah blah blah blah blah Galaxy class vessel blah blah blah blah blah + blah blah. Blah turbolift blah blah scout ship cruiser blah quantum flux blah blah + blah blah blah blah blah blah blah blah blah blah blah William Riker blah blah blah. + Blah blah blah blah blah battlecruiser blah blah blah blah blah blah blah blah Dr. + Pulaski Pacifica blah blah blah blah blah blah turbolift. Blah blah blah Benzite blah + Bajoran blah blah "Borg Invasion imminent!" blah blah blah blah blah blah blah blah + blood wine. Blah emergency transponder blah Starfleet blah blah blah blah blah blah + blah blah blah blah blah blah blah blah blah shuttle bay 2 blah blah blah. Blah blah + blah blah blah blah blah blah distress signal blah spacedock blah Irumodic Syndrome + blah Romulan ale blah blah blah blah blah "All hands abandon ship! This is not a + drill!" blah blah blah blah blah. + The conditional page break comes in here and + is set for 3 inches. + + This is on the next page since there was less than three inches + till the end of the page. + + Blah blah blah blah blah blah Lieutenant + Commander Data Harry Kim blah + blah blah blah blah blah blah blah blah blah blah blah blah. Blah cloaking device + blah blah Lieutenant Commander Data blah Dr. Pulaski blah blah blah USS Enterprise + blah blah blah emergency transponder. Blah blah Ferrengi blah blah blah blah blah + blah blah blah blah blah blah. Blah blah blah blah blah Tom Paris Archer IV blah blah + Archer IV blah blah Soyuz class science vessel blah Betazoid blah blah blah blah + warship blah blah blah blah blah. Blah blah blah Lieutenant Worf blah blah Lieutenant + Worf Vulcan blah blah blah. Blah blah blah blah blah blah blah Tom Paris blah William + Riker blah blah blah blah blah blah blah Klingon blah Admiral Nakamura blah blah blah + blah blah. Blah blah blah blah blah blah blah Romulan ale blah blah blah asteroid + field blah blah blah blah blah blah blah blah. Blah blah blah blah blah Memory Alpha + blah blah blah blah blah blah blah. Blah blah blah Captain Picard blah blah Romulan + blah blah blah blah blah Admiral Nakamura blah blah. Blah blah blah blah blah blah + blah Starfleet Academy blah blah USS Intrepid blah blah blah blah blah blah blah blah + holodeck blah blah blah blah. Blah blah blah blah blah ...with a phaser! blah blah + blah blah blah Romulan Vulcan blah blah blah. Blah blah quantum flux blah blah blah + blah quantum flux Chief O'Brian blah blah blah blah blah blah blah blah blah. Blah + Counsellor Troi blah blah blah blah blah blah USS Intrepid blah blah blah blah blah + Captain Janeway blah asteroid field blah IKV Pagh blah blah. Blah blah blah blah blah + blah Betazoid blah blah blah blah blah IKV Pagh blah blah Captain Janeway blah blah + IKV Pagh. Blah photon torpedo blah blah blah blah blah blah photon torpedo blah blah + blah blah blah blah blah blah blah Ferrengi blah blah blah blah blah. Blah blah blah + blah United Federation of Planets blah blah blah blah blah blah blah Deep Space Nine + blah blah blah blah blah blah blah blah blah. Blah blah "Intruder alert!" Romulan + blah blah blah blah blah blah blah blah blah. Blah blah blah shuttlecraft Ferrengi + Vulcan blah blah blah blah blah blah Galaxy class vessel blah blah blah blah blah + blah blah. Blah turbolift blah blah scout ship cruiser blah quantum flux blah blah + blah blah blah blah blah blah blah blah blah blah blah William Riker blah blah blah. + Blah blah blah blah blah battlecruiser blah blah blah blah blah blah blah blah Dr. + Pulaski Pacifica blah blah blah blah blah blah turbolift. Blah blah blah Benzite blah + Bajoran blah blah "Borg Invasion imminent!" blah blah blah blah blah blah blah blah + blood wine. Blah emergency transponder blah Starfleet blah blah blah blah blah blah + blah blah blah blah blah blah blah blah blah shuttle bay 2 blah blah blah. Blah blah + blah blah blah blah blah blah distress signal blah spacedock blah Irumodic Syndrome + blah Romulan ale blah blah blah blah blah "All hands abandon ship! This is not a + drill!" blah blah blah blah blah. + The conditional page break comes in here + and is set for 3 inches. + + + This is at the bottom of the page since there are more than 3in + remaining. + + + frameBreakBefore and pageBreakBefore + + The frameBreakBefore and pageBeforeBreak are both attributes of the <paraStyle> tag. + The frameBreakBefore attribute causes + the new paragraph to go into the next frame, even if there is still space in the + current frame. The default value is 0. + The pageBreakBefore attribute causes the + new paragraph to go into the next page, even if there is still space in the current + frame, or if there are other frames remaining on the page. The default value is 0. + + + This is an example of frameBreakBefore. + The next paragraph will be in a new frame. + + This paragraph is in a new frame, since its style has the attribute + frameBreakBefore="1" + + This is an example of pageBreakBefore. + The next paragraph will be on a new page. + + + This paragraph is on a new page. It missed out the frame in + the lower right corner of the last page, since its style has pageBreakBefore="1" + + + allowWidows + + The allowWidows attribute, for the <paraStyle> tag, allows the + paragraph to have a widow, a line of text, separated from the rest of the paragraph, + at the end. The default value for allowWidows is 1. + + This is an example of allowWidows="1" + Blah blah blah blah SQL blah blah blah blah pizza + blah blah blah blah TeX blah blah blah blah blah. Blah Intercal blah blah blah blah + blah blah TeX OS/2 TFT display blah Linux blah blah blah blah crash! blah blah Sun + Microsystems blah Logo blah blah. Blah blah blah blah blah blah blah blah blah blah + VB Tcl/Tk Fortran blah blah blah awk blah blah blah. Blah blah blah blah blah blah + blah blah blah blah blah blah PGP TCP/IP blah blah blah. Blah cgi Modula-3 SQL blah + blah blah Delphi blah LISP blah BETA mailing lists blah. Blah blah blah blah + pepperoni pizza blah blah blah blah blah blah blah blah blah blah blah blah blah blah + monitor blah. Blah blah blah blah blah blah blah blah blah parallel languages blah + blah blah blah blah blah blah blah BEER! blah blah. Blah blah beer blah blah OpenGL + monitor blah blah blah blah. Blah blah blah blah blah blah blah blah blah blah blah + blah "illiterate programming" blah blah C: drive. Blah blah blah. + This example has a widow (the line above). + + + This is an example of allowWidows="0" + Blah blah blah blah SQL blah blah blah blah + pizza + blah blah blah blah TeX blah blah blah blah blah. Blah Intercal blah blah blah blah + blah blah TeX OS/2 TFT display blah Linux blah blah blah blah crash! blah blah Sun + Microsystems blah Logo blah blah. Blah blah blah blah blah blah blah blah blah blah + VB Tcl/Tk Fortran blah blah blah awk blah blah blah. Blah blah blah blah blah blah + blah blah blah blah blah blah PGP TCP/IP blah blah blah. Blah cgi Modula-3 SQL blah + blah blah Delphi blah LISP blah BETA mailing lists blah. Blah blah blah blah + pepperoni pizza blah blah blah blah blah blah blah blah blah blah blah blah blah blah + monitor blah. Blah blah blah blah blah blah blah blah blah parallel languages blah + blah blah blah blah blah blah blah BEER! blah blah. Blah blah beer blah blah OpenGL + monitor blah blah blah blah. Blah blah blah blah blah blah blah blah blah blah blah + blah "illiterate programming" blah blah C: drive. Blah blah blah. + This example does not have a widow, since + another line has been brought with it. + + allowOrphans + + The allowOrphans attribute allows the + paragraph to have an orphan, a line of text, left in the original frame, separated + from the rest of the paragraph. The default value is for this attribute is 0. + + This is an example of allowOrphans="0" + + There is no orphan below. + Blah blah blah blah SQL blah blah blah blah pizza blah blah blah + blah TeX blah blah blah blah blah. Blah Intercal blah blah blah blah blah blah TeX + OS/2 TFT display blah Linux blah blah blah blah crash! blah blah Sun Microsystems + Logo blah blah. Blah blah blah blah blah blah blah blah blah blah VB Tcl/Tk Fortran + blah blah blah awk blah blah blah. Blah blah blah blah blah blah blah blah blah blah + blah blah PGP TCP/IP blah blah blah. Blah cgi Modula-3 SQL blah blah blah Delphi blah + LISP blah BETA mailing lists blah. Blah blah blah blah pepperoni pizza blah blah blah + blah blah blah blah blah blah blah blah blah blah blah monitor blah. Blah blah blah + blah blah blah blah blah blah parallel languages blah blah blah blah blah blah blah + blah BEER! blah blah. Blah blah beer blah blah OpenGL monitor blah blah blah blah. + Blah blah Phys blah blah blah blah blah blah blah blah blah "illiterate programming" + blah blah C: drive. + + This is an example of allowOrphans="1" + + There is an orphan below. + Blah blah blah blah SQL blah blah blah blah pizza blah blah blah blah + TeX blah blah blah blah blah. Blah Intercal blah blah blah blah blah blah TeX OS/2 + TFT display blah Linux blah blah blah blah crash! blah blah Sun Microsystems blah + Logo blah blah. Blah blah blah blah blah blah blah blah blah blah VB Tcl/Tk Fortran + blah blah blah awk blah blah blah. Blah blah blah blah blah blah blah blah blah blah + blah blah PGP TCP/IP blah blah blah. Blah cgi Modula-3 SQL blah blah blah Delphi blah + LISP blah BETA mailing lists blah. Blah blah blah blah pepperoni pizza blah blah blah + blah blah blah blah blah blah blah blah blah blah blah monitor blah. Blah blah blah + blah blah blah blah blah blah parallel languages blah blah blah blah blah blah blah + blah BEER! blah blah. Blah blah beer blah blah OpenGL monitor blah blah blah blah. + Blah blah Phys blah blah blah blah blah blah blah blah blah "illiterate programming" + blah blah C: drive. + + + endDots + + The endDots attribute fills in the rest of the last line of the + paragraph with the characters given for the attribute. + + This paragraph should have dots following it until the end of the line. + + This paragraph should have the characters "123" following it until the end of the + line. +
+