18
18
##############################################################################
20
20
from osv import fields, osv
21
from reportlab.lib.fontfinder import FontFinder
22
from reportlab import rl_config
24
26
class oecn_base_fonts_map(osv.osv_memory):
25
27
_name = 'oecn_base_fonts.map'
26
28
def _system_fonts_get(self, cr, uid, ids, context = None):
27
29
''' get fonts list on server '''
28
res = [('font1','font1'),('font2','font2')]
30
# consider both windows and unix like systems
33
'windir': os.environ.get('windir', os.getcwd()),
34
'home': os.environ.get('HOME', os.getcwd()),
39
'%(home)s/tmp/corefonts',
41
folders = [ s % env for s in FontFolders]
42
# get all folders under fonts directory
43
ff = FontFinder( useCache = False )
45
for root, dirs, files in os.walk(ele):
47
folders.append(os.path.join(root, name))
49
ff.addDirectories( set ( folders ))
51
# get fonts name and file path
53
for familyName in ff.getFamilyNames():
54
for font in ff.getFontsInFamily(familyName):
55
if font.fileName[-4:] == ".ttf":
56
res.append((font.fileName, font.name))
32
60
'map_id':fields.many2one('oecn_base_fonts.config','Font Map', required=True),
33
61
'pdf_font':fields.char('Font in pdf report', size=64, required=True),
62
'name':fields.char('New Font name', size=20, required=True),
34
63
'new_font':fields.selection(_system_fonts_get, 'Font to display', required=True),
37
69
oecn_base_fonts_map()
52
84
config_obj = self.pool.get('ir.config_parameter')
54
86
for map in o.map_ids:
55
maps = maps + [(map.pdf_font, map.new_font)]
87
for style in ['normal','bold','italic','bolditalic']:
88
maps = maps + [(map.pdf_font, map.name ,map.new_font, style)]
56
89
config_obj.set_param(cr, uid, 'fonts_map', {'wrap':o.wrap,'maps':maps})
57
# print str(config_obj.get_param(cr, uid, 'fonts_map'))
59
91
oecn_base_fonts_config()
61
93
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: