[Checkins] SVN: z3c.rml/trunk/src/z3c/rml/ * Implemented barCodeFlowable tag.

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Mar 15 22:39:07 EDT 2007


Log message for revision 73210:
  * Implemented barCodeFlowable tag.
  
  * Took the chance to create a test for all barcode types.
  
  

Changed:
  U   z3c.rml/trunk/src/z3c/rml/flowable.py
  U   z3c.rml/trunk/src/z3c/rml/form.py
  U   z3c.rml/trunk/src/z3c/rml/platypus.py
  U   z3c.rml/trunk/src/z3c/rml/tests/input/rml-examples-006-barcodes.rml
  A   z3c.rml/trunk/src/z3c/rml/tests/input/tag-barCodeFlowable.rml

-=-
Modified: z3c.rml/trunk/src/z3c/rml/flowable.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/flowable.py	2007-03-15 21:49:02 UTC (rev 73209)
+++ z3c.rml/trunk/src/z3c/rml/flowable.py	2007-03-16 02:39:06 UTC (rev 73210)
@@ -17,13 +17,20 @@
 """
 __docformat__ = "reStructuredText"
 import copy
+import reportlab.platypus
 import reportlab.platypus.doctemplate
 import reportlab.platypus.flowables
 import reportlab.platypus.tables
-from reportlab import platypus
 from reportlab.lib import styles
-from z3c.rml import attr, element, special
+from z3c.rml import attr, element, form, platypus, special
 
+try:
+    import reportlab.graphics.barcode
+except ImportError:
+    # barcode package has not been installed
+    import reportlab.graphics
+    reportlab.graphics.barcode = types.ModuleType('barcode')
+    reportlab.graphics.barcode.getCodeNames = lambda : ()
 
 class Flowable(element.FunctionElement):
     klass=None
@@ -35,42 +42,29 @@
 
 
 class Spacer(Flowable):
-    klass = platypus.Spacer
+    klass = reportlab.platypus.Spacer
     args = ( attr.Measurement('width', 100), attr.Measurement('length'), )
 
 
-class PlatypusIllustration(platypus.flowables.Flowable):
-    def __init__(self, processor, width, height):
-        self.processor = processor
-        self.width = width
-        self.height = height
-
-    def wrap(self, *args):
-        return (self.width, self.height)
-
-    def draw(self):
-        # Import here to avoid recursive imports
-        from z3c.rml import canvas
-        self.canv.saveState()
-        drawing = canvas.Drawing(
-            self.processor.element, self.processor, self.canv)
-        drawing.process()
-        self.canv.restoreState()
-
 class Illustration(Flowable):
-    klass = PlatypusIllustration
+    klass = platypus.Illustration
     args = ( attr.Measurement('width'), attr.Measurement('height', 100))
 
     def process(self):
         args = self.getPositionalArguments()
         self.parent.flow.append(self.klass(self, *args))
 
+class BarCodeFlowable(Flowable):
+    klass = staticmethod(reportlab.graphics.barcode.createBarcodeDrawing)
+    args = form.BarCode.args[:-1]
+    kw = form.BarCode.kw[2:] + ( ('value', attr.Attribute('value')), )
+
 class Preformatted(Flowable):
-    klass = platypus.Preformatted
+    klass = reportlab.platypus.Preformatted
     args = ( attr.RawXMLContent(u''), attr.Style('style', 'para', 'Normal') )
 
 class XPreformatted(Flowable):
-    klass = platypus.XPreformatted
+    klass = reportlab.platypus.XPreformatted
     args = ( attr.RawXMLContent(u''), attr.Style('style', 'para', 'Normal') )
 
 class PluginFlowable(Flowable):
@@ -83,7 +77,7 @@
         self.parent.flow.append(function(text))
 
 class Paragraph(Flowable):
-    klass = platypus.Paragraph
+    klass = reportlab.platypus.Paragraph
     args = ( attr.XMLContent(u''), attr.Style('style', 'para', 'Normal') )
     kw = ( ('bulletText', attr.Attribute('bulletText')), )
 
@@ -175,7 +169,7 @@
         self.parent.rows.append(self.cols)
 
 class BlockTable(element.ContainerElement, Flowable):
-    klass = platypus.Table
+    klass = reportlab.platypus.Table
     kw = (
         ('rowHeights', attr.Sequence('rowHeights', attr.Measurement())),
         ('colWidths', attr.Sequence('colWidths', attr.Measurement())),
@@ -193,31 +187,30 @@
         self.processSubElements(None)
         # Create the table
         kw = self.getKeywordArguments()
-        table = self.klass(self.rows, **kw)
-        table.setStyle(self.style)
+        table = self.klass(self.rows, style=self.style, **kw)
 
         self.parent.flow.append(table)
 
 
 class NextFrame(Flowable):
-    klass = platypus.doctemplate.FrameBreak
+    klass = reportlab.platypus.doctemplate.FrameBreak
     kw = (
         ('ix', attr.StringOrInt('name')), )
 
 class SetNextFrame(Flowable):
-    klass = platypus.doctemplate.NextFrameFlowable
+    klass = reportlab.platypus.doctemplate.NextFrameFlowable
     kw = (
         ('ix', attr.StringOrInt('name')), )
 
 class NextPage(Flowable):
-    klass = platypus.PageBreak
+    klass = reportlab.platypus.PageBreak
 
 class SetNextTemplate(Flowable):
-    klass = platypus.doctemplate.NextPageTemplate
+    klass = reportlab.platypus.doctemplate.NextPageTemplate
     args = ( attr.StringOrInt('name'), )
 
 class ConditionalPageBreak(Flowable):
-    klass = platypus.CondPageBreak
+    klass = reportlab.platypus.CondPageBreak
     args = ( attr.Measurement('height'), )
 
 
@@ -339,6 +332,7 @@
         'pre': Preformatted,
         'xpre': XPreformatted,
         'pluginFlowable': PluginFlowable,
+        'barCodeFlowable': BarCodeFlowable,
         # Paragraph-Like Flowables
         'title': Title,
         'h1': Heading1,

Modified: z3c.rml/trunk/src/z3c/rml/form.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/form.py	2007-03-15 21:49:02 UTC (rev 73209)
+++ z3c.rml/trunk/src/z3c/rml/form.py	2007-03-16 02:39:06 UTC (rev 73210)
@@ -36,6 +36,8 @@
     kw = (
         ('x', attr.Measurement('x')),
         ('y', attr.Measurement('y')),
+        ('width', attr.Measurement('width')),
+        ('height', attr.Measurement('height')),
         ('strokeColor', attr.Color('strokeColor')),
         ('strokeWidth', attr.Measurement('strokeWidth')),
         ('fillColor', attr.Color('fillColor')),
@@ -43,11 +45,44 @@
         ('barStrokeWidth', attr.Measurement('barStrokeWidth')),
         ('barFillColor', attr.Color('barFillColor')),
         ('gap', attr.Measurement('gap')),
+        # Bar code dependent attributes
+        # I2of5, Code128, Standard93, FIM, POSTNET, Ean13B
+        ('barWidth', attr.Measurement('barWidth')),
+        # I2of5, Code128, Standard93, FIM, POSTNET
+        ('barHeight', attr.Measurement('barHeight')),
+        # I2of5
+        ('ratio', attr.Float('ratio')),
+        # I2of5
+        # Should be boolean, but some code want it as int; will still work
+        ('checksum', attr.Int('checksum')),
+        # I2of5
+        ('bearers', attr.Float('bearers')),
+        # I2of5, Code128, Standard93, FIM, Ean13
+        ('quiet', attr.Bool('quiet')),
+        # I2of5, Code128, Standard93, FIM, Ean13
+        ('lquiet', attr.Measurement('lquiet')),
+        # I2of5, Code128, Standard93, FIM, Ean13
+        ('rquiet', attr.Measurement('rquiet')),
+        # I2of5, Code128, Standard93, FIM, POSTNET, Ean13
+        ('fontName', attr.Text('fontName')),
+        # I2of5, Code128, Standard93, FIM, POSTNET, Ean13
+        ('fontSize', attr.Measurement('fontSize')),
+        # I2of5, Code128, Standard93, FIM, POSTNET, Ean13
+        ('humanReadable', attr.Bool('humanReadable')),
+        # I2of5, Standard93
+        ('stop', attr.Bool('atop')),
+        # FIM, POSTNET
+        ('spaceWidth', attr.Measurement('spaceWidth')),
+        # POSTNET
+        ('shortHeight', attr.Measurement('shortHeight')),
+        # Ean13
+        ('textColor', attr.Color('textColor')),
         )
 
     def process(self):
         kw = self.getKeywordArguments()
-        name, kw['value'] = self.getPositionalArguments()
+        name, value = self.getPositionalArguments()
+        kw['value'] = str(value)
         x = kw.pop('x', 0)
         y = kw.pop('y', 0)
         code = reportlab.graphics.barcode.createBarcodeDrawing(name, **kw)

Modified: z3c.rml/trunk/src/z3c/rml/platypus.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/platypus.py	2007-03-15 21:49:02 UTC (rev 73209)
+++ z3c.rml/trunk/src/z3c/rml/platypus.py	2007-03-16 02:39:06 UTC (rev 73210)
@@ -16,3 +16,23 @@
 $Id$
 """
 __docformat__ = "reStructuredText"
+import reportlab.platypus.flowables
+
+class Illustration(reportlab.platypus.flowables.Flowable):
+    def __init__(self, processor, width, height):
+        self.processor = processor
+        self.width = width
+        self.height = height
+
+    def wrap(self, *args):
+        return (self.width, self.height)
+
+    def draw(self):
+        # Import here to avoid recursive imports
+        from z3c.rml import canvas
+        self.canv.saveState()
+        drawing = canvas.Drawing(
+            self.processor.element, self.processor, self.canv)
+        drawing.process()
+        self.canv.restoreState()
+

Modified: z3c.rml/trunk/src/z3c/rml/tests/input/rml-examples-006-barcodes.rml
===================================================================
--- z3c.rml/trunk/src/z3c/rml/tests/input/rml-examples-006-barcodes.rml	2007-03-15 21:49:02 UTC (rev 73209)
+++ z3c.rml/trunk/src/z3c/rml/tests/input/rml-examples-006-barcodes.rml	2007-03-16 02:39:06 UTC (rev 73210)
@@ -33,7 +33,7 @@
 		<barCode x="1cm" y="0" code="Code11">01234545634563</barCode>
 	</illustration>
 	
-<!--	<spacer length="1cm"/>
+	<spacer length="1cm"/>
 	<para style="normal">Code128</para>
 	<illustration width="10cm" height="1cm">
 		<barCode x="1cm" y="0" code="Code128">AB-12345678</barCode>
@@ -44,7 +44,7 @@
 	<illustration width="10cm" height="1cm">
 		<barCode x="1cm" y="0" code="Code128" barHeight="0.5in" barWidth="0.009in">AB-12345678</barCode>
 	</illustration>
--->	<blockTable style="temp001">
+	<blockTable style="temp001">
 		<tr><td>barChartFlowable</td>
 			<td><barCodeFlowable code="Standard39" value="PFWZF" barWidth="0.01in" quiet="no"/></td>
 		</tr>

Added: z3c.rml/trunk/src/z3c/rml/tests/input/tag-barCodeFlowable.rml
===================================================================
--- z3c.rml/trunk/src/z3c/rml/tests/input/tag-barCodeFlowable.rml	2007-03-15 21:49:02 UTC (rev 73209)
+++ z3c.rml/trunk/src/z3c/rml/tests/input/tag-barCodeFlowable.rml	2007-03-16 02:39:06 UTC (rev 73210)
@@ -0,0 +1,177 @@
+<!DOCTYPE document SYSTEM "rml.dtd">
+<document filename="tag-spacer.pdf">
+  <template>
+    <pageTemplate id="main">
+      <frame id="header" x1="2cm" y1="26cm" width="17cm" height="2cm"/>
+      <frame id="first" x1="2cm" y1="2cm" width="8cm" height="24cm"/>
+      <frame id="second" x1="11cm" y1="2cm" width="8cm" height="24cm"/>
+    </pageTemplate>
+  </template>
+
+  <stylesheet>
+    <paraStyle
+        name="style.Normal"
+        fontName="Helvetica-Bold"
+        fontSize="12"
+        />
+  </stylesheet>
+
+  <story>
+    <title>"barCodeFlowable" Tag Demo</title>
+    <nextFrame />
+    <para>Code 128</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Code128" value="PFWZF" />
+    <spacer length="10mm" />
+
+    <para>Code 128 with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Code128" value="PFWZF" humanReadable="true"
+                     fontName="Helvetica" fontSize="10"
+                     barFillColor="red" barStrokeColor="red"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+    <para>Standard 93</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Standard93" value="98882137" />
+    <spacer length="10mm" />
+
+    <para>Standard 93 with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Standard93" value="98882137" humanReadable="true"
+                     fontName="Helvetica" fontSize="10" stop="true"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+    <para>Extended 93</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Extended93" value="988-CD=137" />
+    <spacer length="10mm" />
+
+    <para>Extended 93 with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Extended93" value="988-CD=137" humanReadable="true"
+                     fontName="Helvetica" fontSize="10" stop="true"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+    <para>Standard 39</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Standard39" value="98882137" />
+    <spacer length="10mm" />
+
+    <para>Standard 39 with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Standard39" value="98882137" humanReadable="true"
+                     fontName="Helvetica" fontSize="10" stop="true"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+
+    <nextFrame />
+
+    <para>Extended 39</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Extended39" value="988-CD-137" />
+    <spacer length="10mm" />
+
+    <para>Extended 39 with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Extended39" value="988-CD-137" humanReadable="true"
+                     fontName="Helvetica" fontSize="10" stop="true"
+                     checksum="1" bearers="2"  ratio="3"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+    <para>MSI</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="MSI" value="988137" />
+    <spacer length="10mm" />
+
+    <para>MSI with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="MSI" value="988137" humanReadable="true"
+                     fontName="Helvetica" fontSize="10" stop="true"
+                     checksum="1" bearers="2"  ratio="3"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+    <para>Codabar</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Codabar" value="988137" />
+    <spacer length="10mm" />
+
+    <para>Codabar with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Codabar" value="988137" humanReadable="true"
+                     fontName="Helvetica" fontSize="10" stop="true"
+                     checksum="1" bearers="2"  ratio="3"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+    <para>Code 11</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Code11" value="988137" />
+    <spacer length="10mm" />
+
+    <para>Code 11 with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Code11" value="988137" humanReadable="true"
+                     fontName="Helvetica" fontSize="10" stop="true"
+                     checksum="1" bearers="2"  ratio="3"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+
+    <nextFrame />
+
+    <para>FIM</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="FIM" value="B" />
+    <spacer length="10mm" />
+
+    <para>FIM with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="FIM" value="B" humanReadable="true"
+                     fontName="Helvetica" fontSize="10" stop="true"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+    <para>Ean13</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Ean13" value="123456789012" />
+    <spacer length="10mm" />
+
+    <para>Ean13 with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Ean13" value="123456789012"
+                     humanReadable="true" fontName="Helvetica" fontSize="7"
+                     barStrokeColor="blue" barFillColor="blue" textColor="blue"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+    <para>Ean8</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Ean8" value="1234567" />
+    <spacer length="10mm" />
+
+    <para>Ean8 with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="Ean8" value="1234567"
+                     humanReadable="true" fontName="Helvetica" fontSize="7"
+                     barStrokeColor="blue" barFillColor="blue" textColor="blue"
+                     quiet="false" barHeight="0.4in" barWidth="0.009in" />
+
+    <nextFrame />
+
+    <para>POSTNET</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="POSTNET" value="38104-0001" />
+    <spacer length="10mm" />
+
+    <para>POSTNET with several options</para>
+    <spacer length="5mm" />
+    <barCodeFlowable code="POSTNET" value="38104-0001" humanReadable="true"
+                     fontName="Helvetica" fontSize="10"
+                     barHeight="0.4in" barWidth="0.009in" />
+    <spacer length="10mm" />
+
+  </story>
+</document>



More information about the Checkins mailing list