Skip to content

Commit

Permalink
[FIX] report: break lines and splitted words with reportlab > 3.0
Browse files Browse the repository at this point in the history
From reportlab 3.0, empty plaintext paragraphs do not lead to a break line anymore.
Before release 3.0, paragraphs having tags but no plaintext leaded to a break line.
This patch aims to recover the behavior of reportlab releases < 3.0, as
<para><font color="white"> </font></para> is used in allmost all rml reports
The current patch is not considered as clean, but we did not find any better solution.
If someone find a parameter to pass to reportlab in order to bring back the old behavior of reportlab
he is welcome to provide the better patch.

Besides, in reportlab 3.0, splitlongwords has been introduced as parameter,
to allow to break long words. The default value is True.
This parameter seems to break the columns headers
(it splits the text within the column header)
We therefore take the choice to not activate it, as it was not present anyway in reportlab < 3.0

To test the good behavior of this patch:
While having reportlab < 3.0 (2.5 for instance), print a draft invoice
Then, upgrade to reportlab > 3.0 (3.1.8 for instance), print the same draft invoice.
The generated pdf must be (allmost) identical, in particular concerning spaces.
Specifically, the space between the partner address and his phone.
  • Loading branch information
beledouxdenis committed Jan 22, 2015
1 parent 9f8731c commit 25f5329
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion openerp/report/render/rml2pdf/trml2pdf.py
Expand Up @@ -32,6 +32,7 @@
import logging
from lxml import etree
import base64
from distutils.version import LooseVersion
from reportlab.platypus.doctemplate import ActionFlowable
from openerp.tools.safe_eval import safe_eval as eval
from reportlab.lib.units import inch,cm,mm
Expand Down Expand Up @@ -175,6 +176,7 @@ def _para_style_update(self, node):
'justify':reportlab.lib.enums.TA_JUSTIFY
}
data['alignment'] = align.get(node.get('alignment').lower(), reportlab.lib.enums.TA_LEFT)
data['splitLongWords'] = 0
return data

def _table_style_get(self, style_node):
Expand Down Expand Up @@ -767,8 +769,15 @@ def _flowable(self, node, extra_style=None):
if extra_style:
style.__dict__.update(extra_style)
result = []
tag_text = ''
plain_text = ''
for i in self._textual(node).split('\n'):
result.append(platypus.Paragraph(i, style, **(utils.attr_get(node, [], {'bulletText':'str'}))))
instance = platypus.Paragraph(i, style, **(utils.attr_get(node, [], {'bulletText':'str'})))
plain_text += instance.getPlainText().strip()
tag_text += instance.text.strip()
result.append(instance)
if LooseVersion(reportlab.Version) > LooseVersion('3.0') and not plain_text and tag_text:
result.append(platypus.Paragraph('&nbsp;<br/>', style, **(utils.attr_get(node, [], {'bulletText': 'str'}))))
return result
elif node.tag=='barCode':
try:
Expand Down

0 comments on commit 25f5329

Please sign in to comment.