~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to PIL/PcfFontFile.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# See the README file for information on usage and redistribution.
17
17
#
18
18
 
19
 
import Image
20
 
import FontFile
21
 
 
22
 
import string
 
19
from . import Image
 
20
from . import FontFile
 
21
from . import _binary
23
22
 
24
23
# --------------------------------------------------------------------
25
24
# declarations
43
42
    lambda bits: ((bits+63) >> 3) & ~7,
44
43
]
45
44
 
46
 
 
47
 
def l16(c):
48
 
    return ord(c[0]) + (ord(c[1])<<8)
49
 
def l32(c):
50
 
    return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24)
51
 
 
52
 
def b16(c):
53
 
    return ord(c[1]) + (ord(c[0])<<8)
54
 
def b32(c):
55
 
    return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24)
 
45
i8 = _binary.i8
 
46
l16 = _binary.i16le
 
47
l32 = _binary.i32le
 
48
b16 = _binary.i16be
 
49
b32 = _binary.i32be
56
50
 
57
51
def sz(s, o):
58
 
    return s[o:string.index(s, "\0", o)]
 
52
    return s[o:s.index(b"\0", o)]
59
53
 
60
54
##
61
55
# Font file plugin for the X11 PCF format.
68
62
 
69
63
        magic = l32(fp.read(4))
70
64
        if magic != PCF_MAGIC:
71
 
            raise SyntaxError, "not a PCF file"
 
65
            raise SyntaxError("not a PCF file")
72
66
 
73
67
        FontFile.FontFile.__init__(self)
74
68
 
126
120
        # read property description
127
121
        p = []
128
122
        for i in range(nprops):
129
 
            p.append((i32(fp.read(4)), ord(fp.read(1)), i32(fp.read(4))))
 
123
            p.append((i32(fp.read(4)), i8(fp.read(1)), i32(fp.read(4))))
130
124
        if nprops & 3:
131
125
            fp.seek(4 - (nprops & 3), 1) # pad
132
126
 
155
149
 
156
150
            # "compressed" metrics
157
151
            for i in range(i16(fp.read(2))):
158
 
                left = ord(fp.read(1)) - 128
159
 
                right = ord(fp.read(1)) - 128
160
 
                width = ord(fp.read(1)) - 128
161
 
                ascent = ord(fp.read(1)) - 128
162
 
                descent = ord(fp.read(1)) - 128
 
152
                left = i8(fp.read(1)) - 128
 
153
                right = i8(fp.read(1)) - 128
 
154
                width = i8(fp.read(1)) - 128
 
155
                ascent = i8(fp.read(1)) - 128
 
156
                descent = i8(fp.read(1)) - 128
163
157
                xsize = right - left
164
158
                ysize = ascent + descent
165
159
                append(
198
192
        nbitmaps = i32(fp.read(4))
199
193
 
200
194
        if nbitmaps != len(metrics):
201
 
            raise IOError, "Wrong number of bitmaps"
 
195
            raise IOError("Wrong number of bitmaps")
202
196
 
203
197
        offsets = []
204
198
        for i in range(nbitmaps):
226
220
            x, y, l, r, w, a, d, f = metrics[i]
227
221
            b, e = offsets[i], offsets[i+1]
228
222
            bitmaps.append(
229
 
                Image.fromstring("1", (x, y), data[b:e], "raw", mode, pad(x))
 
223
                Image.frombytes("1", (x, y), data[b:e], "raw", mode, pad(x))
230
224
                )
231
225
 
232
226
        return bitmaps