← Back to team overview

openerp-chinese-team team mailing list archive

[Merge] lp:~openerp-chinese-team/openobject-server/V6 into lp:openobject-server

 

digitalsatori has proposed merging lp:~openerp-chinese-team/openobject-server/V6 into lp:openobject-server.

Requested reviews:
  OpenERP Core Team (openerp)


register fonts only when needed to improve the report process speed
-- 
https://code.launchpad.net/~openerp-chinese-team/openobject-server/V6/+merge/44161
Your team Open ERP Chinese is subscribed to branch lp:~openerp-chinese-team/openobject-server/V6.
=== modified file 'bin/report/render/rml2pdf/customfonts.py'
--- bin/report/render/rml2pdf/customfonts.py	2010-11-26 18:30:43 +0000
+++ bin/report/render/rml2pdf/customfonts.py	2010-12-19 06:46:10 +0000
@@ -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 <http://www.gnu.org/licenses/>.     
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
@@ -34,7 +34,7 @@
 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 @@
         ('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 @@
 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 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

=== modified file 'bin/report/render/rml2pdf/trml2pdf.py'
--- bin/report/render/rml2pdf/trml2pdf.py	2010-12-14 16:28:26 +0000
+++ bin/report/render/rml2pdf/trml2pdf.py	2010-12-19 06:46:10 +0000
@@ -65,7 +65,7 @@
         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 @@
             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,7 +255,8 @@
         from reportlab.pdfbase import pdfmetrics
         from reportlab.pdfbase.ttfonts import TTFont
 
-        pdfmetrics.registerFont(TTFont(fontname, filename ))
+        if fontname not in pdfmetrics._fonts:
+            pdfmetrics.registerFont(TTFont(fontname, filename ))
         if (mode == 'all'):
             addMapping(face, 0, 0, fontname)    #normal
             addMapping(face, 0, 1, fontname)    #italic


Follow ups