4
4
from xml.sax import saxutils, handler, make_parser
6
unicodetable = { "normal":{}, "bold":{}, "italic":{},
7
"slant":{}, "boldItalic":{} }
8
10
class ContentGenerator(handler.ContentHandler):
13
handler.ContentHandler.__init__(self)
10
16
def startElement(self, name, attrs):
17
if name == 'unicodetable':
19
for (name, value) in attrs.items():
20
if name == "font" and value:
22
if value not in fonttable:
24
elif self.font and name == 'entry':
13
26
for (name, value) in attrs.items():
14
27
if name == "key": key = int(value)
15
28
elif name == "number": number = value
16
29
elif name == "name": latexName = value
17
30
elif name == "class": charClass = value
31
elif name == "style": style = value
20
table[number] = (key, latexName, charClass)
24
parser = make_parser()
25
parser.setContentHandler(ContentGenerator())
26
parser.parse("symbol.xml")
28
f = open('../symbolfontmapping.cc', 'w')
34
unicodetable[style][number] = (latexName, charClass)
35
fonttable[self.font].append((key, number, style))
37
def fontkey(font, style, number):
38
for mapping in fonttable[font]:
40
if s == style and n == number:
44
def writeFontTable(fontname, f):
45
f.write('\n\nstatic InternFontTable ' + fontname + 'Map[] = {\n')
46
for style in unicodetable:
47
for key in unicodetable[style]:
48
latexName, charClass = unicodetable[style][key]
49
pos = fontkey(fontname, style, key)
51
f.write(' { ' + key + ', ' + hex(pos) + ', ' + charClass + ', ' + style + 'Char },\n')
52
f.write(' { 0, 0, ORDINARY, normalChar }\n};\n\n')
30
57
// Created: ''' + time.ctime(time.time()) + '''
31
58
// by: gensymbolfontmap.py
32
59
// from: symbol.xml
34
61
// WARNING! All changes made in this file will be lost!
37
for key in table.keys():
38
pos, latexName, charClass = table[key]
39
if len(latexName) > 0:
40
f.write('char symbolFontMap_' + latexName.replace('\\', '') + '[] = "' +
41
latexName.replace('\\', '\\\\') + '";\n' )
42
f.write('\nstruct { int unicode; uchar pos; CharClass cl; char* latexName; } symbolFontMap[] = {\n')
43
for key in table.keys():
44
pos, latexName, charClass = table[key]
45
if len(latexName) > 0:
46
latexName = 'symbolFontMap_' + latexName.replace('\\', '')
49
f.write(' { ' + key + ', ' + `pos` + ', ' + charClass + ', ' +
51
f.write(' { 0, 0, ORDINARY, 0 }\n};\n\n')
65
f = open('../symbolfontmapping.cc', 'w')
67
writeFontTable("symbol", f)
70
f = open('../esstixfontmapping.cc', 'w')
72
fontnames = [ "esstixnine",
93
f = open('../cmmapping.cc', 'w')
95
fontnames = [ "cmbx10",
107
writeFontTable(fn, f)
110
f = open('../unicodenames.cc', 'w')
112
print >>f, 'struct UnicodeNameTable { short unicode; const char* name; };'
113
print >>f, 'static UnicodeNameTable nameTable[] = {'
116
for style in unicodetable:
117
table.update(unicodetable[style])
120
latexName, charClass = table[key]
121
if len(latexName) > 0:
122
#for fn in fontnames:
123
# if fontkey(fn, style, key):
124
print >>f, ' { ' + key + ', "' + latexName + '" },'
126
print >>f, ' { 0, 0 }\n};'
131
def make_unicode_table():
134
f = open('../config/unicode.tbl', 'r')
135
for line in f.xreadlines():
137
header.append(line.strip())
140
for line in f.xreadlines():
142
codes[line.split(',')[0].strip()] = line
145
for key in unicodetable:
146
latexName, charClass = unicodetable[key]
147
if len(latexName) > 0:
148
codes[key] = key + ', ' + charClass + ', ' + latexName.replace('\\', '')
150
codes[key] = key + ', ' + charClass
152
f = open('../config/unicode.tbl', 'w')
156
print >> f, codes[key]
159
def make_font_table(font):
162
## f = open('../config/' + font + '.font', 'r')
163
## for line in f.xreadlines():
164
## if line[0] == '#':
165
## header.append(line.strip())
172
#f = open('../config/' + font + '.font', 'w')
173
f = open(font + '.font', 'w')
174
## for line in header:
176
#print >> f, "name = " + font
177
for key in unicodetable:
178
latexName, charClass = unicodetable[key]
179
pos = fontkey(font, key)
181
print >> f, str(pos), key, charClass, latexName
184
def make_all_font_tables():
185
for font in fonttable:
186
make_font_table(font)
189
def symbol_entry(pos, unicode, charClass, name):
190
return ' <entry key="%d" number="%s" name="%s" class="%s"/>' % \
191
(pos, unicode, name, charClass)
194
def compare_font(font):
195
for line in file(font+".font"):
205
if (pos, unicode) not in fonttable[font]:
206
print "not in font", font, (pos, unicode)
207
print symbol_entry(pos, unicode, charClass, name)
208
if unicode not in unicodetable:
209
print font, unicode, (name, charClass)
210
print symbol_entry(pos, unicode, charClass, name)
211
elif unicodetable[unicode] != (name, charClass):
212
print font, unicode, pos, unicodetable[unicode], "!=", (name, charClass)
215
fontnames = [ "symbol",
234
for font in fontnames:
55
238
if __name__ == '__main__':
239
parser = make_parser()
240
parser.setContentHandler(ContentGenerator())
241
parser.parse("symbol.xml")
249
#make_unicode_table()
250
#make_all_font_tables()