1 # -*- encoding: utf-8 -*-
4 # Copyright (C) 2007-2011 Jörg Lehmann <joergl@users.sourceforge.net>
5 # Copyright (C) 2007-2011 André Wobst <wobsta@users.sourceforge.net>
7 # This file is part of PyX (http://pyx.sourceforge.net/).
9 # PyX is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # PyX is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with PyX; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 from pyx
import reader
28 def __init__(self
, word
):
29 self
.width_index
= int((word
& 0xFF000000) >> 24) #make sign-safe
30 self
.height_index
= (word
& 0x00F00000) >> 20
31 self
.depth_index
= (word
& 0x000F0000) >> 16
32 self
.italic_index
= (word
& 0x0000FC00) >> 10
33 self
.tag
= (word
& 0x00000300) >> 8
34 self
.remainder
= (word
& 0x000000FF)
39 def __init__(self
, file, debug
=0):
40 with reader
.bytesreader(file.read()) as file:
46 self
.lf
= file.readint16()
47 self
.lh
= file.readint16()
48 self
.bc
= file.readint16()
49 self
.ec
= file.readint16()
50 self
.nw
= file.readint16()
51 self
.nh
= file.readint16()
52 self
.nd
= file.readint16()
53 self
.ni
= file.readint16()
54 self
.nl
= file.readint16()
55 self
.nk
= file.readint16()
56 self
.ne
= file.readint16()
57 self
.np
= file.readint16()
59 if not (self
.bc
-1 <= self
.ec
<= 255 and
61 self
.lf
== 6+self
.lh
+(self
.ec
-self
.bc
+1)+self
.nw
+self
.nh
+self
.nd
62 +self
.ni
+self
.nl
+self
.nk
+self
.ne
+self
.np
):
63 raise RuntimeError("error in TFM pre-header")
66 print("lh=%d" % self
.lh
)
72 self
.checksum
= file.readint32()
73 self
.designsize
= file.readint32()
74 assert self
.designsize
> 0, "invald design size"
76 assert self
.lh
> 11, "inconsistency in TFM file: incomplete field"
77 self
.charcoding
= file.readstring(40)
79 self
.charcoding
= None
82 assert self
.lh
> 16, "inconsistency in TFM file: incomplete field"
83 self
.fontfamily
= file.readstring(20)
85 self
.fontfamily
= None
88 print("(FAMILY %s)" % self
.fontfamily
)
89 print("(CODINGSCHEME %s)" % self
.charcoding
)
90 print("(DESINGSIZE R %f)" % (16.0*self
.designsize
/16777216))
93 self
.sevenbitsave
= file.readuchar()
94 # ignore the following two bytes
96 facechar
= file.readuchar()
97 # decode ugly face specification into the Knuth suggested string
109 self
.face
= "L" + self
.face
112 self
.face
= "B" + self
.face
115 self
.face
= "M" + self
.face
118 self
.face
= self
.face
[0] + "I" + self
.face
[1]
120 self
.face
= self
.face
[0] + "R" + self
.face
[1]
125 self
.sevenbitsave
= self
.face
= None
128 # just ignore the rest
129 print(file.read((self
.lh
-18)*4))
135 self
.char_info
= [None]*(self
.ec
+1)
136 for charcode
in range(self
.bc
, self
.ec
+1):
137 self
.char_info
[charcode
] = char_info_word(file.readint32())
138 if self
.char_info
[charcode
].width_index
== 0:
139 # disable character if width_index is zero
140 self
.char_info
[charcode
] = None
146 self
.width
= [None for width_index
in range(self
.nw
)]
147 for width_index
in range(self
.nw
):
148 self
.width
[width_index
] = file.readint32()
154 self
.height
= [None for height_index
in range(self
.nh
)]
155 for height_index
in range(self
.nh
):
156 self
.height
[height_index
] = file.readint32()
162 self
.depth
= [None for depth_index
in range(self
.nd
)]
163 for depth_index
in range(self
.nd
):
164 self
.depth
[depth_index
] = file.readint32()
170 self
.italic
= [None for italic_index
in range(self
.ni
)]
171 for italic_index
in range(self
.ni
):
172 self
.italic
[italic_index
] = file.readint32()
178 # XXX decode to lig_kern_command
180 self
.lig_kern
= [None for lig_kern_index
in range(self
.nl
)]
181 for lig_kern_index
in range(self
.nl
):
182 self
.lig_kern
[lig_kern_index
] = file.readint32()
188 self
.kern
= [None for kern_index
in range(self
.nk
)]
189 for kern_index
in range(self
.nk
):
190 self
.kern
[kern_index
] = file.readint32()
196 # XXX decode to extensible_recipe
198 self
.exten
= [None for exten_index
in range(self
.ne
)]
199 for exten_index
in range(self
.ne
):
200 self
.exten
[exten_index
] = file.readint32()
208 self
.param
= [None for param_index
in range(self
.np
)]
209 for param_index
in range(self
.np
):
210 self
.param
[param_index
] = file.readint32()