2963
|
1 |
#Copyright ReportLab Europe Ltd. 2000-2004
|
|
2 |
#see license.txt for license details
|
|
3 |
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/demos/stdfonts/stdfonts.py
|
|
4 |
__version__=''' $Id$ '''
|
|
5 |
__doc__="""
|
|
6 |
This generates tables showing the 14 standard fonts in both
|
|
7 |
WinAnsi and MacRoman encodings, and their character codes.
|
|
8 |
Supply an argument of 'hex' or 'oct' to get code charts
|
|
9 |
in those encodings; octal is what you need for \\n escape
|
|
10 |
sequences in Python literals.
|
|
11 |
|
|
12 |
usage: standardfonts.py [dec|hex|oct]
|
|
13 |
"""
|
|
14 |
import sys
|
|
15 |
from reportlab.pdfbase import pdfmetrics
|
|
16 |
from reportlab.pdfgen import canvas
|
|
17 |
import string
|
|
18 |
|
|
19 |
label_formats = {'dec':('%d=', 'Decimal'),
|
|
20 |
'oct':('%o=','Octal'),
|
|
21 |
'hex':('0x%x=', 'Hexadecimal')}
|
|
22 |
|
|
23 |
def run(mode):
|
|
24 |
|
|
25 |
label_formatter, caption = label_formats[mode]
|
|
26 |
|
|
27 |
for enc in ['MacRoman', 'WinAnsi']:
|
|
28 |
canv = canvas.Canvas(
|
|
29 |
'StandardFonts_%s.pdf' % enc,
|
|
30 |
)
|
|
31 |
canv.setPageCompression(0)
|
|
32 |
|
|
33 |
for faceName in pdfmetrics.standardFonts:
|
|
34 |
if faceName in ['Symbol', 'ZapfDingbats']:
|
|
35 |
encLabel = faceName+'Encoding'
|
|
36 |
else:
|
|
37 |
encLabel = enc + 'Encoding'
|
|
38 |
|
|
39 |
fontName = faceName + '-' + encLabel
|
|
40 |
pdfmetrics.registerFont(pdfmetrics.Font(fontName,
|
|
41 |
faceName,
|
|
42 |
encLabel)
|
|
43 |
)
|
|
44 |
|
|
45 |
canv.setFont('Times-Bold', 18)
|
|
46 |
canv.drawString(80, 744, fontName)
|
|
47 |
canv.setFont('Times-BoldItalic', 12)
|
|
48 |
canv.drawRightString(515, 744, 'Labels in ' + caption)
|
|
49 |
|
|
50 |
|
|
51 |
#for dingbats, we need to use another font for the numbers.
|
|
52 |
#do two parallel text objects.
|
|
53 |
for byt in range(32, 256):
|
|
54 |
col, row = divmod(byt - 32, 32)
|
|
55 |
x = 72 + (66*col)
|
|
56 |
y = 720 - (18*row)
|
|
57 |
canv.setFont('Helvetica', 14)
|
|
58 |
canv.drawString(x, y, label_formatter % byt)
|
|
59 |
canv.setFont(fontName, 14)
|
|
60 |
canv.drawString(x+44, y, chr(byt).decode(encLabel,'ignore').encode('utf8'))
|
|
61 |
canv.showPage()
|
|
62 |
canv.save()
|
|
63 |
|
|
64 |
if __name__ == '__main__':
|
|
65 |
if len(sys.argv)==2:
|
|
66 |
mode = string.lower(sys.argv[1])
|
|
67 |
if mode not in ['dec','oct','hex']:
|
|
68 |
print __doc__
|
|
69 |
|
|
70 |
elif len(sys.argv) == 1:
|
|
71 |
mode = 'dec'
|
|
72 |
run(mode)
|
|
73 |
else:
|
|
74 |
print __doc__
|