src/reportlab/lib/codecharts.py
author rptlab
Tue, 30 Apr 2013 14:28:14 +0100
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3794 398ea04239b5
permissions -rw-r--r--
second stage of port to Python 3.3; working hello world
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3617
ae5744e97c42 reportlab: copyright date changes
robin
parents: 3029
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2012
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 '''
3029
eded59f94021 adding docstrings to lib
andy
parents: 2964
diff changeset
     6
__doc__="""Routines to print code page (character set) drawings. Predates unicode.
1361
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
2619
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
    13
import codecs
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    14
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    15
from reportlab.pdfgen.canvas import Canvas
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    16
from reportlab.platypus import Flowable
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    17
from reportlab.pdfbase import pdfmetrics, cidfonts
1679
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
    18
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
    19
from reportlab.graphics.widgetbase import Widget
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
    20
from reportlab.lib import colors
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
    21
2619
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
    22
adobe2codec = {
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
    23
    'WinAnsiEncoding':'winansi',
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
    24
    'MacRomanEncoding':'macroman',
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
    25
    'MacExpert':'macexpert',
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
    26
    'PDFDoc':'pdfdoc',
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
    27
    
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
    28
    }
1361
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
class CodeChartBase(Flowable):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    31
    """Basic bits of drawing furniture used by
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    32
    single and multi-byte versions: ability to put letters
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    33
    into boxes."""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    34
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    35
    def calcLayout(self):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    36
        "Work out x and y positions for drawing"
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    37
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    38
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    39
        rows = self.codePoints * 1.0 / self.charsPerRow
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    40
        if rows == int(rows):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    41
            self.rows = int(rows)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    42
        else:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    43
            self.rows = int(rows) + 1
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    44
        # size allows for a gray column of labels
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    45
        self.width = self.boxSize * (1+self.charsPerRow)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    46
        self.height = self.boxSize * (1+self.rows)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    47
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    48
        #handy lists
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    49
        self.ylist = []
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    50
        for row in range(self.rows + 2):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    51
            self.ylist.append(row * self.boxSize)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    52
        self.xlist = []
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    53
        for col in range(self.charsPerRow + 2):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    54
            self.xlist.append(col * self.boxSize)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
    55
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    56
    def formatByte(self, byt):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    57
        if self.hex:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    58
            return '%02X' % byt
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    59
        else:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    60
            return '%d' % byt
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    61
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    62
    def drawChars(self, charList):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    63
        """Fills boxes in order.  None means skip a box.
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    64
        Empty boxes at end get filled with gray"""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    65
        extraNeeded = (self.rows * self.charsPerRow - len(charList))
2192
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
    66
        for i in range(extraNeeded):
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
    67
            charList.append(None)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
    68
        #charList.extend([None] * extraNeeded)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    69
        row = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    70
        col = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    71
        self.canv.setFont(self.fontName, self.boxSize * 0.75)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    72
        for ch in charList:  # may be 2 bytes or 1
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    73
            if ch is None:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    74
                self.canv.setFillGray(0.9)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    75
                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
    76
                    self.boxSize, self.boxSize, stroke=0, fill=1)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    77
                self.canv.setFillGray(0.0)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    78
            else:
2337
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    79
                try:
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    80
                    self.canv.drawCentredString(
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    81
                            (col+1.5) * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    82
                            (self.rows - row - 0.875) * self.boxSize,
2337
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    83
                            ch,
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    84
                            )
2337
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    85
                except:
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    86
                    self.canv.setFillGray(0.9)
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    87
                    self.canv.rect((1+col) * self.boxSize, (self.rows - row - 1) * self.boxSize,
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    88
                        self.boxSize, self.boxSize, stroke=0, fill=1)
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    89
                    self.canv.drawCentredString(
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    90
                            (col+1.5) * self.boxSize,
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    91
                            (self.rows - row - 0.875) * self.boxSize,
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    92
                            '?',
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    93
                            )
0f4b0154b382 Fix for unicode difficulties
rgbecker
parents: 2332
diff changeset
    94
                    self.canv.setFillGray(0.0)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    95
            col = col + 1
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    96
            if col == self.charsPerRow:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    97
                row = row + 1
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    98
                col = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
    99
1362
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   100
    def drawLabels(self, topLeft = ''):
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   101
        """Writes little labels in the top row and first column"""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   102
        self.canv.setFillGray(0.8)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   103
        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
   104
        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
   105
        self.canv.setFillGray(0.0)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   106
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   107
        #label each row and column
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   108
        self.canv.setFont('Helvetica-Oblique',0.375 * self.boxSize)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   109
        byt = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   110
        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
   111
            if self.rowLabels:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   112
                label = self.rowLabels[row]
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   113
            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
   114
                label = self.formatByte(row * self.charsPerRow)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   115
            self.canv.drawCentredString(0.5 * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   116
                                        (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
   117
                                        label
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   118
                                        )
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   119
        for col in range(self.charsPerRow):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   120
            self.canv.drawCentredString((col + 1.5) * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   121
                                        (self.rows + 0.25) * self.boxSize,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   122
                                        self.formatByte(col)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   123
                                        )
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   124
1362
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   125
        if topLeft:
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   126
            self.canv.setFont('Helvetica-BoldOblique',0.5 * self.boxSize)
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   127
            self.canv.drawCentredString(0.5 * self.boxSize,
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   128
                                        (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
   129
                                        topLeft
1362
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   130
                                        )
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   131
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   132
class SingleByteEncodingChart(CodeChartBase):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   133
    def __init__(self, faceName='Helvetica', encodingName='WinAnsiEncoding',
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   134
                 charsPerRow=16, boxSize=14, hex=1):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   135
        self.codePoints = 256
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   136
        self.faceName = faceName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   137
        self.encodingName = encodingName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   138
        self.fontName = self.faceName + '-' + self.encodingName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   139
        self.charsPerRow = charsPerRow
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   140
        self.boxSize = boxSize
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   141
        self.hex = hex
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   142
        self.rowLabels = None
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   143
        pdfmetrics.registerFont(pdfmetrics.Font(self.fontName,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   144
                                                self.faceName,
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   145
                                                self.encodingName)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   146
                                )
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   147
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   148
        self.calcLayout()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   149
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   150
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   151
    def draw(self):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   152
        self.drawLabels()
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   153
        charList = [None] * 32 + list(map(chr, list(range(32, 256))))
2619
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   154
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   155
        #we need to convert these to Unicode, since ReportLab
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   156
        #2.0 can only draw in Unicode.
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   157
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   158
        encName = self.encodingName
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   159
        #apply some common translations
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   160
        encName = adobe2codec.get(encName, encName)
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   161
        decoder = codecs.lookup(encName)[1]
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   162
        def decodeFunc(txt):
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   163
            if txt is None:
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   164
                return None
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   165
            else:
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   166
                return decoder(txt, errors='replace')[0]
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   167
            
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   168
        charList = [decodeFunc(ch) for ch in charList]
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   169
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   170
95e4977ac148 updated codecharts and ch3 of user guide
andy
parents: 2337
diff changeset
   171
        
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   172
        self.drawChars(charList)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   173
        self.canv.grid(self.xlist, self.ylist)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   174
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   175
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   176
class KutenRowCodeChart(CodeChartBase):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   177
    """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
   178
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   179
    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
   180
    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
   181
    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
   182
    but rather output a sequence of these."""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   183
    #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
   184
    #was to draw the boxes, but never mind...
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   185
    def __init__(self, row, faceName, encodingName):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   186
        self.row = row
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   187
        self.codePoints = 94
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   188
        self.boxSize = 18
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   189
        self.charsPerRow = 20
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   190
        self.rows = 5
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   191
        self.rowLabels = ['00','20','40','60','80']
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   192
        self.hex = 0
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   193
        self.faceName = faceName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   194
        self.encodingName = encodingName
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   195
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   196
        try:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   197
            # the dependent files might not be available
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   198
            font = cidfonts.CIDFont(self.faceName, self.encodingName)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   199
            pdfmetrics.registerFont(font)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   200
        except:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   201
            # 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
   202
            self.faceName = 'Helvetica'
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   203
            self.encodingName = 'WinAnsiEncoding'
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   204
        self.fontName = self.faceName + '-' + self.encodingName
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   205
        self.calcLayout()
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   206
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   207
    def makeRow(self, row):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   208
        """Works out the character values for this kuten row"""
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   209
        cells = []
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   210
        if string.find(self.encodingName, 'EUC') > -1:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   211
            # it is an EUC family encoding.
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   212
            for col in range(1, 95):
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   213
                ch = chr(row + 160) + chr(col+160)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   214
                cells.append(ch)
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   215
##        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
   216
##            # it is an EUC family encoding.
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   217
##            for col in range(1, 95):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   218
##                ch = chr(row + 160) + chr(col+160)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   219
        else:
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   220
            cells.append([None] * 94)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   221
        return cells
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   222
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   223
    def draw(self):
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   224
        self.drawLabels(topLeft= 'R%d' % self.row)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   225
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   226
        # 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
   227
        #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
   228
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   229
        # pad out by 1 to match Ken Lunde's tables
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   230
        charList = [None] + self.makeRow(self.row)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   231
        self.drawChars(charList)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   232
        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
   233
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
class Big5CodeChart(CodeChartBase):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   236
    """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
   237
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   238
    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
   239
    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
   240
    def __init__(self, row, faceName, encodingName):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   241
        self.row = row
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   242
        self.codePoints = 160
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   243
        self.boxSize = 18
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   244
        self.charsPerRow = 16
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   245
        self.rows = 10
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   246
        self.hex = 1
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   247
        self.faceName = faceName
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   248
        self.encodingName = encodingName
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   249
        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
   250
        try:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   251
            # 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
   252
            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
   253
            pdfmetrics.registerFont(font)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   254
        except:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   255
            # 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
   256
            self.faceName = 'Helvetica'
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   257
            self.encodingName = 'WinAnsiEncoding'
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   258
        self.fontName = self.faceName + '-' + self.encodingName
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   259
        self.calcLayout()
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   260
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   261
    def makeRow(self, row):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   262
        """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
   263
        Rows start at 0xA1"""
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   264
        cells = []
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   265
        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
   266
            # big 5, different row size
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   267
            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
   268
                for x in range(16):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   269
                    col = y*16+x
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   270
                    ch = chr(row) + chr(col)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   271
                    cells.append(ch)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   272
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   273
        else:
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   274
            cells.append([None] * 160)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   275
        return cells
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   276
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   277
    def draw(self):
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   278
        self.drawLabels(topLeft='%02X' % self.row)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   279
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   280
        charList = self.makeRow(self.row)
1363
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   281
        self.drawChars(charList)
92e3fb40a784 Asian fonts now all working in major encodings, and partly documented
andy_robinson
parents: 1362
diff changeset
   282
        self.canv.grid(self.xlist, self.ylist)
1378
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   283
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   284
2630
11bd38826d14 partial silencing of cmap tests
andy
parents: 2619
diff changeset
   285
def hBoxText(msg, canvas, x, y, fontName):
1378
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   286
    """Helper for stringwidth tests on Asian fonts.
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   287
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   288
    Registers font if needed.  Then draws the string,
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   289
    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
   290
    canvas.saveState()
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   291
    try:
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   292
        font = pdfmetrics.getFont(fontName)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   293
    except KeyError:
2630
11bd38826d14 partial silencing of cmap tests
andy
parents: 2619
diff changeset
   294
        font = cidfonts.UnicodeCIDFont(fontName)
1378
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   295
        pdfmetrics.registerFont(font)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   296
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   297
    canvas.setFillGray(0.8)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   298
    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
   299
    canvas.setFillGray(0)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   300
    canvas.setFont(fontName, 16,16)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   301
    canvas.drawString(x,y,msg)
796ce78d458a Fixed font registry entries, tidied up stringWidth tests
andy_robinson
parents: 1363
diff changeset
   302
    canvas.restoreState()
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
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   305
class CodeWidget(Widget):
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   306
    """Block showing all the characters"""
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   307
    def __init__(self):
1679
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   308
        self.x = 0
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   309
        self.y = 0
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   310
        self.width = 160
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   311
        self.height = 160
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   312
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   313
    def draw(self):
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   314
        dx = self.width / 16.0
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   315
        dy = self.height / 16.0
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   316
        g = Group()
1679
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   317
        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
   318
                   fillColor=None, strokeColor=colors.black))
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   319
        for x in range(16):
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   320
            for y in range(16):
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   321
                charValue = y * 16 + x
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   322
                if charValue > 32:
1679
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   323
                    s = String(self.x + x * dx,
e77be1edcd61 Fixed page stream filter order (Thanks Bernhard)
andy_robinson
parents: 1675
diff changeset
   324
                               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
   325
                    g.add(s)
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   326
        return g
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   327
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   328
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   329
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   330
1675
92d3b3c2397d Fixed standard fonts demo, added a basic code page graphic
andy_robinson
parents: 1378
diff changeset
   331
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   332
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   333
def test():
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   334
    c = Canvas('codecharts.pdf')
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   335
    c.setFont('Helvetica-Bold', 24)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   336
    c.drawString(72, 750, 'Testing code page charts')
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   337
    cc1 = SingleByteEncodingChart()
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   338
    cc1.drawOn(c, 72, 500)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   339
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   340
    cc2 = SingleByteEncodingChart(charsPerRow=32)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   341
    cc2.drawOn(c, 72, 300)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   342
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   343
    cc3 = SingleByteEncodingChart(charsPerRow=25, hex=0)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   344
    cc3.drawOn(c, 72, 100)
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   345
2192
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   346
##    c.showPage()
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   347
##
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   348
##    c.setFont('Helvetica-Bold', 24)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   349
##    c.drawString(72, 750, 'Multi-byte Kuten code chart examples')
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   350
##    KutenRowCodeChart(1, 'HeiseiMin-W3','EUC-H').drawOn(c, 72, 600)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   351
##    KutenRowCodeChart(16, 'HeiseiMin-W3','EUC-H').drawOn(c, 72, 450)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   352
##    KutenRowCodeChart(84, 'HeiseiMin-W3','EUC-H').drawOn(c, 72, 300)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   353
##
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   354
##    c.showPage()
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   355
##    c.setFont('Helvetica-Bold', 24)
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   356
##    c.drawString(72, 750, 'Big5 Code Chart Examples')
955d4bf3b9d2 Candidate fix for infinite looping
andy_robinson
parents: 1683
diff changeset
   357
##    #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
   358
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   359
    c.save()
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   360
    print('saved codecharts.pdf')
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   362
if __name__=='__main__':
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   363
    test()
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents:
diff changeset
   364
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1679
diff changeset
   365