diff --git a/openerp/addons/base/res/res_font.py b/openerp/addons/base/res/res_font.py index d19eabacf85..55a490653a1 100644 --- a/openerp/addons/base/res/res_font.py +++ b/openerp/addons/base/res/res_font.py @@ -63,9 +63,23 @@ class res_font(osv.Model): }, context=context) return True - def font_scan(self, cr, uid, context=None): - self._discover_fonts(cr, uid, context=context) - return self._register_fonts(cr, uid, context=context) + def font_scan(self, cr, uid, lazy=False, context=None): + if lazy: + # lazy loading, scan only if no fonts in db + found_fonts_ids = self.search(cr, uid, [('path', '!=', '/dev/null')], context=context) + if not found_fonts_ids: + # no scan yet or no font found on the system, scan the filesystem + self._discover_fonts(cr, uid, context=context) + self._register_fonts(cr, uid, context=context) + else: + if len(customfonts.CustomTTFonts) == 0: + # CustomTTFonts list is empty + for font in self.browse(cr, uid, found_fonts_ids, context=context): + customfonts.CustomTTFonts.append((font.family, font.name, font.path, font.mode)) + else: + self._discover_fonts(cr, uid, context=context) + self._register_fonts(cr, uid, context=context) + return True def _discover_fonts(self, cr, uid, context=None): """Scan fonts on the file system, add them to the list of known fonts diff --git a/openerp/addons/base/security/ir.model.access.csv b/openerp/addons/base/security/ir.model.access.csv index ecae0109d8c..cb391a45701 100644 --- a/openerp/addons/base/security/ir.model.access.csv +++ b/openerp/addons/base/security/ir.model.access.csv @@ -43,7 +43,7 @@ "access_ir_values_group_all","ir_values group_all","model_ir_values",,1,1,1,1 "access_res_company_group_erp_manager","res_company group_erp_manager","model_res_company","group_erp_manager",1,1,1,1 "access_res_company_group_user","res_company group_user","model_res_company",,1,0,0,0 -"access_res_font_group_user","res_font group_user","model_res_font","group_user",1,1,1,1 +"access_res_font_group_erp_manager","res_font group_erp_manager","model_res_font","group_erp_manager",1,1,1,1 "access_res_font_group_all","res_font group_all","model_res_font",,1,0,0,0 "access_res_country_group_all","res_country group_user_all","model_res_country",,1,0,0,0 "access_res_country_state_group_all","res_country_state group_user_all","model_res_country_state",,1,0,0,0 diff --git a/openerp/report/interface.py b/openerp/report/interface.py index 00d1c93ab0a..6a20a63ef34 100644 --- a/openerp/report/interface.py +++ b/openerp/report/interface.py @@ -31,6 +31,7 @@ import print_xml import render import urllib +from openerp import SUPERUSER_ID from openerp.report.render.rml2pdf import customfonts # @@ -98,18 +99,7 @@ class report_rml(report_int): if report_type == 'raw': return xml, report_type - font_obj = registry['res.font'] - - # lazy loading - found_fonts_ids = font_obj.search(cr, uid, [('path', '!=', '/dev/null')], context=context) - if not found_fonts_ids: - # no scan yet or no font found on the system, scan the filesystem - font_obj.font_scan(cr, uid, context=context) - else: - if len(customfonts.CustomTTFonts) == 0: - # CustomTTFonts list is empty - for font in font_obj.browse(cr, uid, found_fonts_ids, context=context): - customfonts.CustomTTFonts.append((font.family, font.name, font.path, font.mode)) + registry['res.font'].font_scan(cr, SUPERUSER_ID, lazy=True, context=context) rml = self.create_rml(cr, xml, uid, context) ir_actions_report_xml_obj = registry['ir.actions.report.xml'] diff --git a/openerp/report/render/rml2pdf/customfonts.py b/openerp/report/render/rml2pdf/customfonts.py index fd163827504..a7138b269ee 100644 --- a/openerp/report/render/rml2pdf/customfonts.py +++ b/openerp/report/render/rml2pdf/customfonts.py @@ -92,9 +92,9 @@ def SetCustomFonts(rmldoc): This function is called once per report, so it should avoid system-wide processing (cache it, instead). """ - for name, font, filename, mode in CustomTTFonts: + for family, font, filename, mode in CustomTTFonts: if os.path.isabs(filename) and os.path.exists(filename): - rmldoc.setTTFontMapping(name, font, filename, mode) + rmldoc.setTTFontMapping(font, family, filename, mode) return True # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py index 84f52823746..03bc0ffa03f 100644 --- a/openerp/report/report_sxw.py +++ b/openerp/report/report_sxw.py @@ -34,6 +34,7 @@ import zipfile import common import openerp +from openerp import SUPERUSER_ID from openerp.osv.fields import float as float_field, function as function_field, datetime as datetime_field from openerp.tools.translate import _ from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT @@ -424,6 +425,7 @@ class report_sxw(report_rml, preprocess.report): context.update(bin_raw=True) registry = openerp.registry(cr.dbname) ir_obj = registry['ir.actions.report.xml'] + registry['res.font'].font_scan(cr, SUPERUSER_ID, lazy=True, context=context) report_xml_ids = ir_obj.search(cr, uid, [('report_name', '=', self.name[7:])], context=context)