From 25f5329deb4068ac737bf7ffdfe54046a46221da Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 22 Jan 2015 14:14:36 +0100 Subject: [PATCH] [FIX] report: break lines and splitted words with reportlab > 3.0 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 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. --- openerp/report/render/rml2pdf/trml2pdf.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openerp/report/render/rml2pdf/trml2pdf.py b/openerp/report/render/rml2pdf/trml2pdf.py index 3b36c3ef932..61da2973a9c 100644 --- a/openerp/report/render/rml2pdf/trml2pdf.py +++ b/openerp/report/render/rml2pdf/trml2pdf.py @@ -32,6 +32,7 @@ import os 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 @@ -175,6 +176,7 @@ class _rml_styles(object,): '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): @@ -767,8 +769,15 @@ class _rml_flowable(object): 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(' 
', style, **(utils.attr_get(node, [], {'bulletText': 'str'})))) return result elif node.tag=='barCode': try: