reportlab/demos/stdfonts/stdfonts.py
changeset 459 642367b8c821
parent 181 62d7a443cbc4
child 494 54257447cfe9
--- a/reportlab/demos/stdfonts/stdfonts.py	Fri Sep 08 10:04:08 2000 +0000
+++ b/reportlab/demos/stdfonts/stdfonts.py	Mon Sep 25 12:33:33 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: stdfonts.py,v $
+#	Revision 1.6  2000/09/25 12:33:33  andy_robinson
+#	Allows you to generate hex, decimal or octal labels
+#
 #	Revision 1.5  2000/04/28 17:33:44  andy_robinson
 #	Added font encoding support and changed default encoding to WinAnsi
-#
+#	
 #	Revision 1.4  2000/02/17 02:06:28  rgbecker
 #	Docstring & other fixes
 #	
@@ -46,17 +49,29 @@
 #	Revision 1.1.1.1  2000/02/15 15:15:57  rgbecker
 #	Initial setup of demos directory and contents.
 #	
-__version__=''' $Id: stdfonts.py,v 1.5 2000/04/28 17:33:44 andy_robinson Exp $ '''
+__version__=''' $Id: stdfonts.py,v 1.6 2000/09/25 12:33:33 andy_robinson Exp $ '''
 __doc__="""
-standardfonts.py
-shows the 14 standard fonts in our encoding
+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
 
-def run():
+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,
@@ -71,6 +86,9 @@
                 encLabel = enc
             canv.setFont('Times-Bold', 18)
             canv.drawString(80, 744, fontname + '-' + encLabel)
+            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.
@@ -78,20 +96,26 @@
                 labelfont = 'Helvetica'
             else:
                 labelfont = fontname
-
             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, '%d =' % byt)
+                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__':
-    run()
+    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__
+