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