[FIX]customefont : fixed problem if ttf is not exits
authorHarry (Open ERP) <hmo@tinyerp.com>
Wed, 25 Nov 2009 13:41:16 +0000 (19:11 +0530)
committerHarry (Open ERP) <hmo@tinyerp.com>
Wed, 25 Nov 2009 13:41:16 +0000 (19:11 +0530)
bzr revid: hmo@tinyerp.com-20091125134116-n89ilj53bjmkcevw

bin/report/render/rml2pdf/customfonts.py

index 49165a1..c05e9cb 100644 (file)
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2009 P. Christeas, Tiny SPRL (<http://tiny.be>). 
+#    Copyright (C) 2004-2009 P. Christeas, Tiny SPRL (<http://tiny.be>).
 #    All Rights Reserved
 #
 #    This program is free software: you can redistribute it and/or modify
@@ -20,6 +20,8 @@
 #
 ##############################################################################
 
+from reportlab import rl_config
+import os
 
 CustomTTFonts = [ ('Helvetica',"DejaVu Sans", "DejaVuSans.ttf", 'normal'),
         ('Helvetica',"DejaVu Sans Bold", "DejaVuSans-Bold.ttf", 'bold'),
@@ -42,8 +44,19 @@ CustomTTFonts = [ ('Helvetica',"DejaVu Sans", "DejaVuSans.ttf", 'normal'),
         ('Courier',"FreeMono Oblique", "FreeMonoOblique.ttf", 'italic'),
         ('Courier',"FreeMono BoldOblique", "FreeMonoBoldOblique.ttf", 'bolditalic'),]
 
+
 def SetCustomFonts(rmldoc):
     for name, font, fname, mode in CustomTTFonts:
-        rmldoc.setTTFontMapping(name, font,fname, mode)
+        for dirname in rl_config.TTFSearchPath:
+            for root, dirs, files in os.walk(os.path.abspath(dirname)):
+                for file_name in files:
+                    filename = os.path.join(root, file_name)
+                    extension = os.path.splitext(filename)[1]
+                    if extension.lower() in ['.ttf']:
+                          if file_name==fname:
+                              rmldoc.setTTFontMapping(name, font,filename, mode)
+
+
+
 
 #eof