~openerp-groupes/openobject-server/6.0-fix-setup-windows

« back to all changes in this revision

Viewing changes to bin/reportlab/lib/fonts.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python2.3
 
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$ '''
 
6
import string, sys, os
 
7
###############################################################################
 
8
#   A place to put useful font stuff
 
9
###############################################################################
 
10
#
 
11
#      Font Mappings
 
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.
 
18
_family_alias = {
 
19
            'serif':'times',
 
20
            'sansserif':'helvetica',
 
21
            'monospaced':'courier',
 
22
            'arial':'helvetica'
 
23
            }
 
24
#maps a piddle font to a postscript one.
 
25
_tt2ps_map = {
 
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',
 
31
 
 
32
            ('courier', 0, 0) :'Courier',
 
33
            ('courier', 1, 0) :'Courier-Bold',
 
34
            ('courier', 0, 1) :'Courier-Oblique',
 
35
            ('courier', 1, 1) :'Courier-BoldOblique',
 
36
 
 
37
            ('helvetica', 0, 0) :'Helvetica',
 
38
            ('helvetica', 1, 0) :'Helvetica-Bold',
 
39
            ('helvetica', 0, 1) :'Helvetica-Oblique',
 
40
            ('helvetica', 1, 1) :'Helvetica-BoldOblique',
 
41
 
 
42
 
 
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',
 
48
 
 
49
            # ditto for dingbats
 
50
            ('zapfdingbats', 0, 0) :'ZapfDingbats',
 
51
            ('zapfdingbats', 1, 0) :'ZapfDingbats',
 
52
            ('zapfdingbats', 0, 1) :'ZapfDingbats',
 
53
            ('zapfdingbats', 1, 1) :'ZapfDingbats',
 
54
 
 
55
 
 
56
            }
 
57
 
 
58
_ps2tt_map={}
 
59
for k,v in _tt2ps_map.items():
 
60
    if not _ps2tt_map.has_key(k):
 
61
        _ps2tt_map[string.lower(v)] = k
 
62
 
 
63
def ps2tt(psfn):
 
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
 
69
 
 
70
def tt2ps(fn,b,i):
 
71
    'family name + bold & italic to ps font name'
 
72
    K = (string.lower(fn),b,i)
 
73
    if _tt2ps_map.has_key(K):
 
74
        return _tt2ps_map[K]
 
75
    else:
 
76
        fn, b1, i1 = ps2tt(K[0])
 
77
        K = fn, b1|b, i1|i
 
78
        if _tt2ps_map.has_key(K):
 
79
            return _tt2ps_map[K]
 
80
    raise ValueError, "Can't find concrete font for family=%s, bold=%d, italic=%d" % (fn, b, i)
 
81
 
 
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