update for HEAD-2003050101
[reactos.git] / lib / freetype / src / tools / docmaker / formatter.py
1 from sources import *
2 from content import *
3 from utils   import *
4
5 class Formatter:
6
7     def __init__( self, processor ):
8
9         self.processor   = processor
10         self.identifiers = {}
11         self.chapters    = processor.chapters
12         self.sections    = processor.sections.values()
13         self.block_index = []
14
15         # store all blocks in a dictionary
16         self.blocks      = []
17         for section in self.sections:
18             for block in section.blocks.values():
19                 self.add_identifier( block.name, block )
20                     
21                 # add enumeration values to the index, since this is useful
22                 for markup in block.markups:
23                     if markup.tag == 'values':
24                         for field in markup.fields:
25                             self.add_identifier( field.name, block )
26
27
28         self.block_index = self.identifiers.keys()
29         self.block_index.sort( index_sort )
30
31
32     def add_identifier( self, name, block ):
33         if self.identifiers.has_key( name ):
34             # duplicate name !!
35             sys.stderr.write( \
36                "WARNING: duplicate definition for '" + name + "' in " + \
37                block.location() + ", previous definition in " +         \
38                self.identifiers[ name ].location() + "\n" )
39         else:
40             self.identifiers[name] = block
41               
42
43     #
44     #  Formatting the table of contents
45     #
46
47     def  toc_enter( self ):
48         pass
49     
50     def  toc_chapter_enter( self, chapter ):
51         pass
52     
53     def  toc_section_enter( self, section ):
54         pass
55         
56     def  toc_section_exit( self, section ):
57         pass
58         
59     def  toc_chapter_exit( self, chapter ):
60         pass
61
62     def  toc_index( self, index_filename ):
63         pass
64     
65     def  toc_exit( self ):
66         pass
67
68     def  toc_dump( self, toc_filename = None, index_filename = None ):
69         
70         output = None
71         if toc_filename:
72             output = open_output( toc_filename )
73         
74         self.toc_enter()
75     
76         for chap in self.processor.chapters:
77     
78             self.toc_chapter_enter( chap )
79     
80             for section in chap.sections:
81                 self.toc_section_enter( section )
82                 self.toc_section_exit( section )
83     
84             self.toc_chapter_exit ( chap )
85     
86         self.toc_index( index_filename )
87     
88         self.toc_exit()
89
90         if output:
91             close_output( output )
92     
93     #
94     #  Formatting the index
95     #
96
97     def  index_enter( self ):
98         pass
99
100     def  index_name_enter( self, name ):
101         pass
102
103     def  index_name_exit( self, name ):
104         pass
105
106     def  index_exit( self ):
107         pass
108
109     def  index_dump( self, index_filename = None ):
110         
111         output = None
112         if index_filename:
113             output = open_output( index_filename )
114
115         self.index_enter()
116
117         for name in self.block_index:
118             self.index_name_enter( name )
119             self.index_name_exit ( name )
120
121         self.index_exit()
122      
123         if output:
124             close_output( output )
125      
126     #
127     #  Formatting a section
128     #
129     def  section_enter( self, section ):
130         pass
131     
132     def  block_enter( self, block ):
133         pass
134     
135     def  markup_enter( self, markup, block = None ):
136         pass
137     
138     def  field_enter( self, field, markup = None, block = None ):
139         pass
140         
141     def  field_exit( self, field, markup = None, block = None ):
142         pass
143     
144     def  markup_exit( self, markup, block = None ):
145         pass
146         
147     def  block_exit( self, block ):
148         pass
149
150     def  section_exit( self, section ):
151         pass
152
153
154     def  section_dump( self, section, section_filename = None ):
155         
156         output = None
157         if section_filename:
158             output = open_output( section_filename )
159         
160         self.section_enter( section )
161
162         for name in section.block_names:
163             block = self.identifiers[ name ]
164             self.block_enter( block )
165
166             for markup in block.markups[1:]:   # always ignore first markup !!
167                 self.markup_enter( markup, block )
168
169                 for field in markup.fields:
170                     self.field_enter( field, markup, block )
171
172                     self.field_exit ( field, markup, block )
173
174                 self.markup_exit( markup, block )
175
176             self.block_exit( block )
177
178         self.section_exit ( section )
179
180         if output:
181             close_output( output )
182
183
184     def section_dump_all( self ):
185         for section in self.sections:
186             self.section_dump( section )
187
188     #
189     #  Formatting a block
190     #
191
192
193
194