src/reportlab/pdfbase/cidfonts.py
author rptlab
Tue, 30 Apr 2013 14:28:14 +0100
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3781 df8b57380768
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: 3376
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2012
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2261
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/pdfbase/cidfonts.py
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
     4
#$Header $
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2261
diff changeset
     5
__version__=''' $Id$ '''
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
     6
__doc__="""CID (Asian multi-byte) font support.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
     7
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
     8
This defines classes to represent CID fonts.  They know how to calculate
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
     9
their own width and how to write themselves into PDF files."""
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    10
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    11
import os
1192
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    12
from types import ListType, TupleType, DictType
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    13
from string import find, split, strip
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
    14
import marshal
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
    15
import time
2993
033cbff23cb6 reportlab: fixes discovered during 2.6 testing
rgbecker
parents: 2964
diff changeset
    16
try:
033cbff23cb6 reportlab: fixes discovered during 2.6 testing
rgbecker
parents: 2964
diff changeset
    17
    from hashlib import md5
033cbff23cb6 reportlab: fixes discovered during 2.6 testing
rgbecker
parents: 2964
diff changeset
    18
except ImportError:
033cbff23cb6 reportlab: fixes discovered during 2.6 testing
rgbecker
parents: 2964
diff changeset
    19
    from md5 import md5
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    20
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents: 1286
diff changeset
    21
import reportlab
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    22
from reportlab.pdfbase import pdfmetrics
2629
3f42be5bfbfc added canned width data for CID fonts
andy
parents: 2575
diff changeset
    23
from reportlab.pdfbase._cidfontdata import allowedTypeFaces, allowedEncodings, CIDFontInfo, \
3f42be5bfbfc added canned width data for CID fonts
andy
parents: 2575
diff changeset
    24
     defaultUnicodeEncodings, widthsByUnichar
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    25
from reportlab.pdfgen.canvas import Canvas
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    26
from reportlab.pdfbase import pdfdoc
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
    27
from reportlab.pdfbase.pdfutils import _escape
1193
7f89709f35da CMap Search Path now in config
andy_robinson
parents: 1192
diff changeset
    28
from reportlab.rl_config import CMapSearchPath
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    29
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    30
2633
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    31
#quick hackery for 2.0 release.  Now we always do unicode, and have built in
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    32
#the CMAP data, any code to load CMap files is not needed.
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    33
DISABLE_CMAP = True
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    34
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    35
1219
9c6ed345ce82 Test suite fixups
andy_robinson
parents: 1193
diff changeset
    36
def findCMapFile(name):
9c6ed345ce82 Test suite fixups
andy_robinson
parents: 1193
diff changeset
    37
    "Returns full filename, or raises error"
9c6ed345ce82 Test suite fixups
andy_robinson
parents: 1193
diff changeset
    38
    for dirname in CMapSearchPath:
9c6ed345ce82 Test suite fixups
andy_robinson
parents: 1193
diff changeset
    39
        cmapfile = dirname + os.sep + name
9c6ed345ce82 Test suite fixups
andy_robinson
parents: 1193
diff changeset
    40
        if os.path.isfile(cmapfile):
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
    41
            #print "found", cmapfile
1219
9c6ed345ce82 Test suite fixups
andy_robinson
parents: 1193
diff changeset
    42
            return cmapfile
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    43
    raise IOError('CMAP file for encodings "%s" not found!' % name)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
    44
1192
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    45
def structToPDF(structure):
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    46
    "Converts deeply nested structure to PDFdoc dictionary/array objects"
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    47
    if type(structure) is DictType:
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    48
        newDict = {}
3723
99aa837b6703 second stage of port to Python 3.3; working hello world
rptlab
parents: 3721
diff changeset
    49
        for k, v in structure.items():
1192
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    50
            newDict[k] = structToPDF(v)
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    51
        return pdfdoc.PDFDictionary(newDict)
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    52
    elif type(structure) in (ListType, TupleType):
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    53
        newList = []
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    54
        for elem in structure:
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    55
            newList.append(structToPDF(elem))
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    56
        return pdfdoc.PDFArray(newList)
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    57
    else:
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    58
        return structure
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
    59
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    60
class CIDEncoding(pdfmetrics.Encoding):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    61
    """Multi-byte encoding.  These are loaded from CMAP files.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    62
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    63
    A CMAP file is like a mini-codec.  It defines the correspondence
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    64
    between code points in the (multi-byte) input data and Character
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    65
    IDs. """
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    66
    # aims to do similar things to Brian Hooper's CMap class,
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    67
    # but I could not get it working and had to rewrite.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    68
    # also, we should really rearrange our current encoding
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    69
    # into a SingleByteEncoding since many of its methods
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    70
    # should not apply here.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    71
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents: 1286
diff changeset
    72
    def __init__(self, name, useCache=1):
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
    73
        self.name = name
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
    74
        self._mapFileHash = None
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    75
        self._codeSpaceRanges = []
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    76
        self._notDefRanges = []
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    77
        self._cmap = {}
1362
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
    78
        self.source = None
2633
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    79
        if not DISABLE_CMAP:
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    80
            if useCache:
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    81
                from reportlab.lib.utils import get_rl_tempdir
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    82
                fontmapdir = get_rl_tempdir('FastCMAPS')
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    83
                if os.path.isfile(fontmapdir + os.sep + name + '.fastmap'):
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    84
                    self.fastLoad(fontmapdir)
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    85
                    self.source = fontmapdir + os.sep + name + '.fastmap'
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    86
                else:
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    87
                    self.parseCMAPFile(name)
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    88
                    self.source = 'CMAP: ' + name
9877f90e0ad9 disable loading of CMAPS
andy
parents: 2629
diff changeset
    89
                    self.fastSave(fontmapdir)
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents: 1286
diff changeset
    90
            else:
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents: 1286
diff changeset
    91
                self.parseCMAPFile(name)
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    92
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
    93
    def _hash(self, text):
2993
033cbff23cb6 reportlab: fixes discovered during 2.6 testing
rgbecker
parents: 2964
diff changeset
    94
        hasher = md5()
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
    95
        hasher.update(text)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
    96
        return hasher.digest()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
    97
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    98
    def parseCMAPFile(self, name):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
    99
        """This is a tricky one as CMAP files are Postscript
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   100
        ones.  Some refer to others with a 'usecmap'
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   101
        command"""
2565
c71534d975ff reportlab: remove cidfonts print, fix get_rl_tempdir
rgbecker
parents: 2332
diff changeset
   102
        #started = time.clock()
1219
9c6ed345ce82 Test suite fixups
andy_robinson
parents: 1193
diff changeset
   103
        cmapfile = findCMapFile(name)
1264
79862e6e40a1 Mostly correct string widths implemented for Asian fonts.
andy_robinson
parents: 1219
diff changeset
   104
        # this will CRAWL with the unicode encodings...
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   105
        rawdata = open(cmapfile, 'r').read()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   106
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   107
        self._mapFileHash = self._hash(rawdata)
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   108
        #if it contains the token 'usecmap', parse the other
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   109
        #cmap file first....
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   110
        usecmap_pos = find(rawdata, 'usecmap')
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   111
        if  usecmap_pos > -1:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   112
            #they tell us to look in another file
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   113
            #for the code space ranges. The one
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   114
            # to use will be the previous word.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   115
            chunk = rawdata[0:usecmap_pos]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   116
            words = split(chunk)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   117
            otherCMAPName = words[-1]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   118
            #print 'referred to another CMAP %s' % otherCMAPName
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   119
            self.parseCMAPFile(otherCMAPName)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   120
            # now continue parsing this, as it may
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   121
            # override some settings
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   122
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   123
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   124
        words = split(rawdata)
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3031
diff changeset
   125
        while words != []:
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   126
            if words[0] == 'begincodespacerange':
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   127
                words = words[1:]
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3031
diff changeset
   128
                while words[0] != 'endcodespacerange':
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   129
                    strStart, strEnd, words = words[0], words[1], words[2:]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   130
                    start = int(strStart[1:-1], 16)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   131
                    end = int(strEnd[1:-1], 16)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   132
                    self._codeSpaceRanges.append((start, end),)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   133
            elif words[0] == 'beginnotdefrange':
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   134
                words = words[1:]
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3031
diff changeset
   135
                while words[0] != 'endnotdefrange':
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   136
                    strStart, strEnd, strValue = words[0:3]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   137
                    start = int(strStart[1:-1], 16)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   138
                    end = int(strEnd[1:-1], 16)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   139
                    value = int(strValue)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   140
                    self._notDefRanges.append((start, end, value),)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   141
                    words = words[3:]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   142
            elif words[0] == 'begincidrange':
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   143
                words = words[1:]
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3031
diff changeset
   144
                while words[0] != 'endcidrange':
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   145
                    strStart, strEnd, strValue = words[0:3]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   146
                    start = int(strStart[1:-1], 16)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   147
                    end = int(strEnd[1:-1], 16)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   148
                    value = int(strValue)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   149
                    # this means that 'start' corresponds to 'value',
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   150
                    # start+1 corresponds to value+1 and so on up
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   151
                    # to end
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   152
                    offset = 0
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   153
                    while start + offset <= end:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   154
                        self._cmap[start + offset] = value + offset
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   155
                        offset = offset + 1
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   156
                    words = words[3:]
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   157
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   158
            else:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   159
                words = words[1:]
2565
c71534d975ff reportlab: remove cidfonts print, fix get_rl_tempdir
rgbecker
parents: 2332
diff changeset
   160
        #finished = time.clock()
c71534d975ff reportlab: remove cidfonts print, fix get_rl_tempdir
rgbecker
parents: 2332
diff changeset
   161
        #print 'parsed CMAP %s in %0.4f seconds' % (self.name, finished - started)
1286
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   162
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   163
    def translate(self, text):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   164
        "Convert a string into a list of CIDs"
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   165
        output = []
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   166
        cmap = self._cmap
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   167
        lastChar = ''
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   168
        for char in text:
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3031
diff changeset
   169
            if lastChar != '':
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   170
                #print 'convert character pair "%s"' % (lastChar + char)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   171
                num = ord(lastChar) * 256 + ord(char)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   172
            else:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   173
                #print 'convert character "%s"' % char
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   174
                num = ord(char)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   175
            lastChar = char
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   176
            found = 0
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   177
            for low, high in self._codeSpaceRanges:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   178
                if low < num < high:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   179
                    try:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   180
                        cid = cmap[num]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   181
                        #print '%d -> %d' % (num, cid)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   182
                    except KeyError:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   183
                        #not defined.  Try to find the appropriate
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   184
                        # notdef character, or failing that return
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   185
                        # zero
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   186
                        cid = 0
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   187
                        for low2, high2, notdef in self._notDefRanges:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   188
                            if low2 < num < high2:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   189
                                cid = notdef
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   190
                                break
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   191
                    output.append(cid)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   192
                    found = 1
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   193
                    break
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   194
            if found:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   195
                lastChar = ''
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   196
            else:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   197
                lastChar = char
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   198
        return output
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   199
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   200
    def fastSave(self, directory):
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   201
        f = open(os.path.join(directory, self.name + '.fastmap'), 'wb')
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   202
        marshal.dump(self._mapFileHash, f)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   203
        marshal.dump(self._codeSpaceRanges, f)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   204
        marshal.dump(self._notDefRanges, f)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   205
        marshal.dump(self._cmap, f)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   206
        f.close()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   207
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   208
    def fastLoad(self, directory):
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   209
        started = time.clock()
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   210
        f = open(os.path.join(directory, self.name + '.fastmap'), 'rb')
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   211
        self._mapFileHash = marshal.load(f)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   212
        self._codeSpaceRanges = marshal.load(f)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   213
        self._notDefRanges = marshal.load(f)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   214
        self._cmap = marshal.load(f)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   215
        f.close()
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   216
        finished = time.clock()
1361
35586d769319 Enhancements/fixes to Asian fonts; codecharts utility to
andy_robinson
parents: 1286
diff changeset
   217
        #print 'loaded %s in %0.4f seconds' % (self.name, finished - started)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   218
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   219
    def getData(self):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   220
        """Simple persistence helper.  Return a dict with all that matters."""
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   221
        return {
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   222
            'mapFileHash': self._mapFileHash,
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   223
            'codeSpaceRanges': self._codeSpaceRanges,
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   224
            'notDefRanges': self._notDefRanges,
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   225
            'cmap': self._cmap,
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   226
            }
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   227
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   228
class CIDTypeFace(pdfmetrics.TypeFace):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   229
    """Multi-byte type face.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   230
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   231
    Conceptually similar to a single byte typeface,
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   232
    but the glyphs are identified by a numeric Character
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   233
    ID (CID) and not a glyph name. """
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   234
    def __init__(self, name):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   235
        """Initialised from one of the canned dictionaries in allowedEncodings
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   236
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   237
        Or rather, it will be shortly..."""
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   238
        pdfmetrics.TypeFace.__init__(self, name)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   239
        self._extractDictInfo(name)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   240
    def _extractDictInfo(self, name):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   241
        try:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   242
            fontDict = CIDFontInfo[name]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   243
        except KeyError:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   244
            raise KeyError("Unable to find information on CID typeface '%s'" % name +
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   245
                            "Only the following font names work:" + repr(allowedTypeFaces))
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   246
        descFont = fontDict['DescendantFonts'][0]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   247
        self.ascent = descFont['FontDescriptor']['Ascent']
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   248
        self.descent = descFont['FontDescriptor']['Descent']
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   249
        self._defaultWidth = descFont['DW']
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   250
        self._explicitWidths = self._expandWidths(descFont['W'])
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   251
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   252
        # should really support self.glyphWidths, self.glyphNames
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   253
        # but not done yet.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   254
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   255
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   256
    def _expandWidths(self, compactWidthArray):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   257
        """Expands Adobe nested list structure to get a dictionary of widths.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   258
3031
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 2993
diff changeset
   259
        Here is an example of such a structure.::
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 2993
diff changeset
   260
        
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 2993
diff changeset
   261
            (
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   262
            # starting at character ID 1, next n  characters have the widths given.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   263
            1,  (277,305,500,668,668,906,727,305,445,445,508,668,305,379,305,539),
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   264
            # all Characters from ID 17 to 26 are 668 em units wide
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   265
            17, 26, 668,
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   266
            27, (305, 305, 668, 668, 668, 566, 871, 727, 637, 652, 699, 574, 555,
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   267
                 676, 687, 242, 492, 664, 582, 789, 707, 734, 582, 734, 605, 605,
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   268
                 641, 668, 727, 945, 609, 609, 574, 445, 668, 445, 668, 668, 590,
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   269
                 555, 609, 547, 602, 574, 391, 609, 582, 234, 277, 539, 234, 895,
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   270
                 582, 605, 602, 602, 387, 508, 441, 582, 562, 781, 531, 570, 555,
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   271
                 449, 246, 449, 668),
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   272
            # these must be half width katakana and the like.
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   273
            231, 632, 500
3031
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 2993
diff changeset
   274
            )
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 2993
diff changeset
   275
        
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   276
        """
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   277
        data = compactWidthArray[:]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   278
        widths = {}
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   279
        while data:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   280
            start, data = data[0], data[1:]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   281
            if type(data[0]) in (ListType, TupleType):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   282
                items, data = data[0], data[1:]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   283
                for offset in range(len(items)):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   284
                    widths[start + offset] = items[offset]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   285
            else:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   286
                end, width, data = data[0], data[1], data[2:]
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   287
                for idx in range(start, end+1):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   288
                    widths[idx] = width
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   289
        return widths
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   290
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   291
    def getCharWidth(self, characterId):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   292
        return self._explicitWidths.get(characterId, self._defaultWidth)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   293
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   294
class CIDFont(pdfmetrics.Font):
1193
7f89709f35da CMap Search Path now in config
andy_robinson
parents: 1192
diff changeset
   295
    "Represents a built-in multi-byte font"
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   296
    _multiByte = 1
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   297
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   298
    def __init__(self, face, encoding):
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   299
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   300
        assert face in allowedTypeFaces, "TypeFace '%s' not supported! Use any of these instead: %s" % (face, allowedTypeFaces)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   301
        self.faceName = face
1286
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   302
        #should cache in registry...
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   303
        self.face = CIDTypeFace(face)
1264
79862e6e40a1 Mostly correct string widths implemented for Asian fonts.
andy_robinson
parents: 1219
diff changeset
   304
79862e6e40a1 Mostly correct string widths implemented for Asian fonts.
andy_robinson
parents: 1219
diff changeset
   305
        assert encoding in allowedEncodings, "Encoding '%s' not supported!  Use any of these instead: %s" % (encoding, allowedEncodings)
79862e6e40a1 Mostly correct string widths implemented for Asian fonts.
andy_robinson
parents: 1219
diff changeset
   306
        self.encodingName = encoding
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   307
        self.encoding = CIDEncoding(encoding)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   308
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   309
        #legacy hack doing quick cut and paste.
1264
79862e6e40a1 Mostly correct string widths implemented for Asian fonts.
andy_robinson
parents: 1219
diff changeset
   310
        self.fontName = self.faceName + '-' + self.encodingName
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   311
        self.name = self.fontName
1286
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   312
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   313
        # need to know if it is vertical or horizontal
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   314
        self.isVertical = (self.encodingName[-1] == 'V')
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   315
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   316
        #no substitutes initially
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   317
        self.substitutionFonts = []
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   318
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   319
    def formatForPdf(self, text):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   320
        encoded = _escape(text)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   321
        #print 'encoded CIDFont:', encoded
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   322
        return encoded
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   323
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   324
    def stringWidth(self, text, size, encoding=None):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   325
        """This presumes non-Unicode input.  UnicodeCIDFont wraps it for that context"""
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   326
        cidlist = self.encoding.translate(text)
1286
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   327
        if self.isVertical:
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   328
            #this part is "not checked!" but seems to work.
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   329
            #assume each is 1000 ems high
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   330
            return len(cidlist) * size
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   331
        else:
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   332
            w = 0
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   333
            for cid in cidlist:
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   334
                w = w + self.face.getCharWidth(cid)
3fa0476f4ef6 Enhanced the asin font support
andy_robinson
parents: 1265
diff changeset
   335
            return 0.001 * w * size
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   336
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   337
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   338
    def addObjects(self, doc):
1362
9771eaa21b0c Japanese test now does full EUC kuten table
andy_robinson
parents: 1361
diff changeset
   339
        """The explicit code in addMinchoObjects and addGothicObjects
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   340
        will be replaced by something that pulls the data from
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   341
        _cidfontdata.py in the next few days."""
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   342
        internalName = 'F' + repr(len(doc.fontMapping)+1)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   343
1192
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   344
        bigDict = CIDFontInfo[self.face.name]
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   345
        bigDict['Name'] = '/' + internalName
1264
79862e6e40a1 Mostly correct string widths implemented for Asian fonts.
andy_robinson
parents: 1219
diff changeset
   346
        bigDict['Encoding'] = '/' + self.encodingName
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   347
1192
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   348
        #convert to PDF dictionary/array objects
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   349
        cidObj = structToPDF(bigDict)
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   350
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   351
        # link into document, and add to font map
1192
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   352
        r = doc.Reference(cidObj, internalName)
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   353
        fontDict = doc.idToObject['BasicFonts'].dict
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   354
        fontDict[internalName] = r
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   355
        doc.fontMapping[self.name] = '/' + internalName
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   356
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   357
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   358
class UnicodeCIDFont(CIDFont):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   359
    """Wraps up CIDFont to hide explicit encoding choice;
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   360
    encodes text for output as UTF16.
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   361
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   362
    lang should be one of 'jpn',chs','cht','kor' for now.
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   363
    if vertical is set, it will select a different widths array
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   364
    and possibly glyphs for some punctuation marks.
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   365
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   366
    halfWidth is only for Japanese.
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   367
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   368
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   369
    >>> dodgy = UnicodeCIDFont('nonexistent')
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   370
    Traceback (most recent call last):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   371
    ...
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   372
    KeyError: "don't know anything about CID font nonexistent"
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   373
    >>> heisei = UnicodeCIDFont('HeiseiMin-W3')
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   374
    >>> heisei.name
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   375
    'HeiseiMin-W3'
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   376
    >>> heisei.language
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   377
    'jpn'
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   378
    >>> heisei.encoding.name
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   379
    'UniJIS-UCS2-H'
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   380
    >>> #This is how PDF data gets encoded.
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   381
    >>> print heisei.formatForPdf('hello')
3376
9f1f91de9b3e reportlab: fix doctests
rgbecker
parents: 3328
diff changeset
   382
    \\000h\\000e\\000l\\000l\\000o
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   383
    >>> tokyo = u'\u6771\u4AEC'
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   384
    >>> print heisei.formatForPdf(tokyo)
3376
9f1f91de9b3e reportlab: fix doctests
rgbecker
parents: 3328
diff changeset
   385
    gqJ\\354
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   386
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   387
    """
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   388
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   389
    def __init__(self, face, isVertical=False, isHalfWidth=False):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   390
        #pass
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   391
        try:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   392
            lang, defaultEncoding = defaultUnicodeEncodings[face]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   393
        except KeyError:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   394
            raise KeyError("don't know anything about CID font %s" % face)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   395
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   396
        #we know the languages now.
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   397
        self.language = lang
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   398
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   399
        #rebuilt encoding string.  They follow rules which work
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   400
        #for the 7 fonts provided.
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   401
        enc = defaultEncoding[:-1]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   402
        if isHalfWidth:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   403
            enc = enc + 'HW-'
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   404
        if isVertical:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   405
            enc = enc + 'V'
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   406
        else:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   407
            enc = enc + 'H'
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   408
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   409
        #now we can do the more general case
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   410
        CIDFont.__init__(self, face, enc)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   411
        #self.encName = 'utf_16_le'
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   412
        #it's simpler for unicode, just use the face name
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   413
        self.name = self.fontName = face
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   414
        self.vertical = isVertical
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   415
        self.isHalfWidth = isHalfWidth
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   416
2629
3f42be5bfbfc added canned width data for CID fonts
andy
parents: 2575
diff changeset
   417
        self.unicodeWidths = widthsByUnichar[self.name]
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   418
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   419
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   420
    def formatForPdf(self, text):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   421
        #these ones should be encoded asUTF16 minus the BOM
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   422
        from codecs import utf_16_be_encode
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   423
        #print 'formatting %s: %s' % (type(text), repr(text))
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   424
        if type(text) is not str:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   425
            text = text.decode('utf8')
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   426
        utfText = utf_16_be_encode(text)[0]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   427
        encoded = _escape(utfText)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   428
        #print '  encoded:',encoded
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   429
        return encoded
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   430
        #
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   431
        #result = _escape(encoded)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   432
        #print '    -> %s' % repr(result)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   433
        #return result
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   434
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   435
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   436
    def stringWidth(self, text, size, encoding=None):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   437
        "Just ensure we do width test on characters, not bytes..."
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   438
        if type(text) is type(''):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   439
            text = text.decode('utf8')
2629
3f42be5bfbfc added canned width data for CID fonts
andy
parents: 2575
diff changeset
   440
3f42be5bfbfc added canned width data for CID fonts
andy
parents: 2575
diff changeset
   441
        widths = self.unicodeWidths
3f42be5bfbfc added canned width data for CID fonts
andy
parents: 2575
diff changeset
   442
        return size * 0.001 * sum([widths.get(uch, 1000) for uch in text])
3f42be5bfbfc added canned width data for CID fonts
andy
parents: 2575
diff changeset
   443
        #return CIDFont.stringWidth(self, text, size, encoding)
2678
38d18a697cd0 reportlab: Python2.5 changes + minor cosmetics and improvements
rgbecker
parents: 2633
diff changeset
   444
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   445
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   446
def precalculate(cmapdir):
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   447
    # crunches through all, making 'fastmap' files
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   448
    import os
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   449
    files = os.listdir(cmapdir)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   450
    for file in files:
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   451
        if os.path.isfile(cmapdir + os.sep + self.name + '.fastmap'):
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   452
            continue
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   453
        try:
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   454
            enc = CIDEncoding(file)
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   455
        except:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   456
            print('cannot parse %s, skipping' % enc)
1265
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   457
            continue
f11478b89928 Initial (inaccurate metrics?) support for chinese simplified and traditional
andy_robinson
parents: 1264
diff changeset
   458
        enc.fastSave(cmapdir)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   459
        print('saved %s.fastmap' % file)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   460
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   461
def test():
1192
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   462
    # only works if you have cirrect encodings on your box!
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   463
    c = Canvas('test_japanese.pdf')
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   464
    c.setFont('Helvetica', 30)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   465
    c.drawString(100,700, 'Japanese Font Support')
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   466
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   467
    pdfmetrics.registerFont(CIDFont('HeiseiMin-W3','90ms-RKSJ-H'))
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   468
    pdfmetrics.registerFont(CIDFont('HeiseiKakuGo-W5','90ms-RKSJ-H'))
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   469
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   470
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   471
    # the two typefaces
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   472
    c.setFont('HeiseiMin-W3-90ms-RKSJ-H', 16)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   473
    # this says "This is HeiseiMincho" in shift-JIS.  Not all our readers
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   474
    # have a Japanese PC, so I escaped it. On a Japanese-capable
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   475
    # system, print the string to see Kanji
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   476
    message1 = '\202\261\202\352\202\315\225\275\220\254\226\276\222\251\202\305\202\267\201B'
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   477
    c.drawString(100, 675, message1)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   478
    c.save()
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   479
    print('saved test_japanese.pdf')
1192
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   480
08043d817140 Added a trivial korean test, prior to testing on another machine
andy_robinson
parents: 1180
diff changeset
   481
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   482
##    print 'CMAP_DIR = ', CMAP_DIR
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   483
##    tf1 = CIDTypeFace('HeiseiMin-W3')
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   484
##    print 'ascent = ',tf1.ascent
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   485
##    print 'descent = ',tf1.descent
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   486
##    for cid in [1,2,3,4,5,18,19,28,231,1742]:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   487
##        print 'width of cid %d = %d' % (cid, tf1.getCharWidth(cid))
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   488
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   489
    encName = '90ms-RKSJ-H'
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   490
    enc = CIDEncoding(encName)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   491
    print(message1, '->', enc.translate(message1))
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   492
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   493
    f = CIDFont('HeiseiMin-W3','90ms-RKSJ-H')
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   494
    print('width = %0.2f' % f.stringWidth(message1, 10))
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   495
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   496
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   497
    #testing all encodings
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   498
##    import time
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   499
##    started = time.time()
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   500
##    import glob
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   501
##    for encName in _cidfontdata.allowedEncodings:
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   502
##    #encName = '90ms-RKSJ-H'
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   503
##        enc = CIDEncoding(encName)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   504
##        print 'encoding %s:' % encName
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   505
##        print '    codeSpaceRanges = %s' % enc._codeSpaceRanges
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   506
##        print '    notDefRanges = %s' % enc._notDefRanges
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   507
##        print '    mapping size = %d' % len(enc._cmap)
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   508
##    finished = time.time()
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   509
##    print 'constructed all encodings in %0.2f seconds' % (finished - started)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1362
diff changeset
   510
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   511
if __name__=='__main__':
3328
4d7f836cd947 reportlab: fix 2to3 warnings
rgbecker
parents: 3326
diff changeset
   512
    import doctest
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   513
    from . import cidfonts
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   514
    doctest.testmod(cidfonts)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2565
diff changeset
   515
    #test()
1180
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   516
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   517
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   518
1961429ad6f4 Japanese Fonts checked in
andy_robinson
parents:
diff changeset
   519