src/reportlab/lib/codecharts.py
branchpy33
changeset 3794 398ea04239b5
parent 3721 0c93dd8ff567
child 3796 c9a86549dee7
equal deleted inserted replaced
3793:cc3f9cc828f7 3794:398ea04239b5
     7 
     7 
     8 To be sure we can accurately represent characters in various encodings
     8 To be sure we can accurately represent characters in various encodings
     9 and fonts, we need some routines to display all those characters.
     9 and fonts, we need some routines to display all those characters.
    10 These are defined herein.  The idea is to include flowable, drawable
    10 These are defined herein.  The idea is to include flowable, drawable
    11 and graphic objects for single and multi-byte fonts. """
    11 and graphic objects for single and multi-byte fonts. """
    12 import string
       
    13 import codecs
    12 import codecs
    14 
    13 
    15 from reportlab.pdfgen.canvas import Canvas
    14 from reportlab.pdfgen.canvas import Canvas
    16 from reportlab.platypus import Flowable
    15 from reportlab.platypus import Flowable
    17 from reportlab.pdfbase import pdfmetrics, cidfonts
    16 from reportlab.pdfbase import pdfmetrics, cidfonts
   205         self.calcLayout()
   204         self.calcLayout()
   206 
   205 
   207     def makeRow(self, row):
   206     def makeRow(self, row):
   208         """Works out the character values for this kuten row"""
   207         """Works out the character values for this kuten row"""
   209         cells = []
   208         cells = []
   210         if string.find(self.encodingName, 'EUC') > -1:
   209         if self.encodingName.find('EUC') > -1:
   211             # it is an EUC family encoding.
   210             # it is an EUC family encoding.
   212             for col in range(1, 95):
   211             for col in range(1, 95):
   213                 ch = chr(row + 160) + chr(col+160)
   212                 ch = chr(row + 160) + chr(col+160)
   214                 cells.append(ch)
   213                 cells.append(ch)
   215 ##        elif string.find(self.encodingName, 'GB') > -1:
   214 ##        elif self.encodingName.find('GB') > -1:
   216 ##            # it is an EUC family encoding.
   215 ##            # it is an EUC family encoding.
   217 ##            for col in range(1, 95):
   216 ##            for col in range(1, 95):
   218 ##                ch = chr(row + 160) + chr(col+160)
   217 ##                ch = chr(row + 160) + chr(col+160)
   219         else:
   218         else:
   220             cells.append([None] * 94)
   219             cells.append([None] * 94)
   222 
   221 
   223     def draw(self):
   222     def draw(self):
   224         self.drawLabels(topLeft= 'R%d' % self.row)
   223         self.drawLabels(topLeft= 'R%d' % self.row)
   225 
   224 
   226         # work out which characters we need for the row
   225         # work out which characters we need for the row
   227         #assert string.find(self.encodingName, 'EUC') > -1, 'Only handles EUC encoding today, you gave me %s!' % self.encodingName
   226         #assert self.encodingName.find('EUC') > -1, 'Only handles EUC encoding today, you gave me %s!' % self.encodingName
   228 
   227 
   229         # pad out by 1 to match Ken Lunde's tables
   228         # pad out by 1 to match Ken Lunde's tables
   230         charList = [None] + self.makeRow(self.row)
   229         charList = [None] + self.makeRow(self.row)
   231         self.drawChars(charList)
   230         self.drawChars(charList)
   232         self.canv.grid(self.xlist, self.ylist)
   231         self.canv.grid(self.xlist, self.ylist)
   260 
   259 
   261     def makeRow(self, row):
   260     def makeRow(self, row):
   262         """Works out the character values for this Big5 row.
   261         """Works out the character values for this Big5 row.
   263         Rows start at 0xA1"""
   262         Rows start at 0xA1"""
   264         cells = []
   263         cells = []
   265         if string.find(self.encodingName, 'B5') > -1:
   264         if self.encodingName.find('B5') > -1:
   266             # big 5, different row size
   265             # big 5, different row size
   267             for y in [4,5,6,7,10,11,12,13,14,15]:
   266             for y in [4,5,6,7,10,11,12,13,14,15]:
   268                 for x in range(16):
   267                 for x in range(16):
   269                     col = y*16+x
   268                     col = y*16+x
   270                     ch = chr(row) + chr(col)
   269                     ch = chr(row) + chr(col)