reportlab/lib/codecharts.py
author rgbecker
Wed, 23 Jun 2004 08:49:10 +0000
changeset 2337 0f4b0154b382
parent 2332 2a7ab4405e18
child 2619 95e4977ac148
permissions -rw-r--r--
Fix for unicode difficulties
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2192
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2004
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2192
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/lib/codecharts.py
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
     4
#$Header $
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
     5
__version__=''' $Id '''
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
     6
__doc__="""Routines to print code page (character set) drawings.
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
     7
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
     8
To be sure we can accurately represent characters in various encodings
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
     9
and fonts, we need some routines to display all those characters.
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    10
These are defined herein.  The idea is to include flowable, drawable
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    11
and graphic objects for single and multi-byte fonts. """
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    12
import string
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    13
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    14
from reportlab.pdfgen.canvas import Canvas
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    15
from reportlab.platypus import Flowable
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    16
from reportlab.pdfbase import pdfmetrics, cidfonts
1679
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
    17
from reportlab.graphics.shapes import Drawing, Group, String, Circle, Rect
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
    18
from reportlab.graphics.widgetbase import Widget
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
    19
from reportlab.lib import colors
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
    20
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    21
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    22
class CodeChartBase(Flowable):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    23
    """Basic bits of drawing furniture used by
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    24
    single and multi-byte versions: ability to put letters
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    25
    into boxes."""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    26
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    27
    def calcLayout(self):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    28
        "Work out x and y positions for drawing"
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    29
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    30
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    31
        rows = self.codePoints * 1.0 / self.charsPerRow
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    32
        if rows == int(rows):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    33
            self.rows = int(rows)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    34
        else:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    35
            self.rows = int(rows) + 1
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    36
        # size allows for a gray column of labels
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    37
        self.width = self.boxSize * (1+self.charsPerRow)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    38
        self.height = self.boxSize * (1+self.rows)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    39
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    40
        #handy lists
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    41
        self.ylist = []
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    42
        for row in range(self.rows + 2):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    43
            self.ylist.append(row * self.boxSize)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    44
        self.xlist = []
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    45
        for col in range(self.charsPerRow + 2):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    46
            self.xlist.append(col * self.boxSize)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
    47
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    48
    def formatByte(self, byt):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    49
        if self.hex:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    50
            return '%02X' % byt
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    51
        else:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    52
            return '%d' % byt
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    53
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    54
    def drawChars(self, charList):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    55
        """Fills boxes in order.  None means skip a box.
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    56
        Empty boxes at end get filled with gray"""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    57
        extraNeeded = (self.rows * self.charsPerRow - len(charList))
2192
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
    58
        for i in range(extraNeeded):
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
    59
            charList.append(None)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
    60
        #charList.extend([None] * extraNeeded)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    61
        row = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    62
        col = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    63
        self.canv.setFont(self.fontName, self.boxSize * 0.75)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    64
        for ch in charList:  # may be 2 bytes or 1
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    65
            if ch is None:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    66
                self.canv.setFillGray(0.9)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    67
                self.canv.rect((1+col) * self.boxSize, (self.rows - row - 1) * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    68
                    self.boxSize, self.boxSize, stroke=0, fill=1)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    69
                self.canv.setFillGray(0.0)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    70
            else:
2337
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    71
                try:
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    72
                    self.canv.drawCentredString(
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    73
                            (col+1.5) * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    74
                            (self.rows - row - 0.875) * self.boxSize,
2337
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    75
                            ch,
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    76
                            )
2337
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    77
                except:
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    78
                    self.canv.setFillGray(0.9)
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    79
                    self.canv.rect((1+col) * self.boxSize, (self.rows - row - 1) * self.boxSize,
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    80
                        self.boxSize, self.boxSize, stroke=0, fill=1)
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    81
                    self.canv.drawCentredString(
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    82
                            (col+1.5) * self.boxSize,
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    83
                            (self.rows - row - 0.875) * self.boxSize,
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    84
                            '?',
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    85
                            )
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    86
                    self.canv.setFillGray(0.0)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    87
            col = col + 1
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    88
            if col == self.charsPerRow:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    89
                row = row + 1
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    90
                col = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    91
1362
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
    92
    def drawLabels(self, topLeft = ''):
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    93
        """Writes little labels in the top row and first column"""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    94
        self.canv.setFillGray(0.8)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    95
        self.canv.rect(0, self.ylist[-2], self.width, self.boxSize, fill=1, stroke=0)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    96
        self.canv.rect(0, 0, self.boxSize, self.ylist[-2], fill=1, stroke=0)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    97
        self.canv.setFillGray(0.0)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
    98
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    99
        #label each row and column
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   100
        self.canv.setFont('Helvetica-Oblique',0.375 * self.boxSize)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   101
        byt = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   102
        for row in range(self.rows):
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   103
            if self.rowLabels:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   104
                label = self.rowLabels[row]
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   105
            else: # format start bytes as hex or decimal
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   106
                label = self.formatByte(row * self.charsPerRow)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   107
            self.canv.drawCentredString(0.5 * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   108
                                        (self.rows - row - 0.75) * self.boxSize,
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   109
                                        label
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   110
                                        )
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   111
        for col in range(self.charsPerRow):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   112
            self.canv.drawCentredString((col + 1.5) * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   113
                                        (self.rows + 0.25) * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   114
                                        self.formatByte(col)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   115
                                        )
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   116
1362
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   117
        if topLeft:
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   118
            self.canv.setFont('Helvetica-BoldOblique',0.5 * self.boxSize)
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   119
            self.canv.drawCentredString(0.5 * self.boxSize,
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   120
                                        (self.rows + 0.25) * self.boxSize,
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   121
                                        topLeft
1362
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   122
                                        )
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   123
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   124
class SingleByteEncodingChart(CodeChartBase):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   125
    def __init__(self, faceName='Helvetica', encodingName='WinAnsiEncoding',
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   126
                 charsPerRow=16, boxSize=14, hex=1):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   127
        self.codePoints = 256
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   128
        self.faceName = faceName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   129
        self.encodingName = encodingName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   130
        self.fontName = self.faceName + '-' + self.encodingName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   131
        self.charsPerRow = charsPerRow
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   132
        self.boxSize = boxSize
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   133
        self.hex = hex
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   134
        self.rowLabels = None
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   135
        pdfmetrics.registerFont(pdfmetrics.Font(self.fontName,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   136
                                                self.faceName,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   137
                                                self.encodingName)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   138
                                )
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   139
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   140
        self.calcLayout()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   141
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   142
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   143
    def draw(self):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   144
        self.drawLabels()
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   145
        charList = [None] * 32 + map(chr, range(32, 256))
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   146
        self.drawChars(charList)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   147
        self.canv.grid(self.xlist, self.ylist)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   148
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   149
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   150
class KutenRowCodeChart(CodeChartBase):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   151
    """Formats one 'row' of the 94x94 space used in many Asian encodings.aliases
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   152
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   153
    These deliberately resemble the code charts in Ken Lunde's "Understanding
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   154
    CJKV Information Processing", to enable manual checking.  Due to the large
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   155
    numbers of characters, we don't try to make one graphic with 10,000 characters,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   156
    but rather output a sequence of these."""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   157
    #would be cleaner if both shared one base class whose job
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   158
    #was to draw the boxes, but never mind...
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   159
    def __init__(self, row, faceName, encodingName):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   160
        self.row = row
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   161
        self.codePoints = 94
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   162
        self.boxSize = 18
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   163
        self.charsPerRow = 20
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   164
        self.rows = 5
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   165
        self.rowLabels = ['00','20','40','60','80']
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   166
        self.hex = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   167
        self.faceName = faceName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   168
        self.encodingName = encodingName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   169
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   170
        try:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   171
            # the dependent files might not be available
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   172
            font = cidfonts.CIDFont(self.faceName, self.encodingName)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   173
            pdfmetrics.registerFont(font)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   174
        except:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   175
            # fall back to English and at least shwo we can draw the boxes
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   176
            self.faceName = 'Helvetica'
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   177
            self.encodingName = 'WinAnsiEncoding'
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   178
        self.fontName = self.faceName + '-' + self.encodingName
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   179
        self.calcLayout()
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   180
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   181
    def makeRow(self, row):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   182
        """Works out the character values for this kuten row"""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   183
        cells = []
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   184
        if string.find(self.encodingName, 'EUC') > -1:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   185
            # it is an EUC family encoding.
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   186
            for col in range(1, 95):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   187
                ch = chr(row + 160) + chr(col+160)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   188
                cells.append(ch)
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   189
##        elif string.find(self.encodingName, 'GB') > -1:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   190
##            # it is an EUC family encoding.
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   191
##            for col in range(1, 95):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   192
##                ch = chr(row + 160) + chr(col+160)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   193
        else:
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   194
            cells.append([None] * 94)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   195
        return cells
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   196
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   197
    def draw(self):
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   198
        self.drawLabels(topLeft= 'R%d' % self.row)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   199
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   200
        # work out which characters we need for the row
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   201
        #assert string.find(self.encodingName, 'EUC') > -1, 'Only handles EUC encoding today, you gave me %s!' % self.encodingName
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   202
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   203
        # pad out by 1 to match Ken Lunde's tables
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   204
        charList = [None] + self.makeRow(self.row)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   205
        self.drawChars(charList)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   206
        self.canv.grid(self.xlist, self.ylist)
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   207
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   208
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   209
class Big5CodeChart(CodeChartBase):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   210
    """Formats one 'row' of the 94x160 space used in Big 5
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   211
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   212
    These deliberately resemble the code charts in Ken Lunde's "Understanding
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   213
    CJKV Information Processing", to enable manual checking."""
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   214
    def __init__(self, row, faceName, encodingName):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   215
        self.row = row
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   216
        self.codePoints = 160
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   217
        self.boxSize = 18
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   218
        self.charsPerRow = 16
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   219
        self.rows = 10
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   220
        self.hex = 1
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   221
        self.faceName = faceName
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   222
        self.encodingName = encodingName
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   223
        self.rowLabels = ['4','5','6','7','A','B','C','D','E','F']
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   224
        try:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   225
            # the dependent files might not be available
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   226
            font = cidfonts.CIDFont(self.faceName, self.encodingName)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   227
            pdfmetrics.registerFont(font)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   228
        except:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   229
            # fall back to English and at least shwo we can draw the boxes
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   230
            self.faceName = 'Helvetica'
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   231
            self.encodingName = 'WinAnsiEncoding'
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   232
        self.fontName = self.faceName + '-' + self.encodingName
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   233
        self.calcLayout()
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   234
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   235
    def makeRow(self, row):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   236
        """Works out the character values for this Big5 row.
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   237
        Rows start at 0xA1"""
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   238
        cells = []
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   239
        if string.find(self.encodingName, 'B5') > -1:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   240
            # big 5, different row size
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   241
            for y in [4,5,6,7,10,11,12,13,14,15]:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   242
                for x in range(16):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   243
                    col = y*16+x
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   244
                    ch = chr(row) + chr(col)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   245
                    cells.append(ch)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   246
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   247
        else:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   248
            cells.append([None] * 160)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   249
        return cells
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   250
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   251
    def draw(self):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   252
        self.drawLabels(topLeft='%02X' % self.row)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   253
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   254
        charList = self.makeRow(self.row)
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   255
        self.drawChars(charList)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   256
        self.canv.grid(self.xlist, self.ylist)
1378
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   257
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   258
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   259
def hBoxText(msg, canvas, x, y, faceName, encName):
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   260
    """Helper for stringwidth tests on Asian fonts.
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   261
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   262
    Registers font if needed.  Then draws the string,
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   263
    and a box around it derived from the stringWidth function"""
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   264
    canvas.saveState()
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   265
    fontName = faceName + '-' + encName
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   266
    try:
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   267
        font = pdfmetrics.getFont(fontName)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   268
    except KeyError:
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   269
        font = cidfonts.CIDFont(faceName, encName)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   270
        pdfmetrics.registerFont(font)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   271
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   272
    canvas.setFillGray(0.8)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   273
    canvas.rect(x,y,pdfmetrics.stringWidth(msg, fontName, 16),16,stroke=0,fill=1)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   274
    canvas.setFillGray(0)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   275
    canvas.setFont(fontName, 16,16)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   276
    canvas.drawString(x,y,msg)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   277
    canvas.restoreState()
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   278
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   279
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   280
class CodeWidget(Widget):
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   281
    """Block showing all the characters"""
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   282
    def __init__(self):
1679
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   283
        self.x = 0
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   284
        self.y = 0
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   285
        self.width = 160
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   286
        self.height = 160
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   287
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   288
    def draw(self):
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   289
        dx = self.width / 16.0
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   290
        dy = self.height / 16.0
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   291
        g = Group()
1679
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   292
        g.add(Rect(self.x, self.y, self.width, self.height,
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   293
                   fillColor=None, strokeColor=colors.black))
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   294
        for x in range(16):
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   295
            for y in range(16):
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   296
                charValue = y * 16 + x
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   297
                if charValue > 32:
1679
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   298
                    s = String(self.x + x * dx,
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   299
                               self.y + (self.height - y*dy), chr(charValue))
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   300
                    g.add(s)
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   301
        return g
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   302
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   303
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   304
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   305
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   306
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   307
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   308
def test():
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   309
    c = Canvas('codecharts.pdf')
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   310
    c.setFont('Helvetica-Bold', 24)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   311
    c.drawString(72, 750, 'Testing code page charts')
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   312
    cc1 = SingleByteEncodingChart()
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   313
    cc1.drawOn(c, 72, 500)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   314
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   315
    cc2 = SingleByteEncodingChart(charsPerRow=32)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   316
    cc2.drawOn(c, 72, 300)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   317
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   318
    cc3 = SingleByteEncodingChart(charsPerRow=25, hex=0)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   319
    cc3.drawOn(c, 72, 100)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   320
2192
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   321
##    c.showPage()
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   322
##
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   323
##    c.setFont('Helvetica-Bold', 24)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   324
##    c.drawString(72, 750, 'Multi-byte Kuten code chart examples')
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   325
##    KutenRowCodeChart(1, 'HeiseiMin-W3','EUC-H').drawOn(c, 72, 600)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   326
##    KutenRowCodeChart(16, 'HeiseiMin-W3','EUC-H').drawOn(c, 72, 450)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   327
##    KutenRowCodeChart(84, 'HeiseiMin-W3','EUC-H').drawOn(c, 72, 300)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   328
##
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   329
##    c.showPage()
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   330
##    c.setFont('Helvetica-Bold', 24)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   331
##    c.drawString(72, 750, 'Big5 Code Chart Examples')
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   332
##    #Big5CodeChart(0xA1, 'MSungStd-Light-Acro','ETenms-B5-H').drawOn(c, 72, 500)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   333
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   334
    c.save()
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   335
    print 'saved codecharts.pdf'
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   336
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   337
if __name__=='__main__':
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   338
    test()
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   339
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   340