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