5 def __init__(self
, word
):
6 self
.width_index
= int((word
& 0xFF000000L
) >> 24) #make sign-safe
7 self
.height_index
= (word
& 0x00F00000) >> 20
8 self
.depth_index
= (word
& 0x000F0000) >> 16
9 self
.italic_index
= (word
& 0x0000FC00) >> 10
10 self
.tag
= (word
& 0x00000300) >> 8
11 self
.remainder
= (word
& 0x000000FF)
16 def __init__(self
, name
, debug
=0):
17 self
.file = reader
.reader(name
)
23 self
.lf
= self
.file.readint16()
24 self
.lh
= self
.file.readint16()
25 self
.bc
= self
.file.readint16()
26 self
.ec
= self
.file.readint16()
27 self
.nw
= self
.file.readint16()
28 self
.nh
= self
.file.readint16()
29 self
.nd
= self
.file.readint16()
30 self
.ni
= self
.file.readint16()
31 self
.nl
= self
.file.readint16()
32 self
.nk
= self
.file.readint16()
33 self
.ne
= self
.file.readint16()
34 self
.np
= self
.file.readint16()
36 if not (self
.bc
-1 <= self
.ec
<= 255 and
38 self
.lf
== 6+self
.lh
+(self
.ec
-self
.bc
+1)+self
.nw
+self
.nh
+self
.nd
39 +self
.ni
+self
.nl
+self
.nk
+self
.ne
+self
.np
):
40 raise RuntimeError("error in TFM pre-header")
43 print "lh=%d" % self
.lh
49 self
.checksum
= self
.file.readint32()
50 self
.designsize
= self
.file.readint32()
51 assert self
.designsize
> 0, "invald design size"
53 assert self
.lh
> 11, "inconsistency in TFM file: incomplete field"
54 self
.charcoding
= self
.file.readstring(40)
56 self
.charcoding
= None
59 assert self
.lh
> 16, "inconsistency in TFM file: incomplete field"
60 self
.fontfamily
= self
.file.readstring(20)
62 self
.fontfamily
= None
65 print "(FAMILY %s)" % self
.fontfamily
66 print "(CODINGSCHEME %s)" % self
.charcoding
67 print "(DESINGSIZE R %f)" % (16.0*self
.designsize
/16777216L)
70 self
.sevenbitsave
= self
.file.readuchar()
71 # ignore the following two bytes
73 facechar
= self
.file.readuchar()
74 # decode ugly face specification into the Knuth suggested string
86 self
.face
= "L" + self
.face
89 self
.face
= "B" + self
.face
92 self
.face
= "M" + self
.face
95 self
.face
= self
.face
[0] + "I" + self
.face
[1]
97 self
.face
= self
.face
[0] + "R" + self
.face
[1]
102 self
.sevenbitsave
= self
.face
= None
105 # just ignore the rest
106 print self
.file.read((self
.lh
-18)*4)
112 self
.char_info
= [None]*(self
.ec
+1)
113 for charcode
in range(self
.bc
, self
.ec
+1):
114 self
.char_info
[charcode
] = char_info_word(self
.file.readint32())
115 if self
.char_info
[charcode
].width_index
== 0:
116 # disable character if width_index is zero
117 self
.char_info
[charcode
] = None
123 self
.width
= [None for width_index
in range(self
.nw
)]
124 for width_index
in range(self
.nw
):
125 self
.width
[width_index
] = self
.file.readint32()
131 self
.height
= [None for height_index
in range(self
.nh
)]
132 for height_index
in range(self
.nh
):
133 self
.height
[height_index
] = self
.file.readint32()
139 self
.depth
= [None for depth_index
in range(self
.nd
)]
140 for depth_index
in range(self
.nd
):
141 self
.depth
[depth_index
] = self
.file.readint32()
147 self
.italic
= [None for italic_index
in range(self
.ni
)]
148 for italic_index
in range(self
.ni
):
149 self
.italic
[italic_index
] = self
.file.readint32()
155 # XXX decode to lig_kern_command
157 self
.lig_kern
= [None for lig_kern_index
in range(self
.nl
)]
158 for lig_kern_index
in range(self
.nl
):
159 self
.lig_kern
[lig_kern_index
] = self
.file.readint32()
165 self
.kern
= [None for kern_index
in range(self
.nk
)]
166 for kern_index
in range(self
.nk
):
167 self
.kern
[kern_index
] = self
.file.readint32()
173 # XXX decode to extensible_recipe
175 self
.exten
= [None for exten_index
in range(self
.ne
)]
176 for exten_index
in range(self
.ne
):
177 self
.exten
[exten_index
] = self
.file.readint32()
185 self
.param
= [None for param_index
in range(self
.np
)]
186 for param_index
in range(self
.np
):
187 self
.param
[param_index
] = self
.file.readint32()