reportlab/demos/stdfonts/stdfonts.py
author rgbecker
Wed, 25 Oct 2000 08:57:46 +0000
changeset 494 54257447cfe9
parent 459 642367b8c821
child 504 b70ec6bb4041
permissions -rw-r--r--
Changed to indirect copyright
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 459
diff changeset
     1
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 459
diff changeset
     2
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 459
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/demos/stdfonts/stdfonts.py?cvsroot=reportlab
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 459
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/demos/stdfonts/stdfonts.py,v 1.7 2000/10/25 08:57:45 rgbecker Exp $
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 459
diff changeset
     5
__version__=''' $Id: stdfonts.py,v 1.7 2000/10/25 08:57:45 rgbecker Exp $ '''
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
     6
__doc__="""
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
     7
This generates tables showing the 14 standard fonts in both
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
     8
WinAnsi and MacRoman encodings, and their character codes.
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
     9
Supply an argument of 'hex' or 'oct' to get code charts
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    10
in those encodings; octal is what you need for \\n escape
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    11
sequences in Python literals.
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    12
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    13
usage: standardfonts.py [dec|hex|oct]
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    14
"""
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    15
import sys
10
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    16
from reportlab.pdfbase import pdfmetrics
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    17
from reportlab.pdfgen import canvas
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    18
import string
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    19
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    20
label_formats = {'dec':('%d=', 'Decimal'),
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    21
                 'oct':('%o=','Octal'),
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    22
                 'hex':('0x%x=', 'Hexadecimal')}
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    23
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    24
def run(mode):
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    25
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    26
    label_formatter, caption = label_formats[mode]
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    27
    
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    28
    for enc in ['MacRoman', 'WinAnsi']:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    29
        canv = canvas.Canvas(
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    30
                'StandardFonts_%s.pdf' % enc,
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    31
                encoding=enc
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    32
                )
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    33
        canv.setPageCompression(0)
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    34
        
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    35
        for fontname in pdfmetrics.StandardEnglishFonts:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    36
            if fontname in ['Symbol', 'ZapfDingbats']:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    37
                encLabel = 'only available as MacRoman'
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    38
            else:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    39
                encLabel = enc
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    40
            canv.setFont('Times-Bold', 18)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    41
            canv.drawString(80, 744, fontname + '-' + encLabel)
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    42
            canv.setFont('Times-BoldItalic', 12)
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    43
            canv.drawRightString(515, 744, 'Labels in ' + caption)
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    44
            
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    45
            
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    46
            #for dingbats, we need to use another font for the numbers.
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    47
            #do two parallel text objects.
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    48
            if fontname == 'ZapfDingbats':
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    49
                labelfont = 'Helvetica'
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    50
            else:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    51
                labelfont = fontname
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    52
            for byt in range(32, 256):
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    53
                col, row = divmod(byt - 32, 32)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    54
                x = 72 + (66*col)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    55
                y = 720 - (18*row)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    56
                canv.setFont(labelfont, 14)
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    57
                canv.drawString(x, y, label_formatter % byt)
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    58
                canv.setFont(fontname, 14)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    59
                canv.drawString(x + 44, y , chr(byt))
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    60
            canv.showPage()            
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    61
        canv.save()
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    62
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    63
if __name__ == '__main__':
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    64
    if len(sys.argv)==2:
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    65
        mode = string.lower(sys.argv[1])
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    66
        if mode not in ['dec','oct','hex']:
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    67
            print __doc__
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    68
            
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    69
    elif len(sys.argv) == 1:
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    70
        mode = 'dec'
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    71
        run(mode)
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    72
    else:
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    73
        print __doc__
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    74