/usr/share/pyshared/pyx/dvi/tfmfile.py is in python-pyx 0.11.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | # -*- encoding: utf-8 -*-
#
#
# Copyright (C) 2007-2011 Jörg Lehmann <joergl@users.sourceforge.net>
# Copyright (C) 2007-2011 André Wobst <wobsta@users.sourceforge.net>
#
# This file is part of PyX (http://pyx.sourceforge.net/).
#
# PyX is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PyX is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyX; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from pyx import reader
class char_info_word:
def __init__(self, word):
self.width_index = int((word & 0xFF000000L) >> 24) #make sign-safe
self.height_index = (word & 0x00F00000) >> 20
self.depth_index = (word & 0x000F0000) >> 16
self.italic_index = (word & 0x0000FC00) >> 10
self.tag = (word & 0x00000300) >> 8
self.remainder = (word & 0x000000FF)
class TFMfile:
def __init__(self, file, debug=0):
self.file = reader.stringreader(file.read())
#
# read pre header
#
self.lf = self.file.readint16()
self.lh = self.file.readint16()
self.bc = self.file.readint16()
self.ec = self.file.readint16()
self.nw = self.file.readint16()
self.nh = self.file.readint16()
self.nd = self.file.readint16()
self.ni = self.file.readint16()
self.nl = self.file.readint16()
self.nk = self.file.readint16()
self.ne = self.file.readint16()
self.np = self.file.readint16()
if not (self.bc-1 <= self.ec <= 255 and
self.ne <= 256 and
self.lf == 6+self.lh+(self.ec-self.bc+1)+self.nw+self.nh+self.nd
+self.ni+self.nl+self.nk+self.ne+self.np):
raise RuntimeError("error in TFM pre-header")
if debug:
print "lh=%d" % self.lh
#
# read header
#
self.checksum = self.file.readint32()
self.designsize = self.file.readint32()
assert self.designsize > 0, "invald design size"
if self.lh > 2:
assert self.lh > 11, "inconsistency in TFM file: incomplete field"
self.charcoding = self.file.readstring(40)
else:
self.charcoding = None
if self.lh > 12:
assert self.lh > 16, "inconsistency in TFM file: incomplete field"
self.fontfamily = self.file.readstring(20)
else:
self.fontfamily = None
if debug:
print "(FAMILY %s)" % self.fontfamily
print "(CODINGSCHEME %s)" % self.charcoding
print "(DESINGSIZE R %f)" % (16.0*self.designsize/16777216L)
if self.lh > 17:
self.sevenbitsave = self.file.readuchar()
# ignore the following two bytes
self.file.readint16()
facechar = self.file.readuchar()
# decode ugly face specification into the Knuth suggested string
if facechar < 18:
if facechar >= 12:
self.face = "E"
facechar -= 12
elif facechar >= 6:
self.face = "C"
facechar -= 6
else:
self.face = "R"
if facechar >= 4:
self.face = "L" + self.face
facechar -= 4
elif facechar >= 2:
self.face = "B" + self.face
facechar -= 2
else:
self.face = "M" + self.face
if facechar == 1:
self.face = self.face[0] + "I" + self.face[1]
else:
self.face = self.face[0] + "R" + self.face[1]
else:
self.face = None
else:
self.sevenbitsave = self.face = None
if self.lh > 18:
# just ignore the rest
print self.file.read((self.lh-18)*4)
#
# read char_info
#
self.char_info = [None]*(self.ec+1)
for charcode in range(self.bc, self.ec+1):
self.char_info[charcode] = char_info_word(self.file.readint32())
if self.char_info[charcode].width_index == 0:
# disable character if width_index is zero
self.char_info[charcode] = None
#
# read widths
#
self.width = [None for width_index in range(self.nw)]
for width_index in range(self.nw):
self.width[width_index] = self.file.readint32()
#
# read heights
#
self.height = [None for height_index in range(self.nh)]
for height_index in range(self.nh):
self.height[height_index] = self.file.readint32()
#
# read depths
#
self.depth = [None for depth_index in range(self.nd)]
for depth_index in range(self.nd):
self.depth[depth_index] = self.file.readint32()
#
# read italic
#
self.italic = [None for italic_index in range(self.ni)]
for italic_index in range(self.ni):
self.italic[italic_index] = self.file.readint32()
#
# read lig_kern
#
# XXX decode to lig_kern_command
self.lig_kern = [None for lig_kern_index in range(self.nl)]
for lig_kern_index in range(self.nl):
self.lig_kern[lig_kern_index] = self.file.readint32()
#
# read kern
#
self.kern = [None for kern_index in range(self.nk)]
for kern_index in range(self.nk):
self.kern[kern_index] = self.file.readint32()
#
# read exten
#
# XXX decode to extensible_recipe
self.exten = [None for exten_index in range(self.ne)]
for exten_index in range(self.ne):
self.exten[exten_index] = self.file.readint32()
#
# read param
#
# XXX decode
self.param = [None for param_index in range(self.np)]
for param_index in range(self.np):
self.param[param_index] = self.file.readint32()
self.file.close()
|