Skip to content

Commit

Permalink
Merge pull request #70 from niharikasingh/textTransform-style
Browse files Browse the repository at this point in the history
Adding textTransform implementation
  • Loading branch information
strichter committed Oct 4, 2019
2 parents 44756c5 + e36316a commit f8b41af
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGES
3.9.1 (unreleased)
------------------

- Nothing changed yet.
- Adding textTransform implementation.


3.9.0 (2019-07-19)
Expand Down
18 changes: 17 additions & 1 deletion src/z3c/rml/paraparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def _apply_strike(self, style):
setattr(frag, styleName, getattr(style, styleName))
self._new_line('strike')

def _apply_texttransform(self, style):
if not getattr(style, 'textTransform', False):
return
frag = self._stack[-1]
if hasattr(frag, 'text'):
frag.textTransform = style.textTransform

def start_span(self, attr):
reportlab.platypus.paraparser.ParaParser.start_span(self, attr)
self._stack[-1]._style = None
Expand All @@ -198,6 +205,7 @@ def start_span(self, attr):
self._stack[-1]._style = style
self._apply_underline(style)
self._apply_strike(style)
self._apply_texttransform(style)

def start_para(self, attr):
reportlab.platypus.paraparser.ParaParser.start_para(self, attr)
Expand Down Expand Up @@ -266,7 +274,15 @@ def _setup(self, text, style, bulletText, frags, cleaner, manager):
raise ValueError(
"xml parser error (%s) in paragraph beginning\n'%s'"\
% (_parser.errors[0],text[:min(30,len(text))]))
reportlab.platypus.paragraph.textTransformFrags(frags,style)
# apply texttransform to paragraphs
reportlab.platypus.paragraph.textTransformFrags(frags, style)
# apply texttransform to paragraph fragments
for frag in frags:
if hasattr(frag, '_style') \
and hasattr(frag._style, 'textTransform'):
reportlab.platypus.paragraph.textTransformFrags(
[frag], frag._style)

if bulletTextFrags:
bulletText = bulletTextFrags

Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion src/z3c/rml/tests/input/tag-barChart.rml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</categoryAxis>
<valueAxis valueMin="0" valueMax="150" valueStep="30"
visibleTicks="true" visibleLabels="true"
forceZero="true"
doc:example="">
<labels fontName="Helvetica" />
</valueAxis>
Expand All @@ -61,7 +62,7 @@
</categoryAxis>
<valueAxis valueMin="0" valueMax="150" valueStep="30"
visibleTicks="true" visibleLabels="true"
visibleGrid="true">
visibleGrid="true" forceZero="true">
<labels fontName="Helvetica" />
</valueAxis>
<data>
Expand Down
5 changes: 3 additions & 2 deletions src/z3c/rml/tests/input/tag-barChart3d.rml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
</categoryNames>
</categoryAxis>
<valueAxis valueMin="0" valueMax="150" valueStep="30"
visibleTicks="true" visibleLabels="true">
visibleTicks="true" visibleLabels="true"
forceZero="true">
<labels fontName="Helvetica" />
</valueAxis>
<data>
Expand All @@ -58,7 +59,7 @@
</categoryAxis>
<valueAxis valueMin="0" valueMax="150" valueStep="30"
visibleTicks="true" visibleLabels="true"
visibleGrid="true">
visibleGrid="true" forceZero="true">
<labels fontName="Helvetica" />
</valueAxis>
<data>
Expand Down
63 changes: 63 additions & 0 deletions src/z3c/rml/tests/input/tag-para-span-texttransform.rml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<!DOCTYPE document SYSTEM "rml.dtd">

<document
filename="tag-para-underline.pdf"
xmlns:doc="http://namespaces.zope.org/rml/doc">

<template>
<pageTemplate id="main">
<frame id="first" x1="1cm" y1="1cm" width="19cm" height="26cm"/>
</pageTemplate>
</template>

<stylesheet>
<spanStyle
name="uppercase"
textTransform="uppercase"
/>
<spanStyle
name="lowercase"
textTransform="lowercase"
/>
<spanStyle
name="capitalize"
textTransform="capitalize"
/>
<paraStyle
name="uppercase"
textTransform="uppercase"
/>
<paraStyle
name="lowercase"
textTransform="lowercase"
/>
<paraStyle
name="capitalize"
textTransform="capitalize"
/>
</stylesheet>

<story>
<para>
<span style="uppercase">
This is an uppercase span.
</span>
<span style="lowercase">
THIS IS A LOWERCASE SPAN.
</span>
<span style="capitalize">
This is a capitalized span.
</span>
</para>
<para style="uppercase">
This is an uppercase para.
</para>
<para style="lowercase">
THIS IS A LOWERCASE PARA.
</para>
<para style="capitalize">
This is a capitalized para.
</para>
</story>
</document>

0 comments on commit f8b41af

Please sign in to comment.