From 2e03947c9f08794d56155d40305515fc3e38aea2 Mon Sep 17 00:00:00 2001 From: Tony Gu Date: Mon, 20 Dec 2010 13:48:43 +0800 Subject: [PATCH 1/3] [IMP]to allow outside module to set differnt search path in TTFSerachPath* variables bzr revid: tony@wonderland-20101220054843-uru3i4a9wut02qou --- bin/report/render/rml2pdf/customfonts.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/report/render/rml2pdf/customfonts.py b/bin/report/render/rml2pdf/customfonts.py index a60c2d267f5..ccbcd2c1a4a 100644 --- a/bin/report/render/rml2pdf/customfonts.py +++ b/bin/report/render/rml2pdf/customfonts.py @@ -16,7 +16,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -34,7 +34,7 @@ the reportlab engine. This file could be customized per distro (although most Linux/Unix ones) should have the same filenames, only need the code below). -Due to an awful configuration that ships with reportlab at many Linux +Due to an awful configuration that ships with reportlab at many Linux and Ubuntu distros, we have to override the search path, too. """ @@ -56,26 +56,26 @@ CustomTTFonts = [ ('Helvetica',"DejaVu Sans", "DejaVuSans.ttf", 'normal'), ('Courier',"FreeMono BoldOblique", "FreeMonoBoldOblique.ttf", 'bolditalic'),] -TTFSearchPath_Linux = ( +TTFSearchPath_Linux = [ '/usr/share/fonts/truetype', # SuSE '/usr/share/fonts/dejavu', '/usr/share/fonts/liberation', # Fedora, RHEL '/usr/share/fonts/truetype/*', # Ubuntu, '/usr/share/fonts/TTF/*', # at Mandriva/Mageia - ) + ] -TTFSearchPath_Windows = ( +TTFSearchPath_Windows = [ 'c:/winnt/fonts', 'c:/windows/fonts' - ) + ] -TTFSearchPath_Darwin = ( +TTFSearchPath_Darwin = [ #mac os X - from #http://developer.apple.com/technotes/tn/tn2024.html '~/Library/Fonts', '/Library/Fonts', '/Network/Library/Fonts', '/System/Library/Fonts', - ) + ] TTFSearchPathMap = { 'Darwin': TTFSearchPath_Darwin, @@ -89,7 +89,7 @@ __foundFonts = None def FindCustomFonts(): """Fill the __foundFonts list with those filenames, whose fonts can be found in the reportlab ttf font path. - + This process needs only be done once per loading of this module, it is cached. But, if the system admin adds some font in the meanwhile, the server must be restarted eventually. @@ -131,7 +131,7 @@ def FindCustomFonts(): def SetCustomFonts(rmldoc): """ Map some font names to the corresponding TTF fonts - + The ttf font may not even have the same name, as in Times -> Liberation Serif. This function is called once per report, so it should From 5cde817a86a2649caf74e32d7822121a05e6fa6c Mon Sep 17 00:00:00 2001 From: Tony Gu Date: Mon, 20 Dec 2010 13:50:40 +0800 Subject: [PATCH 2/3] [IMP]register custom fonts once only bzr revid: tony@wonderland-20101220055040-lti41w3qq5xi3dtp --- bin/report/render/rml2pdf/trml2pdf.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py index d01317f8257..043814a6854 100644 --- a/bin/report/render/rml2pdf/trml2pdf.py +++ b/bin/report/render/rml2pdf/trml2pdf.py @@ -65,7 +65,7 @@ def _open_image(filename, path=None): except IOError: pass raise IOError("File %s cannot be found in image path" % filename) - + class NumberedCanvas(canvas.Canvas): def __init__(self, *args, **kwargs): canvas.Canvas.__init__(self, *args, **kwargs) @@ -243,7 +243,8 @@ class _rml_doc(object): for font in node.findall('registerFont'): name = font.get('fontName').encode('ascii') fname = font.get('fontFile').encode('ascii') - pdfmetrics.registerFont(TTFont(name, fname )) + if name not in pdfmetrics._fonts: + pdfmetrics.registerFont(TTFont(name, fname )) addMapping(name, 0, 0, name) #normal addMapping(name, 0, 1, name) #italic addMapping(name, 1, 0, name) #bold @@ -254,6 +255,8 @@ class _rml_doc(object): from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont + if fontname not in pdfmetrics._fonts: + pdfmetrics.registerFont(TTFont(name, fname )) pdfmetrics.registerFont(TTFont(fontname, filename )) if (mode == 'all'): addMapping(face, 0, 0, fontname) #normal From c5306903ba63daa28262b08389406b0d947e2c7c Mon Sep 17 00:00:00 2001 From: Tony Gu Date: Mon, 20 Dec 2010 16:26:15 +0800 Subject: [PATCH 3/3] corrected a typo bzr revid: tony@wonderland-20101220082615-k92tie6gnxd5v01a --- bin/report/render/rml2pdf/trml2pdf.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py index 043814a6854..17283525bbb 100644 --- a/bin/report/render/rml2pdf/trml2pdf.py +++ b/bin/report/render/rml2pdf/trml2pdf.py @@ -256,8 +256,7 @@ class _rml_doc(object): from reportlab.pdfbase.ttfonts import TTFont if fontname not in pdfmetrics._fonts: - pdfmetrics.registerFont(TTFont(name, fname )) - pdfmetrics.registerFont(TTFont(fontname, filename )) + pdfmetrics.registerFont(TTFont(fontname, filename )) if (mode == 'all'): addMapping(face, 0, 0, fontname) #normal addMapping(face, 0, 1, fontname) #italic