diff --git a/bin/report/render/rml2pdf/customfonts.py b/bin/report/render/rml2pdf/customfonts.py index e4f15aa8d8b..097c28df524 100644 --- a/bin/report/render/rml2pdf/customfonts.py +++ b/bin/report/render/rml2pdf/customfonts.py @@ -3,6 +3,7 @@ # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 P. Christeas, Tiny SPRL (). +# Copyright (C) 2010 OpenERP SA. (http://www.openerp.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -20,6 +21,8 @@ ############################################################################## from reportlab import rl_config +from tools import config +import glob import os import logging @@ -28,6 +31,9 @@ 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 +and Ubuntu distros, we have to override the search path, too. """ CustomTTFonts = [ ('Helvetica',"DejaVu Sans", "DejaVuSans.ttf", 'normal'), @@ -51,6 +57,15 @@ CustomTTFonts = [ ('Helvetica',"DejaVu Sans", "DejaVuSans.ttf", 'normal'), ('Courier',"FreeMono Oblique", "FreeMonoOblique.ttf", 'italic'), ('Courier',"FreeMono BoldOblique", "FreeMonoBoldOblique.ttf", 'bolditalic'),] + +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 + ) + +# ----- The code below is less distro-specific, please avoid editing! ------- __foundFonts = [] def FindCustomFonts(): @@ -64,10 +79,28 @@ def FindCustomFonts(): dirpath = [] log = logging.getLogger('report.fonts') global __foundFonts - for dirname in rl_config.TTFSearchPath: - abp = os.path.abspath(dirname) - if os.path.isdir(abp): - dirpath.append(abp) + searchpath = [] + + if config.get_misc('ttfonts', 'search_path', False): + searchpath += map(str.strip, config.get_misc('ttfonts', 'search_path').split(',')) + + if os.name == 'nt': + pass # TODO + elif os.uname()[0] == 'Linux': + searchpath += TTFSearchPath_Linux + else: + pass # TODO for MacOSX, Unix etc. + + if config.get_misc('ttfonts', 'use_default_path', True): + # Append the original search path of reportlab (at the end) + searchpath += rl_config.TTFSearchPath + + for dirglob in searchpath: + dirglob = os.path.expanduser(dirglob) + for dirname in glob.iglob(dirglob): + abp = os.path.abspath(dirname) + if os.path.isdir(abp): + dirpath.append(abp) for k, (name, font, fname, mode) in enumerate(CustomTTFonts): if fname in __foundFonts: @@ -77,7 +110,7 @@ def FindCustomFonts(): log.debug("Found font %s in %s as %s", fname, d, name) __foundFonts.append(fname) break - + # print "Found fonts:", __foundFonts diff --git a/bin/tools/convert.py b/bin/tools/convert.py index 0f091ad4a56..61fdb7a82a9 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -844,11 +844,7 @@ form: module.record_id""" % (xml_id,) mod = self.module if '.' in id_str: mod,id_str = id_str.split('.') - result = model_data_obj._get_id(cr, self.uid, mod, id_str) - res = model_data_obj.read(cr, self.uid, [result], ['model', 'res_id']) - if res and res[0] and res[0]['res_id']: - return res[0]['model'], int(res[0]['res_id']) - return False + return model_data_obj.get_object_reference(cr, self.uid, mod, id_str) def parse(self, de): if not de.tag in ['terp', 'openerp']: