This file is indexed.

/usr/share/pyshared/pyx/font/pfmfile.py is in python-pyx 0.12.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# -*- encoding: utf-8 -*-
#
#
# 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

import struct, re
import metric


ansiglyphs = {"space": 32,
              "exclam": 33,
              "quotedbl": 34,
              "numbersign": 35,
              "dollar": 36,
              "percent": 37,
              "ampersand": 38,
              "quotesingle": 39,
              "parenleft": 40,
              "parenright": 41,
              "asterisk": 42,
              "plus": 43,
              "comma": 44,
              "hyphen": 45,
              "period": 46,
              "slash": 47,
              "zero": 48,
              "one": 49,
              "two": 50,
              "three": 51,
              "four": 52,
              "five": 53,
              "six": 54,
              "seven": 55,
              "eight": 56,
              "nine": 57,
              "colon": 58,
              "semicolon": 59,
              "less": 60,
              "equal": 61,
              "greater": 62,
              "question": 63,
              "at": 64,
              "A": 65,
              "B": 66,
              "C": 67,
              "D": 68,
              "E": 69,
              "F": 70,
              "G": 71,
              "H": 72,
              "I": 73,
              "J": 74,
              "K": 75,
              "L": 76,
              "M": 77,
              "N": 78,
              "O": 79,
              "P": 80,
              "Q": 81,
              "R": 82,
              "S": 83,
              "T": 84,
              "U": 85,
              "V": 86,
              "W": 87,
              "X": 88,
              "Y": 89,
              "Z": 90,
              "bracketleft": 91,
              "backslash": 92,
              "bracketright": 93,
              "asciicircum": 94,
              "underscore": 95,
              "grave": 96,
              "a": 97,
              "b": 98,
              "c": 99,
              "d": 100,
              "e":101,
              "f":102,
              "g":103,
              "h":104,
              "i":105,
              "j":106,
              "k":107,
              "l":108,
              "m":109,
              "n":110,
              "o":111,
              "p":112,
              "q":113,
              "r":114,
              "s":115,
              "t":116,
              "u":117,
              "v":118,
              "w":119,
              "x":120,
              "y":121,
              "z":122,
              "braceleft":123,
              "bar":124,
              "braceright":125,
              "asciitilde":126,
              "bullet":127,
              "Euro":128,
              "bullet":129,
              "quotesinglbase":130,
              "florin":131,
              "quotedblbase":132,
              "ellipsis":133,
              "dagger":134,
              "daggerdbl":135,
              "circumflex":136,
              "perthousand":137,
              "Scaron":138,
              "guilsinglleft":139,
              "OE":140,
              "bullet":141,
              "Zcaron":142,
              "bullet":143,
              "bullet":144,
              "quoteleft":145,
              "quoteright":146,
              "quotedblleft":147,
              "quotedblright":148,
              "bullet":149,
              "endash":150,
              "emdash":151,
              "tilde":152,
              "trademark":153,
              "scaron":154,
              "guilsinglright":155,
              "oe":156,
              "bullet":157,
              "zcaron":158,
              "Ydieresis":159,
              "space":160,
              "exclamdown":161,
              "cent":162,
              "sterling":163,
              "currency":164,
              "yen":165,
              "brokenbar":166,
              "section":167,
              "dieresis":168,
              "copyright":169,
              "ordfeminine":170,
              "guillemotleft":171,
              "logicalnot":172,
              "hyphen":173,
              "registered":174,
              "macron":175,
              "degree":176,
              "plusminus":177,
              "twosuperior":178,
              "threesuperior":179,
              "acute":180,
              "mu":181,
              "paragraph":182,
              "periodcentered":183,
              "cedilla":184,
              "onesuperior":185,
              "ordmasculine":186,
              "guillemotright":187,
              "onequarter":188,
              "onehalf":189,
              "threequarters":190,
              "questiondown":191,
              "Agrave":192,
              "Aacute":193,
              "Acircumflex":194,
              "Atilde":195,
              "Adieresis":196,
              "Aring":197,
              "AE":198,
              "Ccedilla":199,
              "Egrave":200,
              "Eacute":201,
              "Ecircumflex":202,
              "Edieresis":203,
              "Igrave":204,
              "Iacute":205,
              "Icircumflex":206,
              "Idieresis":207,
              "Eth":208,
              "Ntilde":209,
              "Ograve":210,
              "Oacute":211,
              "Ocircumflex":212,
              "Otilde":213,
              "Odieresis":214,
              "multiply":215,
              "Oslash":216,
              "Ugrave":217,
              "Uacute":218,
              "Ucircumflex":219,
              "Udieresis":220,
              "Yacute":221,
              "Thorn":222,
              "germandbls":223,
              "agrave":224,
              "aacute":225,
              "acircumflex":226,
              "atilde":227,
              "adieresis":228,
              "aring":229,
              "ae":230,
              "ccedilla":231,
              "egrave":232,
              "eacute":233,
              "ecircumflex":234,
              "edieresis":235,
              "igrave":236,
              "iacute":237,
              "icircumflex":238,
              "idieresis":239,
              "eth":240,
              "ntilde":241,
              "ograve":242,
              "oacute":243,
              "ocircumflex":244,
              "otilde":245,
              "odieresis":246,
              "divide":247,
              "oslash":248,
              "ugrave":249,
              "uacute":250,
              "ucircumflex":251,
              "udieresis":252,
              "yacute":253,
              "thorn":254,
              "ydieresis":255}


fontbboxpattern = re.compile("/FontBBox\s*\{\s*(?P<fontbbox>(-?[0-9.]+)\s+(-?[0-9.]+)\s+(-?[0-9.]+)\s+(-?[0-9.]+))\s*\}\s*(readonly\s+)?def")


def _readNullString(file):
    s = []
    c = file.read(1)
    while c and c != "\0":
        s.append(c)
        c = file.read(1)
    return "".join(s)


class PFMfile(metric.metric):

    def __init__(self, file, t1file):
        # pfm is rather incomplete, the t1file instance can be used to fill the gap
        (self.dfVersion, self.dfSize, self.dfCopyright, self.dfType,
         self.dfPoint, self.dfVertRes, self.dfHorizRes, self.dfAscent,
         self.dfInternalLeading, self.dfExternalLeading, self.dfItalic,
         self.dfUnderline, self.dfStrikeOut, self.dfWeight,
         self.dfCharSet, self.dfPixWidth, self.dfPixHeight,
         self.dfPitchAndFamily, self.dfAvgWidth, self.dfMaxWidth,
         self.dfFirstChar, self.dfLastChar, self.dfDefaultChar,
         self.dfBreakChar, self.dfWidthBytes, self.dfDevice, self.dfFace,
         self.dfBitsPointer, self.dfBitsOffset) = struct.unpack("<HL60s7H3BHB2HB2H4BH4L", file.read(117))
        self.dfCopyright = self.dfCopyright.split("\000", 1)[0]
        (self.dfSizeFields, self.dfExtMetricsOffset, self.dfExtentTable,
         self.dfOriginTable, self.dfPairKernTable, self.dfTrackKernTable,
         self.dfDriverInfo, self.dfReserved) = struct.unpack("<H7L", file.read(30))
        if self.dfDevice == 0:
            raise ValueError("DeviceName is required for Type1 pfm files.")
        file.seek(self.dfDevice)
        self.deviceName = _readNullString(file)
        if self.deviceName.lower() != "postscript":
            raise ValueError("Can process pfm files for PostScript fonts only.")
        if self.dfVersion != 0x100:
            raise ValueError("Invalid pfm file version.")
        if self.dfType != 0x81:
            raise ValueError("Not a Type1 pfm file.")
        if self.dfFace == 0:
            raise ValueError("FaceName is required for Type1 pfm files.")
        if self.dfExtMetricsOffset == 0:
            raise ValueError("ExtTextMetrics is required for Type1 pfm files.")
        if self.dfExtentTable == 0:
            raise ValueError("ExtentTable is required for Type1 pfm files.")
        if self.dfOriginTable != 0:
            raise ValueError("OriginTable is forbidden for Type1 pfm files.")
        if self.dfDriverInfo == 0:
            raise ValueError("DriverInfo is required for Type1 pfm files.")
        # assert self.dfReserved == 0 (must be zero according to the spec, but we don't care)
        file.seek(self.dfExtMetricsOffset)
        (etmSize, self.etmPointSize, self.etmOrientation,
         self.etmMasterHeight, self.etmMinScale, self.etmMaxScale,
         self.etmMasterUnits, self.etmCapHeight, self.etmXHeight,
         self.etmLowerCaseAscent, self.etmLowerCaseDescent, self.etmSlant,
         self.etmSuperScript, self.etmSubScript, self.etmSuperScriptSize,
         self.etmSubScriptSize, self.etmUnderlineOffset,
         self.etmUnderlineWidth, self.etmDoubleUpperUnderlineOffset,
         self.etmDoubleLowerUnderlineOffset, self.etmDoubleUpperUnderlineWidth,
         self.etmDoubleLowerUnderlineWidth, self.etmStrikeOutOffset,
         self.etmStrikeOutWidth, self.etmKernPairs, self.etmKernTracks) = struct.unpack("<24h2H", file.read(52))
        file.seek(self.dfFace)
        self.faceName = _readNullString(file)
        file.seek(self.dfDriverInfo)
        self.driverInfo = _readNullString(file)
        file.seek(self.dfExtentTable)
        count = self.dfLastChar - self.dfFirstChar + 1
        self.widths = struct.unpack("<%dH" % count, file.read(2*count))
        self.kernpairs = []
        self.kernpairsdict = {}
        if self.dfPairKernTable:
            file.seek(self.dfPairKernTable)
            pairs, = struct.unpack("<H", file.read(2))
            if pairs != self.etmKernPairs:
                raise ValueError("number of kerning pairs mismatch in pfm file.")
            for i in range(self.etmKernPairs):
                kpFirst, kpSecond, kpKernAmount = struct.unpack("<BBh", file.read(4))
                self.kernpairs.append((kpFirst, kpSecond, kpKernAmount))
                self.kernpairsdict[(kpFirst, kpSecond)] = kpKernAmount
        self.trackkerns = []
        if self.dfTrackKernTable:
            file.seek(self.dfTrackKernTable)
            items, = struct.unpack("<H", file.read(2))
            if items != self.etmKernTracks:
                raise ValueError("number of kerning tracks mismatch in pfm file.")
            for i in range(self.etmKernTracks):
                # each item consists of the tuple ktDegree, ktMinSize, ktMinAmount, ktMaxSize, ktMaxAmount
                self.trackkerns.append(struct.unpack("<hhhhh", file.read(10)))
        if self.dfCharSet:
            if not t1file.encoding:
                t1file._encoding()
            self.glyphs = dict([(glyph, i) for i, glyph in enumerate(t1file.encoding) if glyph != None])
        else:
            self.glyphs = ansiglyphs
        self.t1file = t1file

    def width_ds(self, glyphname):
        return self.widths[self.glyphs[glyphname]-self.dfFirstChar]

    def width_pt(self, glyphnames, size_pt):
        return sum([self.widths[self.glyphs[glyphname]-self.dfFirstChar] for glyphname in glyphnames])*size_pt/1000.0

    def height_pt(self, glyphnames, size_pt):
        return self.dfAscent*size_pt/1000.0

    def depth_pt(self, glyphnames, size_pt):
        return -self.etmLowerCaseDescent*size_pt/1000.0

    def resolvekernings(self, glyphnames, size_pt=None):
        result = [None]*(2*len(glyphnames)-1)
        for i, glyphname in enumerate(glyphnames):
            result[2*i] = glyphname
        return result

    def resolvekernings(self, glyphnames, size_pt=None):
        result = [None]*(2*len(glyphnames)-1)
        for i, glyphname in enumerate(glyphnames):
            result[2*i] = glyphname
            if i:
                amount = self.kernpairsdict.get((self.glyphs[glyphnames[i-1]], self.glyphs[glyphname]))
                if amount:
                    if size_pt is not None:
                        result[2*i-1] = amount*size_pt/1000.0
                    else:
                        result[2*i-1] = amount
        return result

    def writePDFfontinfo(self, file, seriffont=False, symbolfont=True):
        flags = 0
        if self.dfMaxWidth == self.dfAvgWidth:
            flags += 1<<0
        if seriffont:
            flags += 1<<1
        if symbolfont:
            flags += 1<<2
        else:
            flags += 1<<5
        if self.dfItalic:
            flags += 1<<6
        file.write("/Flags %d\n" % flags)
        file.write("/ItalicAngles %d\n" % (self.etmSlant/10))
        file.write("/Ascent %d\n" % self.dfAscent)
        file.write("/Descent %d\n" % -self.etmLowerCaseDescent)
        file.write("/FontBBox [%s]\n" % fontbboxpattern.search(self.t1file.data1).groups('fontbbox')[0])
        file.write("/CapHeight %d\n" % self.etmCapHeight)
        if self.dfWeight >= 600:
            stemv = 120
        else:
            stemv = 70
        file.write("/StemV %d\n" % stemv)