1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# -*- coding: utf-8 -*-
# __author__ = jeff@openerp.cn
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>.
#
##############################################################################
from osv import fields, osv
from reportlab.lib.fontfinder import FontFinder
from reportlab import rl_config
import os
class oecn_base_fonts_map(osv.osv_memory):
_name = 'oecn_base_fonts.map'
def _system_fonts_get(self, cr, uid, ids, context = None):
''' get fonts list on server '''
# consider both windows and unix like systems
res = []
env = {
'windir': os.environ.get('windir', os.getcwd()),
'home': os.environ.get('HOME', os.getcwd()),
}
FontFolders = [
'%(windir)s/Fonts',
'/usr/share/fonts',
'%(home)s/tmp/corefonts',
]
folders = [ s % env for s in FontFolders]
# get all folders under fonts directory
ff = FontFinder( useCache = False )
for ele in folders:
for root, dirs, files in os.walk(ele):
for name in dirs:
folders.append(os.path.join(root, name))
ff.addDirectories( set ( folders ))
# get fonts name and file path
ff.search()
for familyName in ff.getFamilyNames():
for font in ff.getFontsInFamily(familyName):
if font.fileName[-4:] == ".ttf":
res.append((font.fileName, font.name))
return res
_columns = {
'map_id':fields.many2one('oecn_base_fonts.config','Font Map', required=True),
'pdf_font':fields.char('Font in pdf report', size=64, required=True),
'name':fields.char('New Font name', size=20, required=True),
'new_font':fields.selection(_system_fonts_get, 'Font to display', required=True),
}
_defaults = {
'name':'SimHei',
}
oecn_base_fonts_map()
class oecn_base_fonts_config(osv.osv_memory):
_name = 'oecn_base_fonts.config'
_inherit = 'res.config'
_columns = {
'wrap':fields.char('Word Wrap', size=64, required=True),
'map_ids':fields.one2many('oecn_base_fonts.map','map_id','Fonts you need to replace in pdf'),
}
_defaults = {
'wrap':'CJK',
}
def execute(self, cr, uid, ids, context=None):
for o in self.browse(cr, uid, ids, context=context):
config_obj = self.pool.get('ir.config_parameter')
maps = []
for map in o.map_ids:
for style in ['normal','bold','italic','bolditalic']:
maps = maps + [(map.pdf_font, map.name ,map.new_font, style)]
config_obj.set_param(cr, uid, 'fonts_map', {'wrap':o.wrap,'maps':maps})
oecn_base_fonts_config()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|