Skip to content

Commit

Permalink
Got 2 more RML testsuite files working.
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Mar 16, 2007
1 parent c1880a8 commit 644d5da
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/z3c/rml/flowable.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ def process(self):
modulePath, functionName, text = self.getPositionalArguments()
module = __import__(modulePath, {}, {}, [modulePath])
function = getattr(module, functionName)
self.parent.flow.append(function(text))
flowables = function(text)
if not isinstance(flowables, (tuple, list)):
flowables = [flowables]
self.parent.flow += list(flowables)

class Paragraph(Flowable):
klass = reportlab.platypus.Paragraph
Expand Down Expand Up @@ -387,7 +390,7 @@ class Flow(element.ContainerElement):
'illustration': Illustration,
'pre': Preformatted,
'xpre': XPreformatted,
'pluginFlowable': PluginFlowable,
'plugInFlowable': PluginFlowable,
'barCodeFlowable': BarCodeFlowable,
# Paragraph-Like Flowables
'title': Title,
Expand Down
117 changes: 117 additions & 0 deletions src/z3c/rml/tests/input/rml-examples-009-splitting.rml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
<!DOCTYPE document SYSTEM "rml_1_0.dtd">
<document filename="test_009_splitting.pdf">


<template pageSize="(595, 842)" leftMargin="72" showBoundary="1">
<pageTemplate id="main">
<pageGraphics>
<setFont name="Helvetica-BoldOblique" size="18"/>
<drawRightString x="523" y="800">RML2PDF Test Suite - Test #9</drawRightString>
</pageGraphics>
<frame id="first" x1="1in" y1="5.845in" width="6.27in" height="4in"/>
<frame id="second" x1="1in" y1="1in" width="6.27in" height="4in"/>
</pageTemplate>
</template>

<stylesheet>
<initialize></initialize>

<paraStyle name="h1"
fontName="Courier-Bold"
fontSize="12"
spaceBefore = "0.5 cm"
/>

<paraStyle name="style1"
fontName="Courier"
fontSize="10"
/>


<paraStyle name="heading"
fontName="Helvetica-Bold"
fontSize="24"
leading="28"
spaceBefore = "24"
/>

<paraStyle name="head_keep"
fontName="Helvetica-Bold"
fontSize="24"
leading="28"
spaceBefore = "24"
keepWithNext="1"
/>

<paraStyle name="head_nokeep"
fontName="Helvetica-Bold"
fontSize="24"
leading="28"
spaceBefore = "24"
keepWithNext="0"
/>

<paraStyle name="body"
fontName="Helvetica"
fontSize="12"
leading="14"
spaceBefore = "3"
/>


<blockTableStyle id="myStyle">
<blockAlignment value="center"/>
<blockFont name="Helvetica-Oblique"/>
<lineStyle kind="GRID" colorName="black"/>
</blockTableStyle>

</stylesheet>


<story>
<spacer length="3.65in"/>
<para style="style1">This page tests splitting - this PARAGRAPH in style 'style1' should
split between the two frames on this page. This page tests splitting -
this paragraph should split between the two frames on this page. This
page tests splitting - this paragraph should split between the two
frames on this page. This page tests splitting - this paragraph should
split between the two frames on this page. This page tests splitting -
this paragraph should split between the two frames on this page.
</para>

<nextFrame/>

<spacer length="3.65in"/>
<pre style="style1">This page tests splitting - this PRE in style
'style1' should split between the two frames on this page. These
frames should be ON PAGE TWO, otherwise this test has FAILED. This
page tests splitting - this preformatted paragraph should split between the
two -- (proves this is a pre)
frames on this page. This page tests splitting - this pre should
split between the two frames on this page. This page tests splitting -
this pre should split between the two frames on this page. This
page tests splitting - this pre should split between the two
frames on this page. </pre>

<nextFrame/>

<spacer length="3.65in"/>

<blockTable colWidths="3cm, 3cm,3cm" style="myStyle">
<tr> <td>This tests </td> <td>how a </td><td>simple table</td></tr>
<tr> <td>splits</td> <td>across</td><td>frames</td></tr>
<tr> <td>blah</td> <td>blah</td><td>blah</td></tr>
</blockTable>

<nextFrame/>

<spacer length="3.65in"/>

<plugInFlowable module="module" function="myPreformatted"/>



</story>

</document>
29 changes: 29 additions & 0 deletions src/z3c/rml/tests/input/rml-examples-010-linkURL.rml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- edited with XML Spy v4.0 U (http://www.xmlspy.com) by Andy Robinson (Reportlab Inc.) -->
<!DOCTYPE document SYSTEM "rml_1_0.dtd">
<document filename="test_010_linkURL.pdf">
<template pageSize="(595, 842)" leftMargin="72" showBoundary="1">
<pageTemplate id="main">
<frame id="first" x1="1in" y1="1in" width="6.27in" height="9.69in"/>
</pageTemplate>
</template>
<stylesheet>
</stylesheet>
<story>
<para>These should have links.</para>
<blockTable colWidths="5cm,5cm">
<blockTableStyle id="temp001">
<blockAlignment value="left"/>
<blockFont name="Helvetica-Oblique"/>
<lineStyle kind="GRID" colorName="black"/>
<lineStyle kind="OUTLINE" colorName="black" thickness="2"/>
<blockBackground colorName="pink" start="0,0" stop="-1,0"/>
<blockBackground colorName="yellow" start="0,0" stop="-1,0"/>
</blockTableStyle>
<tr><td>Name</td><td>Email</td></tr>
<tr>
<td>Robin</td>
<td><plugInFlowable module="mymodule" function="linkURL">("mailto:robin@reportlab.com",)</plugInFlowable></td>
</tr>
</blockTable>
</story>
</document>
51 changes: 51 additions & 0 deletions src/z3c/rml/tests/module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
##############################################################################
#
# Copyright (c) 2007 Zope Corporation 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 PARTLAR PURPOSE.
#
##############################################################################
"""Testing all XML Locale functionality.
$Id$
"""
import reportlab.platypus
import reportlab.lib.styles

def myPreformatted(params):
return reportlab.platypus.Preformatted('''
Hey, this is a long text from a plugin. Hey, this is a long text from
a plugin. Hey, this is a long text from a plugin. Hey, this is a long
text from a plugin. Hey, this is a long text from a plugin. Hey, this
is a long text from a plugin. Hey, this is a long text from a
plugin. Hey, this is a long text from a plugin. Hey, this is a long
text from a plugin. Hey, this is a long text from a plugin. Hey, this
is a long text from a plugin. Hey, this is a long text from a
plugin. Hey, this is a long text from a plugin. Hey, this is a long
text from a plugin. Hey, this is a long text from a plugin. Hey, this
is a long text from a plugin.''',
reportlab.lib.styles.getSampleStyleSheet()['Normal'])

class LinkURL(reportlab.platypus.flowables.Flowable):
def __init__(self, link):
self.link = link

def wrap(self, *args):
return (0, 0)

def draw(self):
self.canv.linkURL(self.link, None)


def linkURL(params):
params = eval(params)
return (
reportlab.platypus.Paragraph(
params[0], reportlab.lib.styles.getSampleStyleSheet()['Normal']),
LinkURL(*params))
8 changes: 7 additions & 1 deletion src/z3c/rml/tests/test_rml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# Copyright (c) 2007 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
Expand All @@ -17,6 +17,7 @@
"""
import os
import unittest
import sys
import z3c.rml.tests
from z3c.rml import rml2pdf, attr

Expand All @@ -34,9 +35,14 @@ def testOpen(img, filename):
path = os.path.join(os.path.dirname(self._inPath), filename)
return open(path)
attr.Image.open = testOpen
import z3c.rml.tests.module
sys.modules['module'] = z3c.rml.tests.module
sys.modules['mymodule'] = z3c.rml.tests.module

def tearDown(self):
attr.Image.open = self._imageOpen
del sys.modules['module']
del sys.modules['mymodule']

def runTest(self):
rml2pdf.go(self._inPath, self._outPath)
Expand Down

0 comments on commit 644d5da

Please sign in to comment.