zenilib: zenilib/jni/external/freetype2/src/tools/docmaker/formatter.py Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
formatter.py
Go to the documentation of this file.
1 # Formatter (c) 2002, 2004, 2007, 2008 David Turner <david@freetype.org>
2 #
3
4 from sources import *
5 from content import *
6 from utils import *
7
8 # This is the base Formatter class. Its purpose is to convert
9 # a content processor's data into specific documents (i.e., table of
10 # contents, global index, and individual API reference indices).
11 #
12 # You need to sub-class it to output anything sensible. For example,
13 # the file tohtml.py contains the definition of the HtmlFormatter sub-class
14 # used to output -- you guessed it -- HTML.
15 #
16
17 class Formatter:
18
19 def __init__( self, processor ):
20 self.processor = processor
21 self.identifiers = {}
22 self.chapters = processor.chapters
23 self.sections = processor.sections.values()
24 self.block_index = []
25
26 # store all blocks in a dictionary
27 self.blocks = []
28 for section in self.sections:
29 for block in section.blocks.values():
30 self.add_identifier( block.name, block )
31
32 # add enumeration values to the index, since this is useful
33 for markup in block.markups:
34 if markup.tag == 'values':
35 for field in markup.fields:
36 self.add_identifier( field.name, block )
37
38 self.block_index = self.identifiers.keys()
39 self.block_index.sort( index_sort )
40
41 def add_identifier( self, name, block ):
42 if self.identifiers.has_key( name ):
43 # duplicate name!
44 sys.stderr.write( \
45 "WARNING: duplicate definition for '" + name + "' in " + \
46 block.location() + ", previous definition in " + \
47 self.identifiers[name].location() + "\n" )
48 else:
49 self.identifiers[name] = block
50
51 #
52 # Formatting the table of contents
53 #
54 def toc_enter( self ):
55 pass
56
57 def toc_chapter_enter( self, chapter ):
58 pass
59
60 def toc_section_enter( self, section ):
61 pass
62
63 def toc_section_exit( self, section ):
64 pass
65
66 def toc_chapter_exit( self, chapter ):
67 pass
68
69 def toc_index( self, index_filename ):
70 pass
71
72 def toc_exit( self ):
73 pass
74
75 def toc_dump( self, toc_filename = None, index_filename = None ):
76 output = None
77 if toc_filename:
78 output = open_output( toc_filename )
79
80 self.toc_enter()
81
82 for chap in self.processor.chapters:
83
84 self.toc_chapter_enter( chap )
85
86 for section in chap.sections:
87 self.toc_section_enter( section )
88 self.toc_section_exit( section )
89
90 self.toc_chapter_exit( chap )
91
92 self.toc_index( index_filename )
93
94 self.toc_exit()
95
96 if output:
97 close_output( output )
98
99 #
100 # Formatting the index
101 #
102 def index_enter( self ):
103 pass
104
105 def index_name_enter( self, name ):
106 pass
107
108 def index_name_exit( self, name ):
109 pass
110
111 def index_exit( self ):
112 pass
113
114 def index_dump( self, index_filename = None ):
115 output = None
116 if index_filename:
117 output = open_output( index_filename )
118
119 self.index_enter()
120
121 for name in self.block_index:
122 self.index_name_enter( name )
123 self.index_name_exit( name )
124
125 self.index_exit()
126
127 if output:
128 close_output( output )
129
130 #
131 # Formatting a section
132 #
133 def section_enter( self, section ):
134 pass
135
136 def block_enter( self, block ):
137 pass
138
139 def markup_enter( self, markup, block = None ):
140 pass
141
142 def field_enter( self, field, markup = None, block = None ):
143 pass
144
145 def field_exit( self, field, markup = None, block = None ):
146 pass
147
148 def markup_exit( self, markup, block = None ):
149 pass
150
151 def block_exit( self, block ):
152 pass
153
154 def section_exit( self, section ):
155 pass
156
157 def section_dump( self, section, section_filename = None ):
158 output = None
159 if section_filename:
160 output = open_output( section_filename )
161
162 self.section_enter( section )
163
164 for name in section.block_names:
165 block = self.identifiers[name]
166 self.block_enter( block )
167
168 for markup in block.markups[1:]: # always ignore first markup!
169 self.markup_enter( markup, block )
170
171 for field in markup.fields:
172 self.field_enter( field, markup, block )
173 self.field_exit( field, markup, block )
174
175 self.markup_exit( markup, block )
176
177 self.block_exit( block )
178
179 self.section_exit( section )
180
181 if output:
182 close_output( output )
183
184 def section_dump_all( self ):
185 for section in self.sections:
186 self.section_dump( section )
187
188 # eof
formatter.Formatter.block_enter
def block_enter
Definition: formatter.py:136
formatter.Formatter.add_identifier
def add_identifier
Definition: formatter.py:41
utils.open_output
def open_output
Definition: utils.py:59
formatter.Formatter
Definition: formatter.py:17
formatter.Formatter.toc_chapter_enter
def toc_chapter_enter
Definition: formatter.py:57
formatter.Formatter.toc_dump
def toc_dump
Definition: formatter.py:75
formatter.Formatter.toc_section_exit
def toc_section_exit
Definition: formatter.py:63
formatter.Formatter.__init__
def __init__
Definition: formatter.py:19
formatter.Formatter.index_enter
def index_enter
Definition: formatter.py:102
formatter.Formatter.section_dump
def section_dump
Definition: formatter.py:157
formatter.Formatter.markup_exit
def markup_exit
Definition: formatter.py:148
formatter.Formatter.index_exit
def index_exit
Definition: formatter.py:111
formatter.Formatter.block_exit
def block_exit
Definition: formatter.py:151
formatter.Formatter.toc_section_enter
def toc_section_enter
Definition: formatter.py:60
formatter.Formatter.chapters
chapters
Definition: formatter.py:22
formatter.Formatter.identifiers
identifiers
Definition: formatter.py:21
formatter.Formatter.toc_chapter_exit
def toc_chapter_exit
Definition: formatter.py:66
formatter.Formatter.index_dump
def index_dump
Definition: formatter.py:114
formatter.Formatter.section_exit
def section_exit
Definition: formatter.py:154
formatter.Formatter.block_index
block_index
Definition: formatter.py:24
formatter.Formatter.section_dump_all
def section_dump_all
Definition: formatter.py:184
formatter.Formatter.toc_enter
def toc_enter
Definition: formatter.py:54
formatter.Formatter.section_enter
def section_enter
Definition: formatter.py:133
formatter.Formatter.toc_index
def toc_index
Definition: formatter.py:69
formatter.Formatter.field_exit
def field_exit
Definition: formatter.py:145
formatter.Formatter.field_enter
def field_enter
Definition: formatter.py:142
utils.close_output
def close_output
Definition: utils.py:74
formatter.Formatter.markup_enter
def markup_enter
Definition: formatter.py:139
formatter.Formatter.sections
sections
Definition: formatter.py:23
formatter.Formatter.blocks
blocks
Definition: formatter.py:27
formatter.Formatter.toc_exit
def toc_exit
Definition: formatter.py:72
formatter.Formatter.index_name_enter
def index_name_enter
Definition: formatter.py:105
formatter.Formatter.processor
processor
Definition: formatter.py:20
formatter.Formatter.index_name_exit
def index_name_exit
Definition: formatter.py:108