[Checkins] SVN: z3c.rml/trunk/ - Bug: Overwriting the default paragraph styles did not work properly.

Stephen Richter cvs-admin at zope.org
Wed Dec 19 15:16:13 UTC 2012


Log message for revision 128778:
  - Bug: Overwriting the default paragraph styles did not work properly.
  

Changed:
  U   z3c.rml/trunk/CHANGES.txt
  U   z3c.rml/trunk/src/z3c/rml/attr.py
  U   z3c.rml/trunk/src/z3c/rml/flowable.py
  U   z3c.rml/trunk/src/z3c/rml/stylesheet.py
  A   z3c.rml/trunk/src/z3c/rml/tests/input/rml-examples-043-headings.rml

-=-
Modified: z3c.rml/trunk/CHANGES.txt
===================================================================
--- z3c.rml/trunk/CHANGES.txt	2012-12-19 14:45:52 UTC (rev 128777)
+++ z3c.rml/trunk/CHANGES.txt	2012-12-19 15:16:13 UTC (rev 128778)
@@ -23,6 +23,9 @@
 - Bug: Due to a logic error, bad directives were never properly detected and
   logged about.
 
+- Bug: Overwriting the default paragraph styles did not work properly.
+
+
 1.1.0 (2012-12-18)
 ------------------
 

Modified: z3c.rml/trunk/src/z3c/rml/attr.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/attr.py	2012-12-19 14:45:52 UTC (rev 128777)
+++ z3c.rml/trunk/src/z3c/rml/attr.py	2012-12-19 15:16:13 UTC (rev 128778)
@@ -339,6 +339,19 @@
                 'The color specification "%s" is not valid. %s' % (
                 value, getFileInfo(self)))
 
+def _getStyle(context, value):
+    manager = getManager(context)
+    for styles in (manager.styles,
+                   reportlab.lib.styles.getSampleStyleSheet().byName):
+        if value in styles:
+            return styles[value]
+        elif 'style.' + value in styles:
+            return styles['style.' + value]
+        elif value.startswith('style.') and value[6:] in styles:
+            return styles[value[6:]]
+    raise ValueError('Style %r could not be found. %s' % (
+        value, getFileInfo(self)))
+
 class Style(String):
     """Requires a valid style to be entered.
 
@@ -348,19 +361,8 @@
     default = reportlab.lib.styles.getSampleStyleSheet().byName['Normal']
 
     def fromUnicode(self, value):
-        manager = getManager(self.context)
-        for styles in (manager.styles,
-                       reportlab.lib.styles.getSampleStyleSheet().byName):
-            if value in styles:
-                return styles[value]
-            elif 'style.' + value in styles:
-                return styles['style.' + value]
-            elif value.startswith('style.') and value[6:] in styles:
-                return styles[value[6:]]
-        raise ValueError('Style %r could not be found. %s' % (
-            value, getFileInfo(self)))
+        return _getStyle(self.context, value)
 
-
 class Symbol(Text):
     """This attribute should contain the text representation of a symbol to be
     used."""

Modified: z3c.rml/trunk/src/z3c/rml/flowable.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/flowable.py	2012-12-19 14:45:52 UTC (rev 128777)
+++ z3c.rml/trunk/src/z3c/rml/flowable.py	2012-12-19 15:16:13 UTC (rev 128778)
@@ -141,8 +141,7 @@
         description=(u'The paragraph style that is applied to the paragraph. '
                      u'See the ``paraStyle`` tag for creating a paragraph '
                      u'style.'),
-        default=reportlab.lib.styles.getSampleStyleSheet()['Normal'],
-        required=True)
+        required=False)
 
     bulletText = attr.String(
         title=u'Bullet Character',
@@ -219,6 +218,7 @@
 class Paragraph(Flowable):
     signature = IParagraph
     klass = reportlab.platypus.Paragraph
+    defaultStyle = 'Normal'
 
     styleAttributes = zope.schema.getFieldNames(stylesheet.IBaseParagraphStyle)
 
@@ -232,6 +232,8 @@
 
     def process(self):
         args = dict(self.getAttributeValues(ignore=self.styleAttributes))
+        if 'style' not in args:
+            args['style'] = attr._getStyle(self, self.defaultStyle)
         args['style'] = self.processStyle(args['style'])
         self.parent.flow.append(self.klass(**args))
 
@@ -239,106 +241,56 @@
 class ITitle(IParagraph):
     """The title is a simple paragraph with a special title style."""
 
-    style = attr.Style(
-        title=u'Style',
-        description=(u'The paragraph style that is applied to the paragraph. '
-                     u'See the ``paraStyle`` tag for creating a paragraph '
-                     u'style.'),
-        default=reportlab.lib.styles.getSampleStyleSheet()['Title'],
-        required=True)
-
 class Title(Paragraph):
     signature = ITitle
+    defaultStyle = 'Title'
 
-
 class IHeading1(IParagraph):
     """Heading 1 is a simple paragraph with a special heading 1 style."""
 
-    style = attr.Style(
-        title=u'Style',
-        description=(u'The paragraph style that is applied to the paragraph. '
-                     u'See the ``paraStyle`` tag for creating a paragraph '
-                     u'style.'),
-        default=reportlab.lib.styles.getSampleStyleSheet()['Heading1'],
-        required=True)
-
 class Heading1(Paragraph):
     signature = IHeading1
+    defaultStyle = 'Heading1'
 
 
 class IHeading2(IParagraph):
     """Heading 2 is a simple paragraph with a special heading 2 style."""
 
-    style = attr.Style(
-        title=u'Style',
-        description=(u'The paragraph style that is applied to the paragraph. '
-                     u'See the ``paraStyle`` tag for creating a paragraph '
-                     u'style.'),
-        default=reportlab.lib.styles.getSampleStyleSheet()['Heading2'],
-        required=True)
-
 class Heading2(Paragraph):
     signature = IHeading2
+    defaultStyle = 'Heading2'
 
 
 class IHeading3(IParagraph):
     """Heading 3 is a simple paragraph with a special heading 3 style."""
 
-    style = attr.Style(
-        title=u'Style',
-        description=(u'The paragraph style that is applied to the paragraph. '
-                     u'See the ``paraStyle`` tag for creating a paragraph '
-                     u'style.'),
-        default=reportlab.lib.styles.getSampleStyleSheet()['Heading3'],
-        required=True)
-
 class Heading3(Paragraph):
     signature = IHeading3
+    defaultStyle = 'Heading3'
 
 
 class IHeading4(IParagraph):
     """Heading 4 is a simple paragraph with a special heading 4 style."""
 
-    style = attr.Style(
-        title=u'Style',
-        description=(u'The paragraph style that is applied to the paragraph. '
-                     u'See the ``paraStyle`` tag for creating a paragraph '
-                     u'style.'),
-        default=reportlab.lib.styles.getSampleStyleSheet()['Heading4'],
-        required=True)
-
 class Heading4(Paragraph):
     signature = IHeading4
+    defaultStyle = 'Heading4'
 
 
 class IHeading5(IParagraph):
     """Heading 5 is a simple paragraph with a special heading 5 style."""
 
-    style = attr.Style(
-        title=u'Style',
-        description=(u'The paragraph style that is applied to the paragraph. '
-                     u'See the ``paraStyle`` tag for creating a paragraph '
-                     u'style.'),
-        default=reportlab.lib.styles.getSampleStyleSheet()['Heading5'],
-        required=True)
-
 class Heading5(Paragraph):
     signature = IHeading5
+    defaultStyle = 'Heading5'
 
 
 class IHeading6(IParagraph):
     """Heading 6 is a simple paragraph with a special heading 6 style."""
 
-    style = attr.Style(
-        title=u'Style',
-        description=(u'The paragraph style that is applied to the paragraph. '
-                     u'See the ``paraStyle`` tag for creating a paragraph '
-                     u'style.'),
-        default=reportlab.lib.styles.getSampleStyleSheet()['Heading6'],
-        required=True)
-
 class Heading6(Paragraph):
     signature = IHeading6
+    defaultStyle = 'Heading6'
 
 
 class ITableCell(interfaces.IRMLDirectiveSignature):

Modified: z3c.rml/trunk/src/z3c/rml/stylesheet.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/stylesheet.py	2012-12-19 14:45:52 UTC (rev 128777)
+++ z3c.rml/trunk/src/z3c/rml/stylesheet.py	2012-12-19 15:16:13 UTC (rev 128778)
@@ -146,7 +146,21 @@
         description=u'The radius of the paragraph border.',
         required=False)
 
+    pageBreakBefore = attr.Boolean(
+        title=u'Page Break Before',
+        description=(u'Specifies whether a page break should be inserted '
+                     u'before the directive.'),
+        default=False,
+        required=False)
 
+    frameBreakBefore = attr.Boolean(
+        title=u'Frame Break Before',
+        description=(u'Specifies whether a frame break should be inserted '
+                     u'before the directive.'),
+        default=False,
+        required=False)
+
+
 class IParagraphStyle(IBaseParagraphStyle):
     """Defines a paragraph style and gives it a name."""
 
@@ -171,10 +185,11 @@
 
     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)

Added: z3c.rml/trunk/src/z3c/rml/tests/input/rml-examples-043-headings.rml
===================================================================
--- z3c.rml/trunk/src/z3c/rml/tests/input/rml-examples-043-headings.rml	                        (rev 0)
+++ z3c.rml/trunk/src/z3c/rml/tests/input/rml-examples-043-headings.rml	2012-12-19 15:16:13 UTC (rev 128778)
@@ -0,0 +1,64 @@
+<!DOCTYPE document SYSTEM "rml.dtd">
+<document filename="test_043_headings.pdf">
+
+	<template pageSize="(595, 842)" leftMargin="72" showBoundary="0">
+	<pageTemplate id="main">
+	<pageGraphics>
+		    <setFont name="Helvetica-Bold" size="18"/>
+		    <drawString x="35" y="783">RML Example 44: Headings</drawString>
+			<image file="logo_no_bar.png" preserveAspectRatio="1" x="488" y="749" width="72" height="72"/>
+    		<image file="strapline.png" preserveAspectRatio="1" x="35" y="0" width="525" />
+		</pageGraphics>
+
+
+			<frame id="second" x1="35" y1="45" width="525" height="590"/>
+		</pageTemplate>
+	</template>
+	<stylesheet>
+		<paraStyle name="code"
+				   fontName="Courier"
+				   fontSize="8"
+				   leftIndent="36"
+				   textColor="blue"
+				   />
+		<paraStyle name="style.Heading1"
+				   parent="style.Heading1"
+				   textColor="red"
+				   />
+		<paraStyle name="intro"  fontName="Helvetica" fontSize="12" leading="12" spaceAfter="12"/>
+
+	</stylesheet>
+	<story>
+	<storyPlace x="35" y="660" width="525" height="73" origin="page">
+<para style="intro">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.</para>
+<hr color="white" thickness="8pt"/>
+<para style="intro">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.</para>
+<illustration height="3" width="525" align="center">
+<fill color= "(0,0.99,0.97,0.0)" />
+<rect x="0" y = "-12" width="525" height="3" round="1" fill="1" stroke = "Yes" />
+</illustration>
+</storyPlace>
+		<title>Headings test</title>
+		<para>You can customize heading styles like this:</para>
+		<xpre style="code"><![CDATA[<paraStyle name="style.Heading1"]]></xpre>
+		<xpre style="code"><![CDATA[    parent="style.Heading1"]]></xpre>
+		<xpre style="code"><![CDATA[    textColor="red"]]></xpre>
+		<xpre style="code"><![CDATA[/>]]></xpre>
+
+		<h1>This is heading 1</h1>
+		<h2>This is heading 2</h2>
+		<h3>This is heading 3</h3>
+		<h4>This is heading 4</h4>
+		<h5>This is heading 5</h5>
+		<h6>This is heading 6</h6>
+
+		<h2>This code is generated with folowing RML:</h2>
+
+		<xpre style="code"><![CDATA[<h1>This is heading 1</h1>]]></xpre>
+		<xpre style="code"><![CDATA[<h2>This is heading 2</h2>]]></xpre>
+		<xpre style="code"><![CDATA[<h3>This is heading 3</h3>]]></xpre>
+		<xpre style="code"><![CDATA[<h4>This is heading 4</h4>]]></xpre>
+		<xpre style="code"><![CDATA[<h5>This is heading 5</h5>]]></xpre>
+		<xpre style="code"><![CDATA[<h6>This is heading 6</h6>]]></xpre>
+	</story>
+</document>



More information about the checkins mailing list