Skip to content

Commit

Permalink
adding textTransform implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
niharikasingh committed Oct 3, 2019
1 parent 44756c5 commit 1820cdf
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
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
19 changes: 18 additions & 1 deletion src/z3c/rml/paraparser.py
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(style, 'textTransform') and hasattr(frag, 'text'):
setattr(frag, 'textTransform', getattr(style, 'textTransform'))

def start_span(self, attr):
reportlab.platypus.paraparser.ParaParser.start_span(self, attr)
self._stack[-1]._style = None
Expand All @@ -198,11 +205,13 @@ 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)
self._apply_underline(self._style)
self._apply_strike(self._style)
self._apply_texttransform(self._style)

def start_pagenumber(self, attributes):
self.startDynamic(attributes, PageNumberFragment)
Expand Down Expand Up @@ -266,7 +275,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.
63 changes: 63 additions & 0 deletions src/z3c/rml/tests/input/tag-para-span-texttransform.rml
@@ -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 1820cdf

Please sign in to comment.