From f528f74a12212aabea58b920328f398895047993 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Mon, 14 Aug 2006 20:44:12 +0000 Subject: [PATCH] * src/docgen/PdfDoc.py: Work for both utf8 and latin-1 capable reportlab versions. svn: r7178 --- ChangeLog | 2 ++ src/docgen/PdfDoc.py | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a145a39ac..4d1a89bfb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ 2006-08-14 Alex Roitman + * src/docgen/PdfDoc.py: Work for both utf8 and latin-1 capable + reportlab versions. * src/Filters/Rules/Family/_ChildHasNameOf.py (description): Typo. * src/Filters/Rules/Family/_ChildHasIdOf.py (description): Typo. * src/Filters/Rules/Family/_FatherHasNameOf.py (description): Typo. diff --git a/src/docgen/PdfDoc.py b/src/docgen/PdfDoc.py index f15650b77..ab146553c 100644 --- a/src/docgen/PdfDoc.py +++ b/src/docgen/PdfDoc.py @@ -77,6 +77,27 @@ try: except ImportError: raise Errors.UnavailableError(_("Cannot be loaded because ReportLab is not installed")) + +# Old reportlab versions < 2.0 did not work with utf8 or unicode +# so for those we need to encode text into latin1 +# For the utf8-capable reportlab we should not. +def enc_latin1(s): + try: + new_s = s + return new_s.encode('iso-8859-1') + except: + return str(s) + +def pass_through(s): + return s + +from reportlab import Version as reportlab_version +version_tuple = tuple( [int(item) for item in reportlab_version.split('.')] ) +if version_tuple < (2,0): + enc = enc_latin1 +else: + enc = pass_through + #------------------------------------------------------------------------ # # GrampsDocTemplate @@ -91,13 +112,6 @@ class GrampsDocTemplate(BaseDocTemplate): self._calc() BaseDocTemplate.build(self,flowables) -def enc(s): - try: - new_s = s - return new_s.encode('iso-8859-1') - except: - return str(s) - #------------------------------------------------------------------------ # #