diff options
| author | Tony Gu (openerp-chinese-team) <> | 2010-12-29 16:51:33 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2010-12-29 16:51:33 +0100 |
| commit | 3e1a8baf27e49aaff614f0585dddc9fd6544b944 (patch) | |
| tree | 983af42872c52ff4cc9d5c3110e91d42a770f312 | |
| parent | 50cf154537b9eeafcada4098e61e6807ce6cd0bf (diff) | |
| parent | c5306903ba63daa28262b08389406b0d947e2c7c (diff) | |
[MERGE] reports: register custom fonts only once to improve the report creation performance
bzr revid: odo@openerp.com-20101229155133-xiivbynvjwlvma8f
| -rw-r--r-- | bin/report/render/rml2pdf/customfonts.py | 20 | ||||
| -rw-r--r-- | bin/report/render/rml2pdf/trml2pdf.py | 8 |
2 files changed, 15 insertions, 13 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 <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -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 diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py index 04de2caca51..4aa39d54bb6 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,7 +255,8 @@ class _rml_doc(object): 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 |
