[IMP] font: move lazy loading to report_rml instead of report_sxw
bzr revid: mat@openerp.com-20131209113207-qwipb3urh8gbb04s
This commit is contained in:
parent
51bd2de107
commit
87dfe75013
|
@ -24,8 +24,6 @@ import re
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
import openerp
|
|
||||||
|
|
||||||
import openerp
|
import openerp
|
||||||
import openerp.tools as tools
|
import openerp.tools as tools
|
||||||
import openerp.modules
|
import openerp.modules
|
||||||
|
@ -33,6 +31,8 @@ import print_xml
|
||||||
import render
|
import render
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
|
from openerp.report.render.rml2pdf import customfonts
|
||||||
|
|
||||||
#
|
#
|
||||||
# coerce any type to a unicode string (to preserve non-ascii characters)
|
# coerce any type to a unicode string (to preserve non-ascii characters)
|
||||||
# and escape XML entities
|
# and escape XML entities
|
||||||
|
@ -91,13 +91,27 @@ class report_rml(report_int):
|
||||||
}
|
}
|
||||||
|
|
||||||
def create(self, cr, uid, ids, datas, context):
|
def create(self, cr, uid, ids, datas, context):
|
||||||
|
registry = openerp.registry(cr.dbname)
|
||||||
xml = self.create_xml(cr, uid, ids, datas, context)
|
xml = self.create_xml(cr, uid, ids, datas, context)
|
||||||
xml = tools.ustr(xml).encode('utf8')
|
xml = tools.ustr(xml).encode('utf8')
|
||||||
report_type = datas.get('report_type', 'pdf')
|
report_type = datas.get('report_type', 'pdf')
|
||||||
if report_type == 'raw':
|
if report_type == 'raw':
|
||||||
return xml, report_type
|
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))
|
||||||
|
|
||||||
rml = self.create_rml(cr, xml, uid, context)
|
rml = self.create_rml(cr, xml, uid, context)
|
||||||
registry = openerp.registry(cr.dbname)
|
|
||||||
ir_actions_report_xml_obj = registry['ir.actions.report.xml']
|
ir_actions_report_xml_obj = registry['ir.actions.report.xml']
|
||||||
report_xml_ids = ir_actions_report_xml_obj.search(cr, uid, [('report_name', '=', self.name[7:])], context=context)
|
report_xml_ids = ir_actions_report_xml_obj.search(cr, uid, [('report_name', '=', self.name[7:])], context=context)
|
||||||
self.title = report_xml_ids and ir_actions_report_xml_obj.browse(cr,uid,report_xml_ids)[0].name or 'OpenERP Report'
|
self.title = report_xml_ids and ir_actions_report_xml_obj.browse(cr,uid,report_xml_ids)[0].name or 'OpenERP Report'
|
||||||
|
|
|
@ -45,20 +45,6 @@ BasePDFFonts = [
|
||||||
('Courier', 'Courier', '/dev/null', 'all'),
|
('Courier', 'Courier', '/dev/null', 'all'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# List of fonts found on the disk
|
|
||||||
BaseCustomTTFonts = [ ('Helvetica', "DejaVu Sans", "DejaVuSans.ttf", 'normal'),
|
|
||||||
('Helvetica', "DejaVu Sans Bold", "DejaVuSans-Bold.ttf", 'bold'),
|
|
||||||
('Helvetica', "DejaVu Sans Oblique", "DejaVuSans-Oblique.ttf", 'italic'),
|
|
||||||
('Helvetica', "DejaVu Sans BoldOblique", "DejaVuSans-BoldOblique.ttf", 'bolditalic'),
|
|
||||||
('Times', "Liberation Serif", "LiberationSerif-Regular.ttf", 'normal'),
|
|
||||||
('Times', "Liberation Serif Bold", "LiberationSerif-Bold.ttf", 'bold'),
|
|
||||||
('Times', "Liberation Serif Italic", "LiberationSerif-Italic.ttf", 'italic'),
|
|
||||||
('Times', "Liberation Serif BoldItalic", "LiberationSerif-BoldItalic.ttf", 'bolditalic'),
|
|
||||||
('Courier', "FreeMono", "FreeMono.ttf", 'normal'),
|
|
||||||
('Courier', "FreeMono Bold", "FreeMonoBold.ttf", 'bold'),
|
|
||||||
('Courier', "FreeMono Oblique", "FreeMonoOblique.ttf", 'italic'),
|
|
||||||
('Courier', "FreeMono BoldOblique", "FreeMonoBoldOblique.ttf", 'bolditalic'),
|
|
||||||
]
|
|
||||||
CustomTTFonts = []
|
CustomTTFonts = []
|
||||||
|
|
||||||
# Search path for TTF files, in addition of rl_config.TTFSearchPath
|
# Search path for TTF files, in addition of rl_config.TTFSearchPath
|
||||||
|
@ -94,7 +80,7 @@ def list_all_sysfonts():
|
||||||
# TTFOpenFile is not very good at it.
|
# TTFOpenFile is not very good at it.
|
||||||
searchpath = list(set(TTFSearchPath + rl_config.TTFSearchPath))
|
searchpath = list(set(TTFSearchPath + rl_config.TTFSearchPath))
|
||||||
for dirname in searchpath:
|
for dirname in searchpath:
|
||||||
for filename in glob.glob(os.path.expanduser(dirname)+'/*.[Tt][Tt][Ff]'):
|
for filename in glob.glob(os.path.join(os.path.expanduser(dirname), '*.[Tt][Tt][Ff]')):
|
||||||
filepath.append(filename)
|
filepath.append(filename)
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ import common
|
||||||
|
|
||||||
import openerp
|
import openerp
|
||||||
from openerp.osv.fields import float as float_field, function as function_field, datetime as datetime_field
|
from openerp.osv.fields import float as float_field, function as function_field, datetime as datetime_field
|
||||||
from openerp.report.render.rml2pdf import customfonts
|
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
|
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
|
|
||||||
|
@ -425,18 +424,6 @@ class report_sxw(report_rml, preprocess.report):
|
||||||
context.update(bin_raw=True)
|
context.update(bin_raw=True)
|
||||||
registry = openerp.registry(cr.dbname)
|
registry = openerp.registry(cr.dbname)
|
||||||
ir_obj = registry['ir.actions.report.xml']
|
ir_obj = registry['ir.actions.report.xml']
|
||||||
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))
|
|
||||||
|
|
||||||
report_xml_ids = ir_obj.search(cr, uid,
|
report_xml_ids = ir_obj.search(cr, uid,
|
||||||
[('report_name', '=', self.name[7:])], context=context)
|
[('report_name', '=', self.name[7:])], context=context)
|
||||||
|
|
Loading…
Reference in New Issue