src/reportlab/lib/rl_accel.py
author robin
Mon, 25 Nov 2013 14:59:22 +0000
branchpy33
changeset 3835 8e35c471e0ee
parent 3779 47bb4a41365d
child 3862 272e650eecf5
permissions -rw-r--r--
various: attempt to be more consistent about isStr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     1
#this is the interface module that imports all from the C extension _rl_accel
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     2
_c_funcs = {}
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     3
_py_funcs = {}
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     4
### NOTE!  FP_STR SHOULD PROBABLY ALWAYS DO A PYTHON STR() CONVERSION ON ARGS
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     5
### IN CASE THEY ARE "LAZY OBJECTS".  ACCELLERATOR DOESN'T DO THIS (YET)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     6
__all__ = list(filter(None,'''
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     7
        fp_str
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     8
        unicode2T1
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
     9
        instanceStringWidthT1
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    10
        instanceStringWidthTTF
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    11
        asciiBase85Encode
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    12
        asciiBase85Decode
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    13
        escapePDF
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    14
        sameFrag
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    15
        calcChecksum
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    16
        add32
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    17
        hex32
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    18
        '''.split()))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    19
import __main__
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    20
testing = getattr(__main__,'_rl_testing',False)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    21
del __main__
3725
ca840494f9dd added rl_accel
robin
parents:
diff changeset
    22
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    23
for fn in __all__:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    24
    try:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    25
        exec('from reportlab.lib._rl_accel import %s as f' % fn)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    26
        _c_funcs[fn] = f
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    27
    except ImportError:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    28
        _py_funcs[fn] = None
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    29
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    30
if _py_funcs:
3835
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
    31
    from reportlab.lib.utils import isBytes, isUnicode, isSeq, isPy3
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    32
    from math import log
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    34
if 'fp_str' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    35
    _log_10 = lambda x,log=log,_log_e_10=log(10.0): log(x)/_log_e_10
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    36
    _fp_fmts = "%.0f", "%.1f", "%.2f", "%.3f", "%.4f", "%.5f", "%.6f"
3725
ca840494f9dd added rl_accel
robin
parents:
diff changeset
    37
    def fp_str(*a):
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    38
        '''convert separate arguments (or single sequence arg) into space separated numeric strings'''
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    39
        if len(a)==1 and isSeq(a[0]): a = a[0]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    40
        s = []
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    41
        A = s.append
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    42
        for i in a:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    43
            sa =abs(i)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    44
            if sa<=1e-7: A('0')
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    45
            else:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    46
                l = sa<=1 and 6 or min(max(0,(6-int(_log_10(sa)))),6)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    47
                n = _fp_fmts[l]%i
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    48
                if l:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    49
                    j = len(n)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    50
                    while j:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    51
                        j -= 1
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    52
                        if n[j]!='0':
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    53
                            if n[j]!='.': j += 1
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    54
                            break
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    55
                    n = n[:j]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    56
                A((n[0]!='0' or len(n)==1) and n or n[1:])
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    57
        return ' '.join(s)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    58
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    59
    #hack test for comma users
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    60
    if ',' in fp_str(0.25):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    61
        _FP_STR = _fp_str
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    62
        def _fp_str(*a):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    63
            return _FP_STR(*a).replace(',','.')
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    64
    _py_funcs['fp_str'] = fp_str
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    65
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    66
if 'unicode2T1' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    67
    def unicode2T1(utext,fonts):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    68
        '''return a list of (font,string) pairs representing the unicode text'''
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    69
        R = []
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    70
        font, fonts = fonts[0], fonts[1:]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    71
        enc = font.encName
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    72
        if 'UCS-2' in enc:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    73
            enc = 'UTF16'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    74
        while utext:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    75
            try:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    76
                if isUnicode(utext):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    77
                    s = utext.encode(enc)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    78
                else:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    79
                    s = utext
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    80
                R.append((font,s))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    81
                break
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    82
            except UnicodeEncodeError as e:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    83
                i0, il = e.args[2:4]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    84
                if i0:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    85
                    R.append((font,utext[:i0].encode(enc)))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    86
                if fonts:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    87
                    R.extend(unicode2T1(utext[i0:il],fonts))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    88
                else:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    89
                    R.append((font._notdefFont,font._notdefChar*(il-i0)))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    90
                utext = utext[il:]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    91
        return R
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    92
    _py_funcs['unicode2T1'] = unicode2T1
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    93
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    94
if 'instanceStringWidthT1' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    95
    def _instanceStringWidthT1(self, text, size, encoding='utf8'):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    96
        """This is the "purist" approach to width"""
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    97
        if not isUnicode(text): text = text.decode(encoding)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    98
        return sum([sum(map(f.widths.__getitem__,list(map(ord,t)))) for f, t in unicode2T1(text,[self]+self.substitutionFonts)])*0.001*size
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
    99
    _py_funcs['instanceStringWidthT1'] = instanceStringWidthT1
3725
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   100
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   101
if 'instanceStringWidthTTF' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   102
    def instanceStringWidthTTF(self, text, size, encoding='utf-8'):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   103
        "Calculate text width"
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   104
        if not isinstance(text,str):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   105
            text = str(text, encoding or 'utf-8')   # encoding defaults to utf-8
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   106
        g = self.face.charWidths.get
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   107
        dw = self.face.defaultWidth
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   108
        return 0.001*size*sum([g(ord(u),dw) for u in text])
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   109
    _py_funcs['instanceStringWidthTTF'] = instanceStringWidthTTF
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   110
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   111
if 'hex32' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   112
    def hex32(i):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   113
        return '0X%8.8X' % (int(i)&0xFFFFFFFF)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   114
    _py_funcs['hex32'] = hex32
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   115
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   116
if 'add32' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   117
    def add32(x, y):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   118
        "Calculate (x + y) modulo 2**32"
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   119
        return (x+y) & 0xFFFFFFFF
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   120
    _py_funcs['add32'] = add32
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   121
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   122
if 'calcChecksum' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   123
    def calcChecksum(data):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   124
        """Calculates TTF-style checksums"""
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   125
        if len(data)&3: data = data + (4-(len(data)&3))*"\0"
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   126
        return sum(unpack(">%dl" % (len(data)>>2), data)) & 0xFFFFFFFF
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   127
    _py_funcs['calcChecksum'] = calcChecksum
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   128
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   129
if 'escapePDF' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   130
    _ESCAPEDICT={}
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   131
    for c in range(256):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   132
        if c<32 or c>=127:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   133
            _ESCAPEDICT[c]= '\\%03o' % c
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   134
        elif c in (ord('\\'),ord('('),ord(')')):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   135
            _ESCAPEDICT[c] = '\\'+chr(c)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   136
        else:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   137
            _ESCAPEDICT[c] = chr(c)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   138
    del c
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   139
    #Michael Hudson donated this
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   140
    def escapePDF(s):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   141
        r = []
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   142
        for c in s:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   143
            if not type(c) is int:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   144
                c = ord(c)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   145
            r.append(_ESCAPEDICT[c])
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   146
        return ''.join(r)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   147
    _py_funcs['escapePDF'] = escapePDF
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   148
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   149
if 'asciiBase85Encode' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   150
    def asciiBase85Encode(input):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   151
        """Encodes input using ASCII-Base85 coding.
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   152
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   153
        This is a compact encoding used for binary data within
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   154
        a PDF file.  Four bytes of binary data become five bytes of
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   155
        ASCII.  This is the default method used for encoding images."""
3835
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   156
        doOrd = isPy3 and isUnicode(input)
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   157
        # special rules apply if not a multiple of four bytes.
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   158
        whole_word_count, remainder_size = divmod(len(input), 4)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   159
        cut = 4 * whole_word_count
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   160
        body, lastbit = input[0:cut], input[cut:]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   161
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   162
        out = [].append
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   163
        for i in range(whole_word_count):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   164
            offset = i*4
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   165
            b1 = body[offset]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   166
            b2 = body[offset+1]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   167
            b3 = body[offset+2]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   168
            b4 = body[offset+3]
3835
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   169
            if doOrd:
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   170
                b1 = ord(b1)
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   171
                b2 = ord(b2)
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   172
                b3 = ord(b3)
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   173
                b4 = ord(b4)
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   174
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   175
            if b1<128:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   176
                num = (((((b1<<8)|b2)<<8)|b3)<<8)|b4
3725
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   177
            else:
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   178
                num = 16777216 * b1 + 65536 * b2 + 256 * b3 + b4
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   179
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   180
            if num == 0:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   181
                #special case
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   182
                out('z')
3725
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   183
            else:
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   184
                #solve for five base-85 numbers
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   185
                temp, c5 = divmod(num, 85)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   186
                temp, c4 = divmod(temp, 85)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   187
                temp, c3 = divmod(temp, 85)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   188
                c1, c2 = divmod(temp, 85)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   189
                assert ((85**4) * c1) + ((85**3) * c2) + ((85**2) * c3) + (85*c4) + c5 == num, 'dodgy code!'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   190
                out(chr(c1+33))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   191
                out(chr(c2+33))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   192
                out(chr(c3+33))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   193
                out(chr(c4+33))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   194
                out(chr(c5+33))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   195
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   196
        # now we do the final bit at the end.  I repeated this separately as
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   197
        # the loop above is the time-critical part of a script, whereas this
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   198
        # happens only once at the end.
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   199
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   200
        #encode however many bytes we have as usual
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   201
        if remainder_size > 0:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   202
            while len(lastbit) < 4:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   203
                lastbit = lastbit + b'\000'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   204
            b1 = lastbit[0]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   205
            b2 = lastbit[1]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   206
            b3 = lastbit[2]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   207
            b4 = lastbit[3]
3835
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   208
            if doOrd:
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   209
                b1 = ord(b1)
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   210
                b2 = ord(b2)
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   211
                b3 = ord(b3)
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3779
diff changeset
   212
                b4 = ord(b4)
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   213
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   214
            num = 16777216 * b1 + 65536 * b2 + 256 * b3 + b4
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   215
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   216
            #solve for c1..c5
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   217
            temp, c5 = divmod(num, 85)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   218
            temp, c4 = divmod(temp, 85)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   219
            temp, c3 = divmod(temp, 85)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   220
            c1, c2 = divmod(temp, 85)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   221
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   222
            #print 'encoding: %d %d %d %d -> %d -> %d %d %d %d %d' % (
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   223
            #    b1,b2,b3,b4,num,c1,c2,c3,c4,c5)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   224
            lastword = chr(c1+33) + chr(c2+33) + chr(c3+33) + chr(c4+33) + chr(c5+33)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   225
            #write out most of the bytes.
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   226
            out(lastword[0:remainder_size + 1])
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   227
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   228
        #terminator code for ascii 85
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   229
        out('~>')
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   230
        return ''.join(out.__self__)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   231
    _py_funcs['asciiBase85Encode'] = asciiBase85Encode
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   232
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   233
if 'asciiBase85Decode' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   234
    def asciiBase85Decode(input):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   235
        """Decodes input using ASCII-Base85 coding.
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   236
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   237
        This is not used - Acrobat Reader decodes for you
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   238
        - but a round trip is essential for testing."""
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   239
        #strip all whitespace
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   240
        stripped = ''.join(input.split())
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   241
        #check end
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   242
        assert stripped[-2:] == '~>', 'Invalid terminator for Ascii Base 85 Stream'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   243
        stripped = stripped[:-2]  #chop off terminator
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   244
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   245
        #may have 'z' in it which complicates matters - expand them
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   246
        stripped = stripped.replace('z','!!!!!')
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   247
        # special rules apply if not a multiple of five bytes.
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   248
        whole_word_count, remainder_size = divmod(len(stripped), 5)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   249
        #print '%d words, %d leftover' % (whole_word_count, remainder_size)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   250
        #assert remainder_size != 1, 'invalid Ascii 85 stream!'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   251
        cut = 5 * whole_word_count
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   252
        body, lastbit = stripped[0:cut], stripped[cut:]
3725
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   253
3779
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   254
        out = [].append
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   255
        for i in range(whole_word_count):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   256
            offset = i*5
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   257
            c1 = ord(body[offset]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   258
            c2 = ord(body[offset+1]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   259
            c3 = ord(body[offset+2]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   260
            c4 = ord(body[offset+3]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   261
            c5 = ord(body[offset+4]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   262
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   263
            num = ((85**4) * c1) + ((85**3) * c2) + ((85**2) * c3) + (85*c4) + c5
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   264
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   265
            temp, b4 = divmod(num,256)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   266
            temp, b3 = divmod(temp,256)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   267
            b1, b2 = divmod(temp, 256)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   268
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   269
            assert  num == 16777216 * b1 + 65536 * b2 + 256 * b3 + b4, 'dodgy code!'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   270
            out(chr(b1))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   271
            out(chr(b2))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   272
            out(chr(b3))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   273
            out(chr(b4))
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   274
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   275
        #decode however many bytes we have as usual
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   276
        if remainder_size > 0:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   277
            while len(lastbit) < 5:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   278
                lastbit = lastbit + '!'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   279
            c1 = ord(lastbit[0]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   280
            c2 = ord(lastbit[1]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   281
            c3 = ord(lastbit[2]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   282
            c4 = ord(lastbit[3]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   283
            c5 = ord(lastbit[4]) - 33
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   284
            num = (((85*c1+c2)*85+c3)*85+c4)*85 + (c5
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   285
                     +(0,0,0xFFFFFF,0xFFFF,0xFF)[remainder_size])
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   286
            temp, b4 = divmod(num,256)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   287
            temp, b3 = divmod(temp,256)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   288
            b1, b2 = divmod(temp, 256)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   289
            assert  num == 16777216 * b1 + 65536 * b2 + 256 * b3 + b4, 'dodgy code!'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   290
            #print 'decoding: %d %d %d %d %d -> %d -> %d %d %d %d' % (
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   291
            #    c1,c2,c3,c4,c5,num,b1,b2,b3,b4)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   292
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   293
            #the last character needs 1 adding; the encoding loses
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   294
            #data by rounding the number to x bytes, and when
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   295
            #divided repeatedly we get one less
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   296
            if remainder_size == 2:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   297
                lastword = chr(b1)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   298
            elif remainder_size == 3:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   299
                lastword = chr(b1) + chr(b2)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   300
            elif remainder_size == 4:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   301
                lastword = chr(b1) + chr(b2) + chr(b3)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   302
            else:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   303
                lastword = ''
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   304
            out(lastword)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   305
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   306
        #terminator code for ascii 85
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   307
        return ''.join(out.__self__)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   308
    _py_funcs['asciiBase85Decode'] = asciiBase85Decode
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   309
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   310
if 'sameFrag' in _py_funcs:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   311
    def sameFrag(f,g):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   312
        'returns 1 if two ParaFrags map out the same'
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   313
        if (hasattr(f,'cbDefn') or hasattr(g,'cbDefn')
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   314
                or hasattr(f,'lineBreak') or hasattr(g,'lineBreak')): return 0
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   315
        for a in ('fontName', 'fontSize', 'textColor', 'rise', 'underline', 'strike', 'link', "backColor"):
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   316
            if getattr(f,a,None)!=getattr(g,a,None): return 0
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   317
        return 1
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   318
    _py_funcs['sameFrag'] = sameFrag
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   319
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   320
G=globals()
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   321
for fn in __all__:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   322
    f = _c_funcs[fn] or _py_funcs[fn]
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   323
    if not f:
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   324
        raise RuntimeError('function %s is not properly defined' % fn)
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   325
    G[fn] = f
47bb4a41365d all _rl_accel exports come through rl_accel.py
robin
parents: 3731
diff changeset
   326
del fn, f, G
3725
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   327
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   328
if __name__=='__main__':
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   329
    import sys, os
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   330
    for modname in 'reportlab.lib.rl_accel','reportlab.lib._rl_accel':
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   331
        for cmd  in (
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   332
            #"unicode2T1('abcde fghi . jkl ; mno',fonts)",
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   333
            #"unicode2T1(u'abcde fghi . jkl ; mno',fonts)",
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   334
            "_instanceStringWidthU(font,'abcde fghi . jkl ; mno',10)",
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   335
            "_instanceStringWidthU(font,u'abcde fghi . jkl ; mno',10)",
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   336
            ):
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3727
diff changeset
   337
            print('%s %s' % (modname,cmd))
3725
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   338
            s=';'.join((
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   339
                "from reportlab.pdfbase.pdfmetrics import getFont",
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   340
                "from %s import unicode2T1,_instanceStringWidthU" % modname,
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   341
                "fonts=[getFont('Helvetica')]+getFont('Helvetica').substitutionFonts""",
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   342
                "font=fonts[0]",
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   343
                ))
ca840494f9dd added rl_accel
robin
parents:
diff changeset
   344
            os.system('%s -m timeit -s"%s" "%s"' % (sys.executable,s,cmd))