Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: experimental/PdfViewer/spec2def.py

Issue 22900010: pdfviewer: check in pdfapi classes (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/local/bin/python
2 # coding: utf-8
3
4 import sys
5 import re
6
7 # TODO(edisonn): put processed part of file in a new file
8 # put unprocessed part, in a new file, so we see what we miss
9 # keep blank lines, and generate a version without the blank lines
10
11 #TODO (edisonn): deal manually with tables that don't have "KEY TYPE VALUE' head er, e.g.
12 # TABLE 7.11 Restrictions on the entries in a soft-mask image dictionary
13 #KEY RESTRICTION
14
15
16
17 lines = 0
18 table = ''
19 tableHeaderFound = False
20 tableLine = 0
21 tableRow = 0
22 columnWidth = []
23 columnValues = None
24 mustFollowTableHeader = False
25 emitedDitionaryName = ''
26
27 knownTypes = set([
28 '(any)',
29 unicode('undefined', 'utf8'),
30 '(undefined)',
31 '(various)',
32 'array',
33 'or',
34 'boolean',
35 'date',
36 'dictionary',
37 'function',
38 'integer',
39 unicode('file', 'utf8'),
40 'file',
41 unicode('specification', 'utf8'),
42 'specification',
43 'name',
44 'tree',
45 'number',
46 'rectangle',
47 'stream',
48 'string',
49 'text',
50 ',',
51 ' '
52 ])
53
54 # TODO(edisonn): add a third element in the vector, the base class, by default i t is Dictionary
55 # TODO(edisonn): add overrides for types map<field_name, type_name>
56 # e.g. ,{'Resources', 'ResourceDictionary'}
57 # TODO(edisonn): can be added one by one, or extracted from documentation
58
59 tableToClassName = {
60 'TABLE 3.4': ['StreamCommonDictionary', 'Entries common to all stream dictionari es'],
61 'TABLE 3.7': ['LzwdecodeAndFlatedecodeFiltersDictionary', 'Optional parameters f or LZWDecode and FlateDecode filters'],
62 'TABLE 3.9': ['CcittfaxdecodeFilterDictionary', 'Optional parameters for the CCI TTFaxDecode filter'],
63 'TABLE 3.10': ['Jbig2DecodeFilterDictionary', 'Optional parameter for the JBIG2D ecode filter'],
64 'TABLE 3.11': ['DctdecodeFilterDictionary', 'Optional parameter for the DCTDecod e filter'],
65 'TABLE 3.12': ['FileTrailerDictionary', 'Entries in the file trailer dictionary' ],
66 'TABLE 3.13': ['EncryptionCommonDictionary', 'Entries common to all encryption d ictionaries'],
67 'TABLE 3.14': ['StandardSecurityHandlerDictionary', 'Additional encryption dicti onary entries for the standard security handler'],
68 'TABLE 3.16': ['CatalogDictionary', 'Entries in the catalog dictionary'],
69 'TABLE 3.17': ['PageTreeNodeDictionary', 'Required entries in a page tree node'] ,
70 'TABLE 3.18': ['PageObjectDictionary', 'Entries in a page object'],
71 'TABLE 3.19': ['NameDictionary', 'Entries in the name dictionary'],
72 'TABLE 3.21': ['ResourceDictionary', 'Entries in a resource dictionary'],
73 'TABLE 3.23': ['NameTreeNodeDictionary', 'Entries in a name tree node dictionary '],
74 'TABLE 3.25': ['NumberTreeNodeDictionary', 'Entries in a number tree node dictio nary'],
75 'TABLE 3.26': ['FunctionCommonDictionary', 'Entries common to all function dicti onaries'],
76 'TABLE 3.27': ['Type0FunctionDictionary', 'Additional entries specific to a type 0 function dictionary'],
77 'TABLE 3.28': ['Type2FunctionDictionary', 'Additional entries specific to a type 2 function dictionary'],
78 'TABLE 3.29': ['Type3FunctionDictionary', 'Additional entries specific to a type 3 function dictionary'],
79 'TABLE 3.32': ['FileSpecificationDictionary', 'Entries in a file specification d ictionary'],
80 'TABLE 3.33': ['EmbeddedFileStreamDictionary', 'Additional entries in an embedde d file stream dictionary'],
81 'TABLE 3.34': ['EmbeddedFileParameterDictionary', 'Entries in an embedded file p arameter dictionary'],
82 'TABLE 3.35': ['MacOsFileInformationDictionary', 'Entries in a Mac OS file infor mation dictionary'],
83 'TABLE 4.8': ['GraphicsStateDictionary', 'Entries in a graphics state parameter dictionary'],
84 'TABLE 4.13': ['CalgrayColorSpaceDictionary', 'Entries in a CalGray color space dictionary'],
85 'TABLE 4.14': ['CalrgbColorSpaceDictionary', 'Entries in a CalRGB color space di ctionary'],
86 'TABLE 4.15': ['LabColorSpaceDictionary', 'Entries in a Lab color space dictiona ry'],
87 'TABLE 4.16': ['IccProfileStreamDictionary', 'Additional entries specific to an ICC profile stream dictionary'],
88 'TABLE 4.20': ['DeviceNColorSpaceDictionary', 'Entry in a DeviceN color space at tributes dictionary'],
89 'TABLE 4.22': ['Type1PatternDictionary', 'Additional entries specific to a type 1 pattern dictionary', '', {'PatternType': '[datatypes.PdfInteger(1)]'}],
90 'TABLE 4.23': ['Type2PatternDictionary', 'Entries in a type 2 pattern dictionary '],
91 'TABLE 4.25': ['ShadingDictionary', 'Entries common to all shading dictionaries' ],
92 'TABLE 4.26': ['Type1ShadingDictionary', 'Additional entries specific to a type 1 shading dictionary', 'ShadingDictionary'],
93 'TABLE 4.27': ['Type2ShadingDictionary', 'Additional entries specific to a type 2 shading dictionary', 'ShadingDictionary'],
94 'TABLE 4.28': ['Type3ShadingDictionary', 'Additional entries specific to a type 3 shading dictionary', 'ShadingDictionary'],
95 'TABLE 4.29': ['Type4ShadingDictionary', 'Additional entries specific to a type 4 shading dictionary', 'ShadingDictionary'],
96 'TABLE 4.30': ['Type5ShadingDictionary', 'Additional entries specific to a type 5 shading dictionary', 'ShadingDictionary'],
97 'TABLE 4.31': ['Type6ShadingDictionary', 'Additional entries specific to a type 6 shading dictionary', 'ShadingDictionary'],
98 'TABLE 4.35': ['ImageDictionary', 'Additional entries specific to an image dicti onary', 'XObjectDictionary', {'Subtype': '[datatypes.PdfName(\'Image\')]'}],
99 'TABLE 4.37': ['AlternateImageDictionary', 'Entries in an alternate image dictio nary'],
100 'TABLE 4.41': ['Type1FormDictionary', 'Additional entries specific to a type 1 f orm dictionary', 'XObjectDictionary', {'Subtype': '[datatypes.PdfName(\'Form\')] '}],
101 'TABLE 4.42': ['GroupAttributesDictionary', 'Entries common to all group attribu tes dictionaries'],
102 'TABLE 4.43': ['ReferenceDictionary', 'Entries in a reference dictionary'],
103 'TABLE 4.44': ['PSXobjectDictionary', 'Additional entries specific to a PostScri pt XObject dictionary'],
104 'TABLE 5.8': ['Type1FontDictionary', 'Entries in a Type 1 font dictionary', 'Fon tDictionary', {'Subtype': '[datatypes.PdfName(\'Type1\')]'}],
105 'TABLE 5.9': ['Type3FontDictionary', 'Entries in a Type 3 font dictionary', 'Typ e1FontDictionary', {'Subtype': '[datatypes.PdfName(\'Type3\')]'}],
106 'TABLE 5.11': ['EncodingDictionary', 'Entries in an encoding dictionary'],
107 'TABLE 5.12': ['CIDSystemInfoDictionary', 'Entries in a CIDSystemInfo dictionary '],
108 'TABLE 5.13': ['CIDFontDictionary', 'Entries in a CIDFont dictionary', '', {'Sub type': '[datatypes.PdfName(\'CIDFontType0\'), datatypes.PdfName(\'CIDFontType2\' )]'}],
109 'TABLE 5.16': ['CMapDictionary', 'Additional entries in a CMap dictionary'],
110 'TABLE 5.17': ['Type0FontDictionary', 'Entries in a Type 0 font dictionary', 'Fo ntDictionary', {'Subtype': '[datatypes.PdfName(\'Type0\')]'}],
111 'TABLE 5.18': ['FontDescriptorDictionary', 'Entries common to all font descripto rs', '', {'Type': '[datatypes.PdfName(\'FontDescriptor\')]'}],
112 'TABLE 5.20': ['CIDFontDescriptorDictionary', 'Additional font descriptor entrie s for CIDFonts'],
113 'TABLE 5.23': ['EmbeddedFontStreamDictionary', 'Additional entries in an embedde d font stream dictionary'],
114 'TABLE 6.3': ['Type1HalftoneDictionary', 'Entries in a type 1 halftone dictionar y'],
115 'TABLE 6.4': ['Type6HalftoneDictionary', 'Additional entries specific to a type 6 halftone dictionary'],
116 'TABLE 6.5': ['Type10HalftoneDictionary', 'Additional entries specific to a type 10 halftone dictionary'],
117 'TABLE 6.6': ['Type16HalftoneDictionary', 'Additional entries specific to a type 16 halftone dictionary'],
118 'TABLE 6.7': ['Type5HalftoneDictionary', 'Entries in a type 5 halftone dictionar y'],
119 'TABLE 7.10': ['SoftMaskDictionary', 'Entries in a soft-mask dictionary', '', {' S': '[datatypes.PdfName(\'Alpha\'), datatypes.PdfName(\'Luminosity\')]'}],
120 'TABLE 7.12': ['SoftMaskImageDictionary', 'Additional entry in a soft-mask image dictionary', 'ImageDictionary', {'Subtype': '[datatypes.PdfName(\'Image\')]', ' ColorSpace': '[datatypes.PdfName(\'DeviceGray\'), datatypes.PdfName(\'Gray\')]'} ],
121 'TABLE 7.13': ['TransparencyGroupDictionary', 'Additional entries specific to a transparency group attributes dictionary', '', {'S': '[datatypes.PdfName(\'Trans parency\')]'}],
122 'TABLE 8.1': ['ViewerPreferencesDictionary', 'Entries in a viewer preferences di ctionary'],
123 'TABLE 8.3': ['OutlineDictionary', 'Entries in the outline dictionary'],
124 'TABLE 8.4': ['OutlineItemDictionary', 'Entries in an outline item dictionary'],
125 'TABLE 8.6': ['PageLabelDictionary', 'Entries in a page label dictionary'],
126 'TABLE 8.7': ['ThreadDictionary', 'Entries in a thread dictionary'],
127 'TABLE 8.8': ['BeadDictionary', 'Entries in a bead dictionary'],
128 'TABLE 8.9': ['TransitionDictionary', 'Entries in a transition dictionary'],
129 'TABLE 8.10': ['AnnotationDictionary', 'Entries common to all annotation diction aries'],
130 'TABLE 8.12': ['BorderStyleDictionary', 'Entries in a border style dictionary'],
131 'TABLE 8.13': ['AppearanceDictionary', 'Entries in an appearance dictionary'],
132 'TABLE 8.15': ['TextAnnotationDictionary', 'Additional entries specific to a tex t annotation'],
133 'TABLE 8.16': ['ALinkAnnotationDictionary', 'Additional entries specific to a li nk annotation'],
134 'TABLE 8.17': ['FreeTextAnnotationDictionary', 'Additional entries specific to a free text annotation'],
135 'TABLE 8.18': ['LineAnnotationDictionary', 'Additional entries specific to a lin e annotation'],
136 'TABLE 8.20': ['SquareOrCircleAnnotation', 'Additional entries specific to a squ are or circle annotation'],
137 'TABLE 8.21': ['MarkupAnnotationsDictionary', 'Additional entries specific to ma rkup annotations'],
138 'TABLE 8.22': ['RubberStampAnnotationDictionary', 'Additional entries specific t o a rubber stamp annotation'],
139 'TABLE 8.23': ['InkAnnotationDictionary', 'Additional entries specific to an ink annotation'],
140 'TABLE 8.24': ['PopUpAnnotationDictionary', 'Additional entries specific to a po p-up annotation'],
141 'TABLE 8.25': ['FileAttachmentAnnotationDictionary', 'Additional entries specifi c to a file attachment annotation'],
142 'TABLE 8.26': ['SoundAnnotationDictionary', 'Additional entries specific to a so und annotation'],
143 'TABLE 8.27': ['MovieAnnotationDictionary', 'Additional entries specific to a mo vie annotation'],
144 'TABLE 8.28': ['WidgetAnnotationDictionary', 'Additional entries specific to a w idget annotation'],
145 'TABLE 8.29': ['ActionDictionary', 'Entries common to all action dictionaries'],
146 'TABLE 8.30': ['AnnotationActionsDictionary', 'Entries in an annotation\'s addit ional-actions dictionary'],
147 'TABLE 8.31': ['PageObjectActionsDictionary', 'Entries in a page object\'s addit ional-actions dictionary'],
148 'TABLE 8.32': ['FormFieldActionsDictionary', 'Entries in a form field\'s additio nal-actions dictionary'],
149 'TABLE 8.33': ['DocumentCatalogActionsDictionary', 'Entries in the document cata log\'s additional-actions dictionary'],
150 'TABLE 8.35': ['GoToActionDictionary', 'Additional entries specific to a go-to a ction'],
151 'TABLE 8.36': ['RemoteGoToActionDictionary', 'Additional entries specific to a r emote go-to action'],
152 'TABLE 8.37': ['LaunchActionDictionary', 'Additional entries specific to a launc h action'],
153 'TABLE 8.38': ['WindowsLaunchActionDictionary', 'Entries in a Windows launch par ameter dictionary'],
154 'TABLE 8.39': ['ThreadActionDictionary', 'Additional entries specific to a threa d action'],
155 'TABLE 8.40': ['URIActionDictionary', 'Additional entries specific to a URI acti on'],
156 'TABLE 8.41': ['URIDictionary', 'Entry in a URI dictionary'],
157 'TABLE 8.42': ['SoundActionDictionary', 'Additional entries specific to a sound action'],
158 'TABLE 8.43': ['MovieActionDictionary', 'Additional entries specific to a movie action'],
159 'TABLE 8.44': ['HideActionDictionary', 'Additional entries specific to a hide ac tion'],
160 'TABLE 8.46': ['NamedActionsDictionary', 'Additional entries specific to named a ctions'],
161 'TABLE 8.47': ['InteractiveFormDictionary', 'Entries in the interactive form dic tionary'],
162 'TABLE 8.49': ['FieldDictionary', 'Entries common to all field dictionaries'],
163 'TABLE 8.51': ['VariableTextFieldDictionary', 'Additional entries common to all fields containing variable text'],
164 'TABLE 8.52': ['AppearanceCharacteristicsDictionary', 'Entries in an appearance characteristics dictionary'],
165 'TABLE 8.54': ['CheckboxFieldDictionary', 'Additional entry specific to a checkb ox field'],
166 'TABLE 8.55': ['RadioButtonFieldDictionary', 'Additional entry specific to a rad io button field'],
167 'TABLE 8.57': ['TextFieldDictionary', 'Additional entry specific to a text field '],
168 'TABLE 8.59': ['ChoiceFieldDictionary', 'Additional entries specific to a choice field'],
169 'TABLE 8.60': ['SignatureDictionary', 'Entries in a signature dictionary'],
170 'TABLE 8.61': ['SubmitFormActionDictionary', 'Additional entries specific to a s ubmit-form action'],
171 'TABLE 8.63': ['ResetFormActionDictionary', 'Additional entries specific to a re set-form action'],
172 'TABLE 8.65': ['ImportDataActionDictionary', 'Additional entries specific to an import-data action'],
173 'TABLE 8.66': ['JavascriptActionDictionary', 'Additional entries specific to a J avaScript action'],
174 'TABLE 8.67': ['FDFTrailerDictionary', 'Entry in the FDF trailer dictionary'],
175 'TABLE 8.68': ['FDFCatalogDictionary', 'Entries in the FDF catalog dictionary'],
176 'TABLE 8.69': ['FDFDictionary', 'Entries in the FDF dictionary'],
177 'TABLE 8.70': ['EncryptedEmbeddedFileStreamDictionary', 'Additional entry in an embedded file stream dictionary for an encrypted FDF file'],
178 'TABLE 8.71': ['JavascriptDictionary', 'Entries in the JavaScript dictionary'],
179 'TABLE 8.72': ['FDFFieldDictionary', 'Entries in an FDF field dictionary'],
180 'TABLE 8.73': ['IconFitDictionary', 'Entries in an icon fit dictionary'],
181 'TABLE 8.74': ['FDFPageDictionary', 'Entries in an FDF page dictionary'],
182 'TABLE 8.75': ['FDFTemplateDictionary', 'Entries in an FDF template dictionary'] ,
183 'TABLE 8.76': ['FDFNamedPageReferenceDictionary', 'Entries in an FDF named page reference dictionary'],
184 'TABLE 8.77': ['FDFFileAnnotationDictionary', 'Additional entry for annotation d ictionaries in an FDF file'],
185 'TABLE 8.78': ['SoundObjectDictionary', 'Additional entries specific to a sound object'],
186 'TABLE 8.79': ['MovieDictionary', 'Entries in a movie dictionary'],
187 'TABLE 8.80': ['MovieActivationDictionary', 'Entries in a movie activation dicti onary'],
188 'TABLE 9.2': ['DocumentInformationDictionary', 'Entries in the document informat ion dictionary'],
189 'TABLE 9.3': ['MetadataStreamDictionary', 'Additional entries in a metadata stre am dictionary'],
190 'TABLE 9.4': ['ComponentsWithMetadataDictionary', 'Additional entry for componen ts having metadata'],
191 'TABLE 9.6': ['PagePieceDictionary', 'Entries in a page-piece dictionary'],
192 'TABLE 9.7': ['ApplicationDataDictionary', 'Entries in an application data dicti onary'],
193 'TABLE 9.9': ['StructureTreeRootDictionary', 'Entries in the structure tree root '],
194 'TABLE 9.10': ['StructureElementDictionary', 'Entries in a structure element dic tionary'],
195 'TABLE 9.11': ['MarkedContentReferenceDictionary', 'Entries in a marked-content reference dictionary'],
196 'TABLE 9.12': ['ObjectReferenceDictionary', 'Entries in an object reference dict ionary'],
197 'TABLE 9.13': ['StructureElementAccessDictionary', 'Additional dictionary entrie s for structure element access'],
198 'TABLE 9.14': ['AttributeObjectDictionary', 'Entry common to all attribute objec ts'],
199 'TABLE 9.15': ['MarkInformationDictionary', 'Entry in the mark information dicti onary'],
200 'TABLE 9.16': ['ArtifactsDictionary', 'Property list entries for artifacts'],
201 'TABLE 9.27': ['StandardStructureDictionary', 'Standard layout attributes common to all standard structure types'],
202 'TABLE 9.28': ['BlockLevelStructureElementsDictionary', 'Additional standard lay out attributes specific to block-level structure elements'],
203 'TABLE 9.29': ['InlineLevelStructureElementsDictionary', 'Standard layout attrib utes specific to inline-level structure elements'],
204 'TABLE 9.30': ['ListAttributeDictionary', 'Standard list attribute'],
205 'TABLE 9.31': ['TableAttributesDictionary', 'Standard table attributes'],
206 'TABLE 9.32': ['WebCaptureInformationDictionary', 'Entries in the Web Capture in formation dictionary'],
207 'TABLE 9.33': ['WebCaptureDictionary', 'Entries common to all Web Capture conten t sets'],
208 'TABLE 9.34': ['WebCapturePageSetDictionary', 'Additional entries specific to a Web Capture page set'],
209 'TABLE 9.35': ['WebCaptureImageSetDictionary', 'Additional entries specific to a Web Capture image set'],
210 'TABLE 9.36': ['SourceInformationDictionary', 'Entries in a source information d ictionary'],
211 'TABLE 9.37': ['URLAliasDictionary', 'Entries in a URL alias dictionary'],
212 'TABLE 9.38': ['WebCaptureCommandDictionary', 'Entries in a Web Capture command dictionary'],
213 'TABLE 9.40': ['WebCaptureCommandSettingsDictionary', 'Entries in a Web Capture command settings dictionary'],
214 'TABLE 9.41': ['BoxColorInformationDictionary', 'Entries in a box color informat ion dictionary'],
215 'TABLE 9.42': ['BoxStyleDictionary', 'Entries in a box style dictionary'],
216 'TABLE 9.43': ['PrinterMarkAnnotationDictionary', 'Additional entries specific t o a printer\'s mark annotation'],
217 'TABLE 9.44': ['PrinterMarkFormDictionary', 'Additional entries specific to a pr inter\'s mark form dictionary'],
218 'TABLE 9.45': ['SeparationDictionary', 'Entries in a separation dictionary'],
219 'TABLE 9.46': ['PDF_XOutputIntentDictionary', 'Entries in a PDF/X output intent dictionary'],
220 'TABLE 9.47': ['TrapNetworkAnnotationDictionary', 'Additional entries specific t o a trap network annotation'],
221 'TABLE 9.48': ['TrapNetworkAppearanceStreamDictionary', 'Additional entries spec ific to a trap network appearance stream'],
222 'TABLE 9.49': ['OpiVersionDictionary', 'Entry in an OPI version dictionary'],
223 }
224
225 classTree = {
226 }
227
228 def buildKnownDictionaries():
229 global tableToClassName
230 global knownTypes
231
232 ret = {}
233 for e in tableToClassName:
234 ret[tableToClassName[e][0]] = ''
235 knownTypes.add(tableToClassName[e][0])
236
237 return ret
238
239 knownDictionaries = buildKnownDictionaries()
240
241 def acceptType(val):
242 global knownTypes
243
244 ret = val
245
246 for item in knownTypes:
247 ret = ret.replace(item, '')
248
249 return ret == ''
250
251
252 def inTable():
253 global tableHeaderFound
254 return tableHeaderFound
255
256 def tableDescriptionFound(desc):
257 global table
258 table = desc.strip()
259
260 def tableHasHeader():
261 global table
262 global tableHeaderFound
263
264 tableHeaderFound = True
265 #print table
266
267 def fix(val):
268 ret = val
269
270 # fix unicode chars
271 ret = ret.replace(unicode('fi', 'utf8'), 'fi')
272 ret = ret.replace(u'\u201c', '\"')
273 ret = ret.replace(u'\u201d', '\"')
274 ret = ret.replace(u'\u2019', '\'')
275 ret = ret.replace(u'\ufb02', 'fl')
276 ret = ret.replace(u'\xae', '(R)')
277 ret = ret.replace(u'\u2026', '...')
278 ret = ret.replace(u'\xd7', 'x')
279 ret = ret.replace(u'\u2212', '-')
280 ret = ret.replace(u'\u2264', '<=')
281 ret = ret.replace(u'\u2014', '-')
282 ret = ret.replace(u'\u2013', '\'')
283 ret = ret.replace(u'\u2022', '*')
284 ret = ret.replace(u'\xb5', 'mu')
285 ret = ret.replace(u'\xf7', '/')
286 ret = ret.replace(u'\xc4', 'A')
287 ret = ret.replace(u'\xc5', 'A')
288 ret = ret.replace(u'\u2122', '(TM)')
289
290
291 # how enable to emit this a python string
292 ret = ret.replace('\'', '\\\'')
293 ret = ret.replace('\n', '\\n')
294
295
296 return ret
297
298 def commitRow(fspecPy):
299 global columnValues
300 global emitedDitionaryName
301 global table
302 global tableToClassName
303 global classTree
304 global tableKey
305
306
307 if columnValues == None:
308 return
309
310 #print columnValues
311
312 lastClosed = columnValues[2].find(')')
313 if lastClosed < 0:
314 print 'ERRRRRRRRRRRRRRROR'
315 print columnValues
316 return
317
318 spec = columnValues[2][:lastClosed + 1]
319 spec = spec.replace('(', ';')
320 spec = spec.replace(')', ';')
321 spec = spec.strip(';')
322
323 specs = spec.split(';')
324
325 # clearly required, but it can be required with conditions. don't handle this ones here, but manually
326 required = specs[0] == 'Required'
327
328 inheritable = False
329 version = ''
330 for s in specs:
331 if s.strip() == 'inheritable' or s.strip() == 'Inheritable':
332 inheritable = True
333 elif re.match('^PDF [0-9]*[\.[0-9]*]*', s.strip()):
334 version = s.strip()
335 elif s != 'Required':
336 required = False
337
338 #print spec
339 #print specs
340 #print required
341 #print inheritable
342 #print version
343 #print columnValues
344
345 columnValues = [fix(columnValues[0]), fix(columnValues[1]), fix(columnValues[2 ])]
346
347 tableKey = re.search('(TABLE [0-9].[0-9][0-9]?)', table).group(1)
348
349 if emitedDitionaryName == '':
350 table = fix(table)
351
352 #print table
353 emitedDitionaryName = 'foo'
354 e = re.search('[Entries|Entry] in [a-z]* (.* dictionary)', table)
355 a = re.search('Additional [a-z]* in a[n]? (.* dictionary)', table)
356 s = re.search('Additional [a-z]* (.*)', table)
357 c = re.search('[Entries|Entry] common to all (.*)', table)
358 o1 = re.search('Optional parameter[s]? for the (.*)', table)
359 o2 = re.search('Optional parameter[s]? for (.*)', table)
360 t = re.search('.*ntries in [a-z]* (.*)', table)
361
362 r = re.search('Property list entries for (.*)', table)
363 st = re.search('Standard (.*)', table)
364
365 if e:
366 emitedDitionaryName = e.group(1).title().replace(' ', '')
367 #print emitedDitionaryName
368 elif a:
369 emitedDitionaryName = a.group(1).title().replace(' ', '')
370 #print emitedDitionaryName
371 elif s:
372 emitedDitionaryName = s.group(1).title().replace(' ', '')
373 #print emitedDitionaryName
374 elif c:
375 emitedDitionaryName = c.group(1).title().replace(' ', '') + 'Common'
376 #print emitedDitionaryName
377 elif o1:
378 emitedDitionaryName = o1.group(1).title().replace(' ', '') + 'OptionalPara meters'
379 #print emitedDitionaryName
380 elif o2:
381 emitedDitionaryName = o2.group(1).title().replace(' ', '') + 'OptionalPara meters'
382 #print emitedDitionaryName
383 elif t:
384 emitedDitionaryName = t.group(1).title().replace(' ', '') + 'Dictionary'
385 #print emitedDitionaryName
386 elif r:
387 emitedDitionaryName = r.group(1).title().replace(' ', '') + 'Dictionary'
388 #print emitedDitionaryName
389 elif st:
390 emitedDitionaryName = st.group(1).title().replace(' ', '') + 'Dictionary'
391 #print emitedDitionaryName
392 #else:
393 #print table
394
395 #print tableKey
396 #print('\'' + tableKey + '\': [\'' + emitedDitionaryName + '\', \'' + table[ len(tableKey) + 1:] + '\'],')
397
398 emitedDitionaryName = tableToClassName[tableKey][0]
399 comment = fix(tableToClassName[tableKey][1])
400
401
402 if len(tableToClassName[tableKey]) >= 3 and tableToClassName[tableKey][2] != '':
403 fspecPy.write(' pdfspec.addClass(\'' + emitedDitionaryName + '\', \'' + t ableToClassName[tableKey][2] + '\', \'' + comment + '\')\\\n')
404 classTree[emitedDitionaryName] = [tableToClassName[tableKey][2], {}]
405 else:
406 fspecPy.write(' pdfspec.addClass(\'' + emitedDitionaryName + '\', \'Dicti onary\', \'' + comment + '\')\\\n')
407 classTree[emitedDitionaryName] = ['Dictionary', {}]
408
409 if len(tableToClassName[tableKey]) >= 4 and columnValues[0] in tableToClassNam e[tableKey][3]:
410 required = True
411
412 if required:
413 fspecPy.write(' .required(\'NULL\')\\\n')
414 else:
415 fspecPy.write(' .optional()\\\n')
416
417 fspecPy.write(' .field(\'' + columnValues[0] + '\')\\\n')
418 fspecPy.write(' .name(\'' + columnValues[0] + '\')\\\n')
419 fspecPy.write(' .type(\'' + columnValues[1] + '\')\\\n')
420 fspecPy.write(' .comment(\'' + columnValues[2] + '\')\\\n')
421
422 classTree[emitedDitionaryName][1][columnValues[0]] = ' .field(\'' + columnValues[0] + '\')\\\n' + \
423 ' .name(\'' + columnValues[0] + '\')\\\n' + \
424 ' .type(\'' + columnValues[1] + '\')\\\n' + \
425 ' .comment(\'\')\\\n'
426
427
428 if len(tableToClassName[tableKey]) >= 4 and columnValues[0] in tableToClassNam e[tableKey][3]:
429 fspecPy.write(' .must(' + tableToClassName[tableKey][3][columnValue s[0]] + ')\\\n')
430
431 fspecPy.write(' .done().done()\\\n')
432
433
434 columnValues = None
435
436 def newRow(first, second, third):
437 global columnValues
438 columnValues = [first.rstrip(), second.rstrip(), third.rstrip()]
439
440 def appendRow(second, third):
441 global columnValues
442 if second.rstrip() != '':
443 columnValues[1] = columnValues[1] + ' ' + second.rstrip()
444 if third.rstrip() != '':
445 columnValues[2] = columnValues[2] + '\n' + third.rstrip()
446
447 def rebaseTable(fspecPy, line):
448 global knownTypes
449 global columnWidth
450
451 line2 = line.replace(',', ' , ')
452
453 words = line2.split()
454
455 if len(words) < 3:
456 return False
457
458 i = 1
459 while i < len(words) - 1 and words[i] in knownTypes:
460 i = i + 1
461
462 if words[i].startswith('(Optional') or words[i].startswith('(Required'):
463 commitRow(fspecPy)
464
465 columnWidth[0] = line.find(words[1])
466
467 if words[i].startswith('(Optional'):
468 columnWidth[1] = line.find('(Optional') - columnWidth[0]
469 if words[i].startswith('(Required'):
470 columnWidth[1] = line.find('(Required') - columnWidth[0]
471 return True
472
473 return False
474
475
476 def stopTable(fspecPy):
477 global tableHeaderFound
478 global emitedDitionaryName
479 global tableKey
480 global classTree
481
482 if not inTable():
483 return
484
485 commitRow(fspecPy)
486
487 #print tableKey
488
489 # TODO(edisonn): iterate on all requited key in the def, and if not on the def inition, get definition from parent and export them
490 if len(tableToClassName[tableKey]) >= 4:
491 for field in tableToClassName[tableKey][3]:
492 #print field
493 if not field in classTree[emitedDitionaryName][1]:
494 fieldDef = ''
495 searchKey = classTree[emitedDitionaryName][0]
496 while searchKey != 'Dictionary' and (not field in classTree[searchKey][1 ]):
497 searchKey = classTree[searchKey][0]
498
499 if searchKey != 'Dictionary' and (field in classTree[searchKey][1]):
500 #print tableToClassName[tableKey][3][field]
501 #print classTree[searchKey][1][field]
502 # TODO(edisonns): hack - for required fields, they need to be downgrad ed to only a type
503 classTree[searchKey][1][field] = classTree[searchKey][1][field].replac e(' or array', '')
504 classTree[searchKey][1][field] = classTree[searchKey][1][field].replac e(' or distionary', '')
505 fspecPy.write(' .required(\'NULL\')\\\n')
506 fspecPy.write(classTree[searchKey][1][field])
507 fspecPy.write(' .must(' + tableToClassName[tableKey][3][field ] + ')\\\n')
508 fspecPy.write(' .done().done()\\\n')
509 else:
510 print 'ERROR' + tableKey + '.' + field;
511
512 tableHeaderFound = False
513 emitedDitionaryName = ''
514 fspecPy.write(' .done()\n')
515 fspecPy.write('\n')
516
517
518 def killTable():
519 return
520
521 def processLineCore(fspecPy, line):
522 global lines
523 global tableLine
524 global tableRow
525 global columnWidth
526 global columnValues
527 global mustFollowTableHeader
528
529 #global fnewspec
530
531 lines = lines + 1
532
533 line = unicode(line, 'utf8')
534
535 striped = line.rstrip()
536
537 words = line.split()
538 if len(words) == 0:
539 stopTable(fspecPy)
540 return False
541
542 isTableHeader = re.search('^[\s]*(TABLE [0-9].[0-9][0-9]?)', striped)
543 if isTableHeader:
544 stopTable(fspecPy)
545 tableDescriptionFound(striped)
546 mustFollowTableHeader = True
547 return False
548
549 if mustFollowTableHeader:
550 mustFollowTableHeader = False
551 if len(words) != 3:
552 killTable()
553 return False
554
555 # TODO(edisonn): support for generic table!
556 if words[0] != 'KEY' or words[1] != 'TYPE' or words[2] != 'VALUE':
557 killTable()
558 return False
559
560 tableHasHeader()
561 columnWidth = [0, 0, 0]
562 columnWidth[0] = striped.index('TYPE')
563 columnWidth[1] = striped.index('VALUE') - striped.index('TYPE')
564 columnWidth[2] = 0
565 return True
566
567 if inTable():
568 tableLine = tableLine + 1
569 first = striped[0 : columnWidth[0]]
570 second = striped[columnWidth[0] : columnWidth[0] + columnWidth[1]]
571 third = striped[columnWidth[0] + columnWidth[1] :]
572
573 if tableLine == 1:
574 if third[0] != '(':
575 killTable()
576 return False
577
578 newRow(first, second, third)
579 return True
580
581 if rebaseTable(fspecPy, striped):
582 first = striped[0 : columnWidth[0]]
583 second = striped[columnWidth[0] : columnWidth[0] + columnWidth[1]]
584 third = striped[columnWidth[0] + columnWidth[1] :]
585
586 first = first.rstrip()
587 second = second.rstrip()
588 third = third.rstrip()
589
590 if first == '' and second == '' and third != '':
591 appendRow(second, third)
592 return True
593
594 if len(first.split()) > 1:
595 stopTable(fspecPy)
596 return False
597
598 if first != '' and first[0] == ' ':
599 stopTable(fspecPy)
600 return False
601
602 if first != '' and second != '' and third == '':
603 stopTable(fspecPy)
604 return False
605
606 if first == '' and second != '' and second[0] != ' ':
607 if acceptType(second):
608 appendRow(second, third)
609 return True
610 else:
611 stopTable(fspecPy)
612 return False
613
614 if first != '' and second != '' and third[0] != '(':
615 stopTable(fspecPy)
616 return False
617
618 if first == '' and second != '' and second[0] == ' ':
619 stopTable(fspecPy)
620 return False
621
622 if first != '' and second != '' and third[0] == '(':
623 commitRow(fspecPy)
624 newRow(first, second, third)
625 return True
626
627 return False
628 return False
629
630 def processLine(fspecPy, line):
631 #global fnewspec
632
633 inSpec = processLineCore(fspecPy, line)
634
635 #just return, use the next lines if you wish to rewrite spec
636 return
637
638 if inSpec:
639 #resize colum with types
640 line = line[:columnWidth[0] + columnWidth[1]] + (' ' * (60 - columnWidth[1]) ) + line[columnWidth[0] + columnWidth[1]:]
641 line = line[:columnWidth[0]] + (' ' * (40 - columnWidth[0])) + line[columnWi dth[0]:]
642
643 #fnewspec.write(line)
644
645
646 def generateDef():
647 global lines
648 #global fnewspec
649
650 #fnewspec = open('PdfReference-okular-2.txt', 'w')
651
652 # pdf spec in text format
653 fspecText = open(sys.argv[1], 'r')
654
655 # pdf spec in python directives
656 fspecPy = open(sys.argv[2], 'w')
657
658 fspecPy.write('import datatypes\n')
659 fspecPy.write('\n')
660
661 fspecPy.write('def buildPdfSpec(pdfspec):\n')
662
663 for line in fspecText:
664 processLine(fspecPy, line)
665
666 # close last table if it was not closed already
667 stopTable(fspecPy)
668
669 fspecPy.write('\n')
670
671 fspecPy.write('def addDictionaryTypesTo(knowTypes):\n')
672 for e in tableToClassName:
673 #TODO(edisonn): build this map
674
675 fspecPy.write(' knowTypes[\'' + tableToClassName[e][0] + '\'] = [\'SkPdf' + tableToClassName[e][0] + '*\', \'(SkPdf' + tableToClassName[e][0] + '*)ret\', d atatypes.CppNull(), \'ret->isDictionary() && ((SkPdf' + tableToClassName[e][0] + '*)ret)->valid()\', \'A_DICTIONARY\']\n')
676 fspecPy.write('\n')
677
678 #print lines
679 #fnewspec.close()
680
681 if '__main__' == __name__:
682 sys.exit(generateDef())
OLDNEW
« no previous file with comments | « experimental/PdfViewer/pdfparser/native/pdfapi/SkPdfXObjectDictionary_autogen.cpp ('k') | gyp/pdfviewer_lib.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698