src/reportlab/lib/codecharts.py
branchpy33
changeset 3796 c9a86549dee7
parent 3794 398ea04239b5
child 3970 28e73decd79f
equal deleted inserted replaced
3795:2a6c4b74219f 3796:c9a86549dee7
    15 from reportlab.platypus import Flowable
    15 from reportlab.platypus import Flowable
    16 from reportlab.pdfbase import pdfmetrics, cidfonts
    16 from reportlab.pdfbase import pdfmetrics, cidfonts
    17 from reportlab.graphics.shapes import Drawing, Group, String, Circle, Rect
    17 from reportlab.graphics.shapes import Drawing, Group, String, Circle, Rect
    18 from reportlab.graphics.widgetbase import Widget
    18 from reportlab.graphics.widgetbase import Widget
    19 from reportlab.lib import colors
    19 from reportlab.lib import colors
       
    20 from reportlab.lib.utils import int2byte
    20 
    21 
    21 adobe2codec = {
    22 adobe2codec = {
    22     'WinAnsiEncoding':'winansi',
    23     'WinAnsiEncoding':'winansi',
    23     'MacRomanEncoding':'macroman',
    24     'MacRomanEncoding':'macroman',
    24     'MacExpert':'macexpert',
    25     'MacExpert':'macexpert',
   147         self.calcLayout()
   148         self.calcLayout()
   148 
   149 
   149 
   150 
   150     def draw(self):
   151     def draw(self):
   151         self.drawLabels()
   152         self.drawLabels()
   152         charList = [None] * 32 + list(map(chr, list(range(32, 256))))
   153         charList = [None] * 32 + list(map(int2byte, list(range(32, 256))))
   153 
   154 
   154         #we need to convert these to Unicode, since ReportLab
   155         #we need to convert these to Unicode, since ReportLab
   155         #2.0 can only draw in Unicode.
   156         #2.0 can only draw in Unicode.
   156 
   157 
   157         encName = self.encodingName
   158         encName = self.encodingName
   207         """Works out the character values for this kuten row"""
   208         """Works out the character values for this kuten row"""
   208         cells = []
   209         cells = []
   209         if self.encodingName.find('EUC') > -1:
   210         if self.encodingName.find('EUC') > -1:
   210             # it is an EUC family encoding.
   211             # it is an EUC family encoding.
   211             for col in range(1, 95):
   212             for col in range(1, 95):
   212                 ch = chr(row + 160) + chr(col+160)
   213                 ch = int2byte(row + 160) + int2byte(col+160)
   213                 cells.append(ch)
   214                 cells.append(ch)
   214 ##        elif self.encodingName.find('GB') > -1:
   215 ##        elif self.encodingName.find('GB') > -1:
   215 ##            # it is an EUC family encoding.
   216 ##            # it is an EUC family encoding.
   216 ##            for col in range(1, 95):
   217 ##            for col in range(1, 95):
   217 ##                ch = chr(row + 160) + chr(col+160)
   218 ##                ch = int2byte(row + 160) + int2byte(col+160)
   218         else:
   219         else:
   219             cells.append([None] * 94)
   220             cells.append([None] * 94)
   220         return cells
   221         return cells
   221 
   222 
   222     def draw(self):
   223     def draw(self):
   264         if self.encodingName.find('B5') > -1:
   265         if self.encodingName.find('B5') > -1:
   265             # big 5, different row size
   266             # big 5, different row size
   266             for y in [4,5,6,7,10,11,12,13,14,15]:
   267             for y in [4,5,6,7,10,11,12,13,14,15]:
   267                 for x in range(16):
   268                 for x in range(16):
   268                     col = y*16+x
   269                     col = y*16+x
   269                     ch = chr(row) + chr(col)
   270                     ch = int2byte(row) + int2byte(col)
   270                     cells.append(ch)
   271                     cells.append(ch)
   271 
   272 
   272         else:
   273         else:
   273             cells.append([None] * 160)
   274             cells.append([None] * 160)
   274         return cells
   275         return cells
   318         for x in range(16):
   319         for x in range(16):
   319             for y in range(16):
   320             for y in range(16):
   320                 charValue = y * 16 + x
   321                 charValue = y * 16 + x
   321                 if charValue > 32:
   322                 if charValue > 32:
   322                     s = String(self.x + x * dx,
   323                     s = String(self.x + x * dx,
   323                                self.y + (self.height - y*dy), chr(charValue))
   324                                self.y + (self.height - y*dy), int2byte(charValue))
   324                     g.add(s)
   325                     g.add(s)
   325         return g
   326         return g
   326 
   327 
   327 
   328 
   328 
   329 
   358     c.save()
   359     c.save()
   359     print('saved codecharts.pdf')
   360     print('saved codecharts.pdf')
   360 
   361 
   361 if __name__=='__main__':
   362 if __name__=='__main__':
   362     test()
   363     test()
   363 
       
   364