reportlab/demos/stdfonts/stdfonts.py
author andy_robinson
Fri, 28 Apr 2000 17:33:44 +0000
changeset 181 62d7a443cbc4
parent 16 f9c7525619fb
child 459 642367b8c821
permissions -rw-r--r--
Added font encoding support and changed default encoding to WinAnsi
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 $
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    34
#	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
    35
#	Added font encoding support and changed default encoding to WinAnsi
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    36
#
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    37
#	Revision 1.4  2000/02/17 02:06:28  rgbecker
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    38
#	Docstring & other fixes
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    39
#	
10
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    40
#	Revision 1.3  2000/02/16 09:42:50  rgbecker
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    41
#	Conversion to reportlab package
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    42
#	
7
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    43
#	Revision 1.2  2000/02/15 17:55:59  rgbecker
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    44
#	License text fixes
10
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    45
#	
7
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    46
#	Revision 1.1.1.1  2000/02/15 15:15:57  rgbecker
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    47
#	Initial setup of demos directory and contents.
ca9eb4f68eab License text fixes
rgbecker
parents: 5
diff changeset
    48
#	
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    49
__version__=''' $Id: stdfonts.py,v 1.5 2000/04/28 17:33:44 andy_robinson Exp $ '''
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    50
__doc__="""
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    51
standardfonts.py
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    52
shows the 14 standard fonts in our encoding
f9c7525619fb Docstring & other fixes
rgbecker
parents: 10
diff changeset
    53
"""
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    54
10
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    55
from reportlab.pdfbase import pdfmetrics
0cb88428a663 Conversion to reportlab package
rgbecker
parents: 7
diff changeset
    56
from reportlab.pdfgen import canvas
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    57
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    58
def run():
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    59
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    60
    for enc in ['MacRoman', 'WinAnsi']:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    61
        canv = canvas.Canvas(
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    62
                'StandardFonts_%s.pdf' % enc,
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    63
                encoding=enc
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    64
                )
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    65
        canv.setPageCompression(0)
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    66
        
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    67
        for fontname in pdfmetrics.StandardEnglishFonts:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    68
            if fontname in ['Symbol', 'ZapfDingbats']:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    69
                encLabel = 'only available as MacRoman'
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    70
            else:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    71
                encLabel = enc
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    72
            canv.setFont('Times-Bold', 18)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    73
            canv.drawString(80, 744, fontname + '-' + encLabel)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    74
            
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    75
            #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
    76
            #do two parallel text objects.
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    77
            if fontname == 'ZapfDingbats':
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    78
                labelfont = 'Helvetica'
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    79
            else:
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    80
                labelfont = fontname
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 byt in range(32, 256):
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    83
                col, row = divmod(byt - 32, 32)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    84
                x = 72 + (66*col)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    85
                y = 720 - (18*row)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    86
                canv.setFont(labelfont, 14)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    87
                canv.drawString(x, y, '%d =' % byt)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    88
                canv.setFont(fontname, 14)
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    89
                canv.drawString(x + 44, y , chr(byt))
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    90
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    91
            canv.showPage()            
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    92
                
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    93
181
62d7a443cbc4 Added font encoding support and changed default encoding to WinAnsi
andy_robinson
parents: 16
diff changeset
    94
        canv.save()
5
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    95
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    96
if __name__ == '__main__':
5e321293413b Initial revision
rgbecker
parents:
diff changeset
    97
    run()