~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to lib/kformula/prototype/gensymbolfontmap.py

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import time
4
4
from xml.sax import saxutils, handler, make_parser
5
5
 
6
 
table = {}
 
6
unicodetable = { "normal":{}, "bold":{}, "italic":{},
 
7
                 "slant":{}, "boldItalic":{} }
 
8
fonttable = {}
7
9
 
8
10
class ContentGenerator(handler.ContentHandler):  
9
11
 
 
12
    def __init__(self):
 
13
        handler.ContentHandler.__init__(self)
 
14
        self.font = None
 
15
        
10
16
    def startElement(self, name, attrs):
11
 
        if name == 'entry':
 
17
        if name == 'unicodetable':
 
18
            self.font = None
 
19
            for (name, value) in attrs.items():
 
20
                if name == "font" and value:
 
21
                    self.font = value
 
22
                    if value not in fonttable:
 
23
                        fonttable[value] = []
 
24
        elif self.font and name == 'entry':
12
25
            number = ''
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
18
32
 
19
33
            if number != '':
20
 
                table[number] = (key, latexName, charClass)
21
 
 
22
 
 
23
 
def main():
24
 
    parser = make_parser()
25
 
    parser.setContentHandler(ContentGenerator())
26
 
    parser.parse("symbol.xml")
27
 
 
28
 
    f = open('../symbolfontmapping.cc', 'w')
29
 
    f.write('''//
 
34
                unicodetable[style][number] = (latexName, charClass)
 
35
                fonttable[self.font].append((key, number, style))
 
36
 
 
37
def fontkey(font, style, number):
 
38
    for mapping in fonttable[font]:
 
39
        k, n, s = mapping
 
40
        if s == style and n == number:
 
41
            return k
 
42
 
 
43
 
 
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)
 
50
            if pos:
 
51
                f.write('    { ' + key + ', ' + hex(pos) + ', ' + charClass + ', ' + style + 'Char },\n')
 
52
    f.write('    { 0, 0, ORDINARY, normalChar }\n};\n\n')
 
53
 
 
54
 
 
55
def write_header(f):
 
56
    print >>f, '''//
30
57
// Created: ''' + time.ctime(time.time()) + '''
31
58
//      by: gensymbolfontmap.py
32
59
//    from: symbol.xml
33
60
//
34
61
// WARNING! All changes made in this file will be lost!
35
 
 
36
 
''')
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('\\', '')
47
 
        else:
48
 
            latexName = '0'
49
 
        f.write('    { ' + key + ', ' + `pos` + ', ' + charClass + ', ' +
50
 
                latexName + ' },\n')
51
 
    f.write('    { 0, 0, ORDINARY, 0 }\n};\n\n')
52
 
 
53
 
    f.close()
54
 
 
 
62
'''
 
63
    
 
64
def main():
 
65
    f = open('../symbolfontmapping.cc', 'w')
 
66
    write_header(f)
 
67
    writeFontTable("symbol", f)
 
68
    f.close()
 
69
    
 
70
    f = open('../esstixfontmapping.cc', 'w')
 
71
    write_header(f)
 
72
    fontnames = [ "esstixnine", 
 
73
                  "esstixthirteen", 
 
74
                  "esstixeleven", 
 
75
                  "esstixfourteen", 
 
76
                  "esstixfive", 
 
77
                  "esstixfifteen", 
 
78
                  "esstixeight", 
 
79
                  "esstixthree", 
 
80
                  "esstixten", 
 
81
                  "esstixsixteen", 
 
82
                  "esstixone", 
 
83
                  "esstixtwo", 
 
84
                  "esstixsix", 
 
85
                  "esstixseven", 
 
86
                  "esstixtwelve", 
 
87
                  "esstixseventeen", 
 
88
                  "esstixfour" ]
 
89
    for fn in fontnames:
 
90
        writeFontTable(fn, f)
 
91
    f.close()
 
92
 
 
93
    f = open('../cmmapping.cc', 'w')
 
94
    write_header(f)
 
95
    fontnames = [ "cmbx10", 
 
96
                  "cmex10", 
 
97
                  "cmmi10", 
 
98
                  "cmr10", 
 
99
                  #"cmsl10", 
 
100
                  "cmsy10", 
 
101
                  #"cmti10", 
 
102
                  #"cmtt10", 
 
103
                  "msam10",
 
104
                  "msbm10"
 
105
                  ]
 
106
    for fn in fontnames:
 
107
        writeFontTable(fn, f)
 
108
    f.close()
 
109
 
 
110
    f = open('../unicodenames.cc', 'w')
 
111
    write_header(f)
 
112
    print >>f, 'struct UnicodeNameTable { short unicode; const char* name; };'
 
113
    print >>f, 'static UnicodeNameTable nameTable[] = {'
 
114
    nameDir = {}
 
115
    table = {}
 
116
    for style in unicodetable:
 
117
        table.update(unicodetable[style])
 
118
 
 
119
    for key in table:
 
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 + '" },'
 
125
                    #break
 
126
    print >>f, '    { 0, 0 }\n};'
 
127
    f.close()
 
128
    
 
129
 
 
130
   
 
131
def make_unicode_table():
 
132
    header = []
 
133
    codes = {}
 
134
    f = open('../config/unicode.tbl', 'r')
 
135
    for line in f.xreadlines():
 
136
        if line[0] == '#':
 
137
            header.append(line.strip())
 
138
        else:
 
139
            break
 
140
    for line in f.xreadlines():
 
141
        if len(line) > 0:
 
142
            codes[line.split(',')[0].strip()] = line
 
143
    f.close()
 
144
    
 
145
    for key in unicodetable:
 
146
        latexName, charClass = unicodetable[key]
 
147
        if len(latexName) > 0:
 
148
            codes[key] = key + ', ' + charClass + ', ' + latexName.replace('\\', '')
 
149
        else:
 
150
            codes[key] = key + ', ' + charClass
 
151
            
 
152
    f = open('../config/unicode.tbl', 'w')
 
153
    for line in header:
 
154
        print >> f, line
 
155
    for key in codes:
 
156
        print >> f, codes[key]
 
157
    f.close()
 
158
 
 
159
def make_font_table(font):
 
160
##    header = []
 
161
##    try:
 
162
##        f = open('../config/' + font + '.font', 'r')
 
163
##        for line in f.xreadlines():
 
164
##            if line[0] == '#':
 
165
##                header.append(line.strip())
 
166
##            else:
 
167
##                break
 
168
##        f.close()
 
169
##    except IOError:
 
170
##        pass
 
171
    
 
172
    #f = open('../config/' + font + '.font', 'w')
 
173
    f = open(font + '.font', 'w')
 
174
##    for line in header:
 
175
##        print >> f, line
 
176
    #print >> f, "name = " + font
 
177
    for key in unicodetable:
 
178
        latexName, charClass = unicodetable[key]
 
179
        pos = fontkey(font, key)
 
180
        if pos:
 
181
            print >> f, str(pos), key, charClass, latexName
 
182
    f.close()
 
183
 
 
184
def make_all_font_tables():
 
185
    for font in fonttable:
 
186
        make_font_table(font)
 
187
 
 
188
 
 
189
def symbol_entry(pos, unicode, charClass, name):
 
190
    return '    <entry key="%d" number="%s" name="%s" class="%s"/>' % \
 
191
           (pos, unicode, name, charClass)
 
192
 
 
193
 
 
194
def compare_font(font):
 
195
    for line in file(font+".font"):
 
196
        list = line.split()
 
197
        pos = int(list[0])
 
198
        unicode = list[1]
 
199
        charClass = list[2]
 
200
        if len(list)>3:
 
201
            name = list[3]
 
202
        else:
 
203
            name = ""
 
204
 
 
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)
 
213
 
 
214
def compare():
 
215
    fontnames = [ "symbol",
 
216
                  "esstixnine", 
 
217
                  "esstixthirteen", 
 
218
                  "esstixeleven", 
 
219
                  "esstixfourteen", 
 
220
                  "esstixfive", 
 
221
                  "esstixfifteen", 
 
222
                  "esstixeight", 
 
223
                  "esstixthree", 
 
224
                  "esstixten", 
 
225
                  "esstixsixteen", 
 
226
                  "esstixone", 
 
227
                  "esstixtwo", 
 
228
                  "esstixsix", 
 
229
                  "esstixseven", 
 
230
                  "esstixtwelve", 
 
231
                  "esstixseventeen", 
 
232
                  "esstixfour" ]
 
233
 
 
234
    for font in fontnames:
 
235
        compare_font(font)
 
236
 
 
237
        
55
238
if __name__ == '__main__':
 
239
    parser = make_parser()
 
240
    parser.setContentHandler(ContentGenerator())
 
241
    parser.parse("symbol.xml")
 
242
 
 
243
    #print fonttable
 
244
    #print unicodetable
 
245
 
 
246
    #compare()
 
247
    
56
248
    main()
 
249
    #make_unicode_table()
 
250
    #make_all_font_tables()