File: pilfont.py

package info (click to toggle)
python-imaging 1.1.7-4%2Bdeb7u2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,420 kB
  • sloc: ansic: 19,470; python: 11,012; makefile: 111
file content (56 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/python

#
# The Python Imaging Library
# $Id$
#
# PIL raster font compiler
#
# history:
# 1997-08-25 fl   created
# 2002-03-10 fl   use "from PIL import"
#

VERSION = "0.4"

import site
import glob, os, sys

# drivers
from PIL import BdfFontFile
from PIL import PcfFontFile

if len(sys.argv) <= 1:
    print "PILFONT", VERSION, "-- PIL font compiler."
    print
    print "Usage: pilfont fontfiles..."
    print
    print "Convert given font files to the PIL raster font format."
    print "This version of pilfont supports X BDF and PCF fonts."
    sys.exit(1)

files = []
for f in sys.argv[1:]:
    files = files + glob.glob(f)

for f in files:

    print f + "...",

    try:

        fp = open(f, "rb")

        try:
            p = PcfFontFile.PcfFontFile(fp)
        except SyntaxError:
            fp.seek(0)
            p = BdfFontFile.BdfFontFile(fp)

        p.save(f)

    except (SyntaxError, IOError):
        print "failed"

    else:
        print "OK"