2
#Copyright ReportLab Europe Ltd. 2000-2004
3
#see license.txt for license details
4
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/lib/fonts.py
5
__version__=''' $Id$ '''
7
###############################################################################
8
# A place to put useful font stuff
9
###############################################################################
12
# The brute force approach to finding the correct postscript font name;
13
# much safer than the rule-based ones we tried.
14
# preprocessor to reduce font face names to the shortest list
15
# possible. Add any aliases you wish; it keeps looking up
16
# until it finds no more translations to do. Any input
17
# will be lowercased before checking.
20
'sansserif':'helvetica',
21
'monospaced':'courier',
24
#maps a piddle font to a postscript one.
26
#face, bold, italic -> ps name
27
('times', 0, 0) :'Times-Roman',
28
('times', 1, 0) :'Times-Bold',
29
('times', 0, 1) :'Times-Italic',
30
('times', 1, 1) :'Times-BoldItalic',
32
('courier', 0, 0) :'Courier',
33
('courier', 1, 0) :'Courier-Bold',
34
('courier', 0, 1) :'Courier-Oblique',
35
('courier', 1, 1) :'Courier-BoldOblique',
37
('helvetica', 0, 0) :'Helvetica',
38
('helvetica', 1, 0) :'Helvetica-Bold',
39
('helvetica', 0, 1) :'Helvetica-Oblique',
40
('helvetica', 1, 1) :'Helvetica-BoldOblique',
43
# there is only one Symbol font
44
('symbol', 0, 0) :'Symbol',
45
('symbol', 1, 0) :'Symbol',
46
('symbol', 0, 1) :'Symbol',
47
('symbol', 1, 1) :'Symbol',
50
('zapfdingbats', 0, 0) :'ZapfDingbats',
51
('zapfdingbats', 1, 0) :'ZapfDingbats',
52
('zapfdingbats', 0, 1) :'ZapfDingbats',
53
('zapfdingbats', 1, 1) :'ZapfDingbats',
59
for k,v in _tt2ps_map.items():
60
if not _ps2tt_map.has_key(k):
61
_ps2tt_map[string.lower(v)] = k
64
'ps fontname to family name, bold, italic'
65
psfn = string.lower(psfn)
66
if _ps2tt_map.has_key(psfn):
67
return _ps2tt_map[psfn]
68
raise ValueError, "Can't map determine family/bold/italic for %s" % psfn
71
'family name + bold & italic to ps font name'
72
K = (string.lower(fn),b,i)
73
if _tt2ps_map.has_key(K):
76
fn, b1, i1 = ps2tt(K[0])
78
if _tt2ps_map.has_key(K):
80
raise ValueError, "Can't find concrete font for family=%s, bold=%d, italic=%d" % (fn, b, i)
82
def addMapping(face, bold, italic, psname):
83
'allow a custom font to be put in the mapping'
84
k = (string.lower(face), bold, italic)
85
_tt2ps_map[k] = psname
86
# rebuild inverse - inefficient
87
for k,v in _tt2ps_map.items():
88
if not _ps2tt_map.has_key(k):
89
_ps2tt_map[string.lower(v)] = k