~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/freetype/src/tools/docmaker/tohtml.py

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from sources import *
 
2
from content import *
 
3
from formatter import *
 
4
 
 
5
import time
 
6
 
 
7
# The following defines the HTML header used by all generated pages.
 
8
#
 
9
html_header_1 = """\
 
10
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
 
11
"http://www.w3.org/TR/html4/loose.dtd">
 
12
<html>
 
13
<head>
 
14
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
15
<title>"""
 
16
 
 
17
html_header_2= """ API Reference</title>
 
18
<style type="text/css">
 
19
  body { font-family: Verdana, Geneva, Arial, Helvetica, serif;
 
20
         color: #000000;
 
21
         background: #FFFFFF; }
 
22
 
 
23
  p { text-align: justify; }
 
24
  h1 { text-align: center; }
 
25
  li { text-align: justify; }
 
26
 
 
27
  a:link { color: #0000EF; }
 
28
  a:visited { color: #51188E; }
 
29
  a:hover { color: #FF0000; }
 
30
 
 
31
  span.keyword { font-family: monospace;
 
32
                 text-align: left;
 
33
                 white-space: pre;
 
34
                 color: darkblue; }
 
35
 
 
36
  pre.colored { color: blue; }
 
37
 
 
38
  ul.empty { list-style-type: none; }
 
39
</style>
 
40
</head>
 
41
<body>
 
42
<center><h1>"""
 
43
 
 
44
html_header_3=""" API Reference</h1></center>
 
45
"""
 
46
 
 
47
 
 
48
 
 
49
# The HTML footer used by all generated pages.
 
50
#
 
51
html_footer = """\
 
52
</body>
 
53
</html>"""
 
54
 
 
55
# The header and footer used for each section.
 
56
#
 
57
section_title_header = "<center><h1>"
 
58
section_title_footer = "</h1></center>"
 
59
 
 
60
# The header and footer used for code segments.
 
61
#
 
62
code_header = '<pre class="colored">'
 
63
code_footer = '</pre>'
 
64
 
 
65
# Paragraph header and footer.
 
66
#
 
67
para_header = "<p>"
 
68
para_footer = "</p>"
 
69
 
 
70
# Block header and footer.
 
71
#
 
72
block_header = '<table align=center width="75%"><tr><td>'
 
73
block_footer = '</td></tr></table><hr width="75%">'
 
74
 
 
75
# Description header/footer.
 
76
#
 
77
description_header = '<table align=center width="87%"><tr><td>'
 
78
description_footer = "</td></tr></table><br>"
 
79
 
 
80
# Marker header/inter/footer combination.
 
81
#
 
82
marker_header = '<table align=center width="87%" cellpadding=5><tr bgcolor="#EEEEFF"><td><em><b>'
 
83
marker_inter  = "</b></em></td></tr><tr><td>"
 
84
marker_footer = "</td></tr></table>"
 
85
 
 
86
# Source code extracts header/footer.
 
87
#
 
88
source_header = '<table align=center width="87%"><tr bgcolor="#D6E8FF"><td><pre>\n'
 
89
source_footer = "\n</pre></table><br>"
 
90
 
 
91
# Chapter header/inter/footer.
 
92
#
 
93
chapter_header = '<br><table align=center width="75%"><tr><td><h2>'
 
94
chapter_inter  = '</h2><ul class="empty"><li>'
 
95
chapter_footer = '</li></ul></td></tr></table>'
 
96
 
 
97
 
 
98
# source language keyword coloration/styling
 
99
#
 
100
keyword_prefix = '<span class="keyword">'
 
101
keyword_suffix = '</span>'
 
102
 
 
103
section_synopsis_header = '<h2>Synopsis</h2>'
 
104
section_synopsis_footer = ''
 
105
 
 
106
# Translate a single line of source to HTML.  This will convert
 
107
# a "<" into "&lt.", ">" into "&gt.", etc.
 
108
#
 
109
def html_quote( line ):
 
110
    result = string.replace( line,   "&", "&amp;" )
 
111
    result = string.replace( result, "<", "&lt;" )
 
112
    result = string.replace( result, ">", "&gt;" )
 
113
    return result
 
114
 
 
115
 
 
116
# same as 'html_quote', but ignores left and right brackets
 
117
#
 
118
def html_quote0( line ):
 
119
    return string.replace( line, "&", "&amp;" )
 
120
 
 
121
 
 
122
def dump_html_code( lines, prefix = "" ):
 
123
    # clean the last empty lines
 
124
    #
 
125
    l = len( self.lines )
 
126
    while l > 0 and string.strip( self.lines[l - 1] ) == "":
 
127
        l = l - 1
 
128
 
 
129
    # The code footer should be directly appended to the last code
 
130
    # line to avoid an additional blank line.
 
131
    #
 
132
    print prefix + code_header,
 
133
    for line in self.lines[0 : l+1]:
 
134
        print '\n' + prefix + html_quote(line),
 
135
    print prefix + code_footer,
 
136
 
 
137
 
 
138
 
 
139
class HtmlFormatter(Formatter):
 
140
 
 
141
    def __init__( self, processor, project_title, file_prefix ):
 
142
 
 
143
        Formatter.__init__( self, processor )
 
144
 
 
145
        global html_header_1, html_header_2, html_header_3, html_footer
 
146
 
 
147
        if file_prefix:
 
148
            file_prefix = file_prefix + "-"
 
149
        else:
 
150
            file_prefix = ""
 
151
 
 
152
        self.project_title = project_title
 
153
        self.file_prefix   = file_prefix
 
154
        self.html_header   = html_header_1 + project_title + html_header_2 + \
 
155
                             project_title + html_header_3
 
156
 
 
157
        self.html_footer = "<center><font size=""-2"">generated on " +   \
 
158
                            time.asctime( time.localtime( time.time() ) ) + \
 
159
                           "</font></center>" + html_footer
 
160
 
 
161
        self.columns = 3
 
162
 
 
163
    def  make_section_url( self, section ):
 
164
        return self.file_prefix + section.name + ".html"
 
165
 
 
166
 
 
167
    def  make_block_url( self, block ):
 
168
        return self.make_section_url( block.section ) + "#" + block.name
 
169
 
 
170
 
 
171
    def  make_html_words( self, words ):
 
172
        """ convert a series of simple words into some HTML text """
 
173
        line = ""
 
174
        if words:
 
175
            line = html_quote( words[0] )
 
176
            for w in words[1:]:
 
177
                line = line + " " + html_quote( w )
 
178
 
 
179
        return line
 
180
 
 
181
 
 
182
    def  make_html_word( self, word ):
 
183
        """analyze a simple word to detect cross-references and styling"""
 
184
        # look for cross-references
 
185
        #
 
186
        m = re_crossref.match( word )
 
187
        if m:
 
188
            try:
 
189
                name = m.group(1)
 
190
                rest = m.group(2)
 
191
                block = self.identifiers[ name ]
 
192
                url   = self.make_block_url( block )
 
193
                return '<a href="' + url + '">' + name + '</a>' + rest
 
194
            except:
 
195
                return '?' + name + '?' + rest
 
196
 
 
197
        # look for italics and bolds
 
198
        m = re_italic.match( word )
 
199
        if m:
 
200
            name = m.group(1)
 
201
            return '<i>'+name+'</i>'
 
202
 
 
203
        m = re_bold.match( word )
 
204
        if m:
 
205
            name = m.group(1)
 
206
            return '<b>'+name+'</b>'
 
207
 
 
208
        return html_quote(word)
 
209
 
 
210
 
 
211
    def  make_html_para( self, words ):
 
212
        """ convert a paragraph's words into tagged HTML text, handle xrefs """
 
213
        line = ""
 
214
        if words:
 
215
            line = self.make_html_word( words[0] )
 
216
            for word in words[1:]:
 
217
                line = line + " " + self.make_html_word( word )
 
218
 
 
219
        return "<p>" + line + "</p>"
 
220
 
 
221
 
 
222
    def  make_html_code( self, lines ):
 
223
        """ convert a code sequence to HTML """
 
224
        line = code_header + '\n'
 
225
        for l in lines:
 
226
            line = line + html_quote( l ) + '\n'
 
227
 
 
228
        return line + code_footer
 
229
 
 
230
 
 
231
    def  make_html_items( self, items ):
 
232
        """ convert a field's content into some valid HTML """
 
233
        lines = []
 
234
        for item in items:
 
235
            if item.lines:
 
236
                lines.append( self.make_html_code( item.lines ) )
 
237
            else:
 
238
                lines.append( self.make_html_para( item.words ) )
 
239
 
 
240
        return string.join( lines, '\n' )
 
241
 
 
242
 
 
243
    def  print_html_items( self, items ):
 
244
        print self.make_html_items( items )
 
245
 
 
246
 
 
247
    def print_html_field( self, field ):
 
248
        if field.name:
 
249
            print "<table><tr valign=top><td><b>"+field.name+"</b></td><td>"
 
250
 
 
251
        print self.make_html_items( field.items )
 
252
 
 
253
        if field.name:
 
254
            print "</td></tr></table>"
 
255
 
 
256
 
 
257
    def html_source_quote( self, line, block_name = None ):
 
258
        result = ""
 
259
        while line:
 
260
            m = re_source_crossref.match( line )
 
261
            if m:
 
262
                name   = m.group(2)
 
263
                prefix = html_quote( m.group(1) )
 
264
                length = len( m.group(0) )
 
265
 
 
266
                if name == block_name:
 
267
                    # this is the current block name, if any
 
268
                    result = result + prefix + '<b>' + name + '</b>'
 
269
 
 
270
                elif re_source_keywords.match(name):
 
271
                    # this is a C keyword
 
272
                    result = result + prefix + keyword_prefix + name + keyword_suffix
 
273
 
 
274
                elif self.identifiers.has_key(name):
 
275
                    # this is a known identifier
 
276
                    block = self.identifiers[name]
 
277
                    result = result + prefix + '<a href="' + \
 
278
                             self.make_block_url(block) + '">' + name + '</a>'
 
279
                else:
 
280
                    result = result + html_quote(line[ : length ])
 
281
 
 
282
                line = line[ length : ]
 
283
            else:
 
284
                result = result + html_quote(line)
 
285
                line   = []
 
286
 
 
287
        return result
 
288
 
 
289
 
 
290
    def print_html_field_list( self, fields ):
 
291
        print "<table cellpadding=3>"
 
292
        for field in fields:
 
293
            print "<tr valign=top><td><b>" + field.name + "</b></td><td>"
 
294
            self.print_html_items( field.items )
 
295
            print "</td></tr>"
 
296
        print "</table>"
 
297
 
 
298
 
 
299
    def print_html_markup( self, markup ):
 
300
        table_fields = []
 
301
        for field in markup.fields:
 
302
            if field.name:
 
303
                # we begin a new series of field or value definitions, we
 
304
                # will record them in the 'table_fields' list before outputting
 
305
                # all of them as a single table
 
306
                #
 
307
                table_fields.append( field )
 
308
 
 
309
            else:
 
310
                if table_fields:
 
311
                    self.print_html_field_list( table_fields )
 
312
                    table_fields = []
 
313
 
 
314
                self.print_html_items( field.items )
 
315
 
 
316
        if table_fields:
 
317
            self.print_html_field_list( table_fields )
 
318
 
 
319
    #
 
320
    #  Formatting the index
 
321
    #
 
322
 
 
323
    def  index_enter( self ):
 
324
        print self.html_header
 
325
        self.index_items = {}
 
326
 
 
327
    def  index_name_enter( self, name ):
 
328
        block = self.identifiers[ name ]
 
329
        url   = self.make_block_url( block )
 
330
        self.index_items[ name ] = url
 
331
 
 
332
    def  index_exit( self ):
 
333
 
 
334
        # block_index already contains the sorted list of index names
 
335
        count = len( self.block_index )
 
336
        rows  = (count + self.columns - 1)/self.columns
 
337
 
 
338
        print "<table align=center border=0 cellpadding=0 cellspacing=0>"
 
339
        for r in range(rows):
 
340
            line = "<tr>"
 
341
            for c in range(self.columns):
 
342
                i = r + c*rows
 
343
                if i < count:
 
344
                    bname = self.block_index[ r + c*rows ]
 
345
                    url   = self.index_items[ bname ]
 
346
                    line = line + '<td><a href="' + url + '">' + bname + '</a></td>'
 
347
                else:
 
348
                    line = line + '<td></td>'
 
349
            line = line + "</tr>"
 
350
            print line
 
351
 
 
352
        print "</table>"
 
353
        print self.html_footer
 
354
        self.index_items = {}
 
355
 
 
356
    def  index_dump( self, index_filename = None ):
 
357
 
 
358
        if index_filename == None:
 
359
            index_filename = self.file_prefix + "index.html"
 
360
 
 
361
        Formatter.index_dump( self, index_filename )
 
362
 
 
363
    #
 
364
    #  Formatting the table of content
 
365
    #
 
366
    def  toc_enter( self ):
 
367
        print self.html_header
 
368
        print "<center><h1>Table of Contents</h1></center>"
 
369
 
 
370
    def  toc_chapter_enter( self, chapter ):
 
371
        print  chapter_header + string.join(chapter.title) + chapter_inter
 
372
        print "<table cellpadding=5>"
 
373
 
 
374
    def  toc_section_enter( self, section ):
 
375
        print "<tr valign=top><td>"
 
376
        print '<a href="' + self.make_section_url( section ) + '">' + \
 
377
               section.title + '</a></td><td>'
 
378
 
 
379
        print self.make_html_para( section.abstract )
 
380
 
 
381
    def  toc_section_exit( self, section ):
 
382
        print "</td></tr>"
 
383
 
 
384
    def  toc_chapter_exit( self, chapter ):
 
385
        print "</table>"
 
386
        print  chapter_footer
 
387
 
 
388
    def  toc_index( self, index_filename ):
 
389
        print chapter_header + '<a href="' + index_filename + '">Global Index</a>' + chapter_inter + chapter_footer
 
390
 
 
391
    def  toc_exit( self ):
 
392
        print self.html_footer
 
393
 
 
394
    def  toc_dump( self, toc_filename = None, index_filename = None ):
 
395
        if toc_filename == None:
 
396
            toc_filename = self.file_prefix + "toc.html"
 
397
 
 
398
        if index_filename == None:
 
399
            index_filename = self.file_prefix + "index.html"
 
400
 
 
401
        Formatter.toc_dump( self, toc_filename, index_filename )
 
402
 
 
403
    #
 
404
    #  Formatting sections
 
405
    #
 
406
    def  section_enter( self, section ):
 
407
        print self.html_header
 
408
 
 
409
        print section_title_header
 
410
        print section.title
 
411
        print section_title_footer
 
412
 
 
413
        # print section synopsys
 
414
        print section_synopsis_header
 
415
        print "<table align=center cellspacing=5 cellpadding=0 border=0>"
 
416
 
 
417
        maxwidth = 0
 
418
        for b in section.blocks.values():
 
419
            if len(b.name) > maxwidth:
 
420
                maxwidth = len(b.name)
 
421
 
 
422
        width  = 70  # XXX magic number
 
423
        columns = width / maxwidth
 
424
        if columns < 1:
 
425
            columns = 1
 
426
 
 
427
        count   = len(section.block_names)
 
428
        rows    = (count + columns-1)/columns
 
429
        for r in range(rows):
 
430
            line = "<tr>"
 
431
            for c in range(columns):
 
432
                i = r + c*rows
 
433
                line = line + '<td></td><td>'
 
434
                if i < count:
 
435
                    name = section.block_names[i]
 
436
                    line = line + '<a href="#' + name + '">' + name + '</a>'
 
437
 
 
438
                line = line + '</td>'
 
439
            line = line + "</tr>"
 
440
            print line
 
441
 
 
442
        print "</table><br><br>"
 
443
        print section_synopsis_footer
 
444
 
 
445
        print description_header
 
446
        print self.make_html_items( section.description )
 
447
        print description_footer
 
448
 
 
449
    def  block_enter( self, block ):
 
450
        print block_header
 
451
 
 
452
        # place html anchor if needed
 
453
        if block.name:
 
454
            print '<h4><a name="' + block.name + '">' + block.name + '</a></h4>'
 
455
 
 
456
        # dump the block C source lines now
 
457
        if block.code:
 
458
            print source_header
 
459
            for l in block.code:
 
460
                print self.html_source_quote( l, block.name )
 
461
            print source_footer
 
462
 
 
463
 
 
464
    def  markup_enter( self, markup, block ):
 
465
        if markup.tag == "description":
 
466
            print description_header
 
467
        else:
 
468
            print marker_header + markup.tag + marker_inter
 
469
 
 
470
        self.print_html_markup( markup )
 
471
 
 
472
    def  markup_exit( self, markup, block ):
 
473
        if markup.tag == "description":
 
474
            print description_footer
 
475
        else:
 
476
            print marker_footer
 
477
 
 
478
    def  block_exit( self, block ):
 
479
        print block_footer
 
480
 
 
481
 
 
482
    def  section_exit( self, section ):
 
483
        print html_footer
 
484
 
 
485
 
 
486
    def section_dump_all( self ):
 
487
        for section in self.sections:
 
488
            self.section_dump( section, self.file_prefix + section.name + '.html' )
 
489