reportlab/demos/stdfonts/stdfonts.py
author andy_robinson
Mon, 25 Sep 2000 12:33:33 +0000
changeset 459 642367b8c821
parent 181 62d7a443cbc4
child 494 54257447cfe9
permissions -rw-r--r--
Allows you to generate hex, decimal or octal labels
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     1
###############################################################################
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     2
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     3
#	ReportLab Public License Version 1.0
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     4
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     5
#   Except for the change of names the spirit and intention of this
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     6
#   license is the same as that of Python
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     7
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     8
#	(C) Copyright ReportLab Inc. 1998-2000.
5e321293413b Initial revision
rgbecker
parents:
diff changeset
     9
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    10
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    11
# All Rights Reserved
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    12
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    13
# Permission to use, copy, modify, and distribute this software and its
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    14
# documentation for any purpose and without fee is hereby granted, provided
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    15
# that the above copyright notice appear in all copies and that both that
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    16
# copyright notice and this permission notice appear in supporting
7
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    17
# documentation, and that the name of ReportLab not be used
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    18
# in advertising or publicity pertaining to distribution of the software
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    19
# without specific, written prior permission. 
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    20
# 
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    21
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    22
# Disclaimer
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    23
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    24
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    25
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    26
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    27
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    28
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    29
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    30
# PERFORMANCE OF THIS SOFTWARE. 
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    31
#
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    32
###############################################################################
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    33
#	$Log: stdfonts.py,v $
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    34
#	Revision 1.6  2000/09/25 12:33:33  andy_robinson
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    35
#	Allows you to generate hex, decimal or octal labels
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    36
#
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    37
#	Revision 1.5  2000/04/28 17:33:44  andy_robinson
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    38
#	Added font encoding support and changed default encoding to WinAnsi
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    39
#	
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    40
#	Revision 1.4  2000/02/17 02:06:28  rgbecker
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    41
#	Docstring & other fixes
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    42
#	
10
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    43
#	Revision 1.3  2000/02/16 09:42:50  rgbecker
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    44
#	Conversion to reportlab package
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    45
#	
7
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    46
#	Revision 1.2  2000/02/15 17:55:59  rgbecker
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    47
#	License text fixes
10
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    48
#	
7
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    49
#	Revision 1.1.1.1  2000/02/15 15:15:57  rgbecker
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    50
#	Initial setup of demos directory and contents.
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    51
#	
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    52
__version__=''' $Id: stdfonts.py,v 1.6 2000/09/25 12:33:33 andy_robinson Exp $ '''
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    53
__doc__="""
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    54
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
    55
WinAnsi and MacRoman encodings, and their character codes.
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    56
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
    57
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
    58
sequences in Python literals.
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    59
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    60
usage: standardfonts.py [dec|hex|oct]
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    61
"""
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    62
import sys
10
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    63
from reportlab.pdfbase import pdfmetrics
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    64
from reportlab.pdfgen import canvas
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    65
import string
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    66
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    67
label_formats = {'dec':('%d=', 'Decimal'),
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    68
                 'oct':('%o=','Octal'),
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    69
                 'hex':('0x%x=', 'Hexadecimal')}
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    70
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    71
def run(mode):
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    72
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    73
    label_formatter, caption = label_formats[mode]
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    74
    
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    75
    for enc in ['MacRoman', 'WinAnsi']:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    76
        canv = canvas.Canvas(
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    77
                'StandardFonts_%s.pdf' % enc,
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    78
                encoding=enc
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    79
                )
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    80
        canv.setPageCompression(0)
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    81
        
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    82
        for fontname in pdfmetrics.StandardEnglishFonts:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    83
            if fontname in ['Symbol', 'ZapfDingbats']:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    84
                encLabel = 'only available as MacRoman'
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    85
            else:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    86
                encLabel = enc
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    87
            canv.setFont('Times-Bold', 18)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    88
            canv.drawString(80, 744, fontname + '-' + encLabel)
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    89
            canv.setFont('Times-BoldItalic', 12)
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    90
            canv.drawRightString(515, 744, 'Labels in ' + caption)
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
    91
            
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    92
            
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    93
            #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
    94
            #do two parallel text objects.
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    95
            if fontname == 'ZapfDingbats':
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    96
                labelfont = 'Helvetica'
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    97
            else:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    98
                labelfont = fontname
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    99
            for byt in range(32, 256):
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
   100
                col, row = divmod(byt - 32, 32)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
   101
                x = 72 + (66*col)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
   102
                y = 720 - (18*row)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
   103
                canv.setFont(labelfont, 14)
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   104
                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
   105
                canv.setFont(fontname, 14)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
   106
                canv.drawString(x + 44, y , chr(byt))
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
   107
            canv.showPage()            
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
   108
        canv.save()
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
   109
5e321293413b Initial revision
rgbecker
parents:
diff changeset
   110
if __name__ == '__main__':
459
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   111
    if len(sys.argv)==2:
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   112
        mode = string.lower(sys.argv[1])
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   113
        if mode not in ['dec','oct','hex']:
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   114
            print __doc__
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   115
            
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   116
    elif len(sys.argv) == 1:
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   117
        mode = 'dec'
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   118
        run(mode)
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   119
    else:
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   120
        print __doc__
642367b8c821 Allows you to generate hex, decimal or octal labels
andy_robinson
parents: 181
diff changeset
   121