*** empty log message ***
[lilypond/patrick.git] / buildscripts / substitute-encoding.py
blob6cb7f20cc1a314780b5695fedc5cd9a52640856d
1 #!@PYTHON@
3 # mess up the coding table of PFAemmentaler to work around
4 # GS bug,
6 # http://bugs.ghostscript.com/show_bug.cgi?id=688017
8 import getopt
9 import os
10 import re
11 import string
12 import sys
14 outdir = 'out'
15 (options, files) = getopt.getopt (sys.argv[1:], 'o', ['outdir='])
16 for opt in options:
17 o = opt[0]
18 a = opt[1]
19 if o == '--outdir' or o == '-o':
20 outdir = a
22 filename = files[0]
23 def get_glyph_names (enc_name):
24 enc_str = open (enc_name).read ()
25 glyphs = []
26 def note_glyph (match):
27 nm = match.group (1)
28 glyphs.append (nm)
31 m = re.sub ("(/[a-z.A-Z0-9_]+) %", note_glyph, enc_str )
33 glyphs = filter (lambda x: None == re.match (r'/\.notdef', x),
34 glyphs)
35 return glyphs
37 if re.search ('mmental', filename):
38 glyph_names = (get_glyph_names ('%(outdir)s/feta20.enc' % vars ())
39 + get_glyph_names ('%(outdir)s/feta-alphabet20.enc' % vars ())
40 + get_glyph_names ('%(outdir)s/parmesan20.enc' % vars ()))
42 str = open (filename).read ()
43 os.rename (filename, filename + "~")
45 glyph_names = glyph_names[:256]
47 put_glyphs = ''
48 i = 0
49 for g in glyph_names:
50 put_glyphs += 'dup %d %s put \n' % (i,g)
51 i += 1
53 str = re.sub ('( 0 1 255 { 1 index exch /.notdef put} for)',
54 '\\1 \n %s' % put_glyphs,
55 str)
56 str = re.sub ('StandardEncoding def',
57 '256 array\n0 1 255 { 1 index exch /.notdef put} for\n%sreadonly def' % put_glyphs,
58 str)
60 open (filename, 'w').write (str)