]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/substitute-encoding.py
* buildscripts/substitute-encoding.py: Handle PFAemmentaler-xx.pfa
[lilypond.git] / buildscripts / substitute-encoding.py
1 #!@PYTHON@
2 #
3 # mess up the coding table of PFAemmentaler to work around
4 # GS bug,
5 #
6 # http://bugs.ghostscript.com/show_bug.cgi?id=688017
7
8 import getopt
9 import os
10 import re
11 import string
12 import sys
13
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
21
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)
29
30
31         m = re.sub ("(/[a-z-.A-Z0-9]+) %", note_glyph, enc_str )
32
33         glyphs = filter (lambda x: None == re.match (r'/\.notdef', x),
34                          glyphs)
35         return glyphs
36
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 ()))
41
42         str = open (filename).read ()
43         os.rename (filename, filename + "~")
44
45         glyph_names = glyph_names[:256]
46         
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
52                 
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)
59
60         open (filename, 'w').write (str)