2
# -*- coding: ISO-8859-1 -*-
5
# Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
def pfblength(string):
30
raise ValueError("invalid string length")
31
return (ord(string[0]) +
33
ord(string[2])*256*256 +
34
ord(string[3])*256*256*256)
36
def fullfont(file, filename):
37
"""inserts full pfa or pfb fonts
38
- file is a file instance where the pfa output is written to
39
- pfbfilename is the full filename of the pfa or pfb input file
40
- the input type pfa or pfb is autodetected"""
42
infile = open(filename, "rb")
43
blockid = infile.read(2)
46
file.write(infile.read().replace("\r\n", "\n").replace("\r", "\n"))
50
raise RuntimeError("EOF reached while reading blockid")
51
if blockid == _PFB_DONE:
52
if infile.read() != "":
53
raise RuntimeError("trailing characters in pfb file")
56
if blockid != _PFB_ASCII and blockid != _PFB_BIN:
57
raise RuntimeError("invalid blockid")
58
length = pfblength(infile.read(4))
59
block = infile.read(length)
60
if blockid == _PFB_ASCII:
61
file.write(block.replace("\r\n", "\n").replace("\r", "\n"))
63
block = [ord(c) for c in block]
64
while len(block) > 32:
65
file.write("%02x"*32 % tuple(block[:32]) + "\n")
68
file.write("%02x"*len(block) % tuple(block) + "\n")
69
blockid = infile.read(2)