blob: 05267bc9407aa6d7c9d8b08d619063166edc0d6e [file] [log] [blame]
edisonn@google.coma2fab9d2013-06-14 19:22:19 +00001
2
edisonn@google.com1a191c62013-06-11 21:44:08 +00003import sys
4
edisonn@google.coma2fab9d2013-06-14 19:22:19 +00005import datatypes
6import pdfspec_autogen
edisonn@google.comaf3daa02013-06-12 19:07:45 +00007
edisonn@google.com1277cf02013-06-17 23:36:45 +00008knowTypes = {
9'(any)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true'],
10'(undefined)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true'],
11'(various)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true'],
12'array': ['SkPdfArray', 'ArrayFromDictionary', datatypes.PdfArrayNone(), 'ret->podofo()->GetDataType() == ePdfDataType_Array'],
13'boolean': ['bool', 'BoolFromDictionary', datatypes.PdfBoolean('false'), 'ret->podofo()->GetDataType() == ePdfDataType_Bool'],
14'date': ['SkPdfDate', 'DateFromDictionary', datatypes.PdfDateNever(), 'ret->podofo()->GetDataType() == ePdfDataType_Array'],
15'dictionary': ['SkPdfDictionary*', 'DictionaryFromDictionary', datatypes.CppNull(), 'ret->podofo()->GetDataType() == ePdfDataType_Dictionary'],
16'function': ['SkPdfFunction', 'FunctionFromDictionary', datatypes.PdfFunctionNone(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'],
17'integer': ['long', 'LongFromDictionary', datatypes.PdfInteger(0), 'ret->podofo()->GetDataType() == ePdfDataType_Number'],
18'file_specification': ['SkPdfFileSpec', 'FileSpecFromDictionary', datatypes.FileSpecNone(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'],
19'name': ['std::string', 'NameFromDictionary', datatypes.PdfString('""'), 'ret->podofo()->GetDataType() == ePdfDataType_Name'],
20'tree': ['SkPdfTree*', 'TreeFromDictionary', datatypes.CppNull(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'],
21'number': ['double', 'DoubleFromDictionary', datatypes.PdfNumber(0), 'ret->podofo()->GetDataType() == ePdfDataType_Real'],
22'rectangle': ['SkRect', 'SkRectFromDictionary', datatypes.PdfEmptyRect(), 'ret->podofo()->GetDataType() == ePdfDataType_Array'],
23'stream': ['SkPdfStream', 'StreamFromDictionary', datatypes.PdfEmptyStream(), 'ret->podofo()->HasStream()'],
24'string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 'ret->podofo()->GetDataType() == ePdfDataType_String || ret->podofo()->GetDataType() == ePdfDataType_HexString'],
25'text': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 'ret->podofo()->GetDataType() == ePdfDataType_String || ret->podofo()->GetDataType() == ePdfDataType_HexString'],
26'text string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 'ret->podofo()->GetDataType() == ePdfDataType_String || ret->podofo()->GetDataType() == ePdfDataType_HexString'],
27}
edisonn@google.com45327112013-06-13 20:02:29 +000028
29
edisonn@google.com1a191c62013-06-11 21:44:08 +000030class PdfField:
31 def __init__(self, parent, name, abr):
32 self.fParent = parent
33 self.fName = name
34 self.fAbr = abr
35
36 self.fDefault = ''
edisonn@google.com1277cf02013-06-17 23:36:45 +000037 self.fTypes = ''
edisonn@google.comaf3daa02013-06-12 19:07:45 +000038 self.fCppName = ''
edisonn@google.com1277cf02013-06-17 23:36:45 +000039 self.fEnumValues = []
40 self.fHasMust = False
edisonn@google.comaf3daa02013-06-12 19:07:45 +000041 self.fMustBe = ''
edisonn@google.com1a191c62013-06-11 21:44:08 +000042
43 def must(self, value):
edisonn@google.comaf3daa02013-06-12 19:07:45 +000044 self.fHasMust = True
45 self.fMustBe = value
46 return self
edisonn@google.com1a191c62013-06-11 21:44:08 +000047
48 def default(self, value):
49 self.fDefault = value
50 return self
51
edisonn@google.com1277cf02013-06-17 23:36:45 +000052 def multiple(self, enumValues):
53 self.fEnumValues = enumValues
edisonn@google.com1a191c62013-06-11 21:44:08 +000054 return self
55
edisonn@google.comaf3daa02013-06-12 19:07:45 +000056 def name(self, name):
edisonn@google.comaf3daa02013-06-12 19:07:45 +000057 self.fCppName = name
edisonn@google.com1a191c62013-06-11 21:44:08 +000058 return self
59
edisonn@google.com1277cf02013-06-17 23:36:45 +000060 def type(self, types):
edisonn@google.com45327112013-06-13 20:02:29 +000061 # TODO (edisonn): if simple type, use it, otherwise set it to Dictionary, and set a mask for valid types, like array or name
edisonn@google.com1277cf02013-06-17 23:36:45 +000062 types = types.strip()
63 types = types.replace('or', ' ')
64 types = types.replace(',', ' ')
65 types = types.replace('text', ' ') # TODO(edisonn): what is the difference between 'text string' and 'string'?
66 types = types.replace('file specification', 'file_specification')
edisonn@google.coma2fab9d2013-06-14 19:22:19 +000067
edisonn@google.coma2fab9d2013-06-14 19:22:19 +000068
edisonn@google.com1277cf02013-06-17 23:36:45 +000069 self.fTypes = types
edisonn@google.com45327112013-06-13 20:02:29 +000070 return self
71
72 def comment(self, comment):
73 return self
74
edisonn@google.com1a191c62013-06-11 21:44:08 +000075 def done(self):
76 return self.fParent
77
78
79class PdfClassField:
edisonn@google.com45327112013-06-13 20:02:29 +000080 def __init__(self, parent, required, version='', inheritable=False, comment=''):
edisonn@google.comaf3daa02013-06-12 19:07:45 +000081 #self.fProp = ''
edisonn@google.com1a191c62013-06-11 21:44:08 +000082 self.fParent = parent
83 self.fRequired = required
edisonn@google.com45327112013-06-13 20:02:29 +000084 self.fVersion = version
85 self.fInheritable = inheritable
86 self.fComment = comment
edisonn@google.com1a191c62013-06-11 21:44:08 +000087
edisonn@google.comaf3daa02013-06-12 19:07:45 +000088 def field(self, name, abr=''):
89 self.fProp = PdfField(self, name, abr)
90 return self.fProp
edisonn@google.com1a191c62013-06-11 21:44:08 +000091
92 def done(self):
93 return self.fParent
94
95class PdfClass:
edisonn@google.com45327112013-06-13 20:02:29 +000096 def __init__(self, name, base, comment):
edisonn@google.com1a191c62013-06-11 21:44:08 +000097 self.fFields = []
98 self.fIncludes = []
edisonn@google.comaf3daa02013-06-12 19:07:45 +000099 self.fCCPublic = []
100 self.fCCPrivate = []
edisonn@google.com1a191c62013-06-11 21:44:08 +0000101 self.fName = name
102 self.fBase = base
edisonn@google.com45327112013-06-13 20:02:29 +0000103 self.fComment = comment
edisonn@google.com1a191c62013-06-11 21:44:08 +0000104
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000105 self.fEnumSubclasses = []
106
107 self.fEnum = '!UNDEFINED'
108 self.fEnumEnd = '!UNDEFINED'
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000109 self.fCheck = ''
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000110
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000111 def check(self, ifCheck):
112 self.fCheck = ifCheck
113 return self
114
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000115 def required(self, badDefault):
edisonn@google.com1a191c62013-06-11 21:44:08 +0000116 field = PdfClassField(self, True)
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000117 field.fBadDefault = badDefault
edisonn@google.com1a191c62013-06-11 21:44:08 +0000118 self.fFields.append(field)
119 return field
120
121 def optional(self):
122 field = PdfClassField(self, False)
123 self.fFields.append(field)
124 return field
edisonn@google.com45327112013-06-13 20:02:29 +0000125
126 #([Required] [;] [inheritable] [;] [version]; [comments])
127 # version: PDF [d].[d]
128 # ; separate props
129 #inheritable
130 #version
131 #required, if
132 #optional, if
edisonn@google.com1a191c62013-06-11 21:44:08 +0000133
134 def include(self, path):
135 self.fIncludes.append(path)
136 return self
137
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000138 def carbonCopyPublic(self, cc):
139 self.fCCPublic.append(cc)
140 return self
141
142 def carbonCopyPrivate(self, cc):
143 self.fCCPrivate.append(cc)
edisonn@google.com1a191c62013-06-11 21:44:08 +0000144 return self
edisonn@google.com45327112013-06-13 20:02:29 +0000145
146 def done(self):
147 return
edisonn@google.com1a191c62013-06-11 21:44:08 +0000148
149class PdfClassManager:
150 def __init__(self):
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000151 self.fClasses = {}
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000152 self.fClassesNamesInOrder = []
edisonn@google.com1a191c62013-06-11 21:44:08 +0000153
edisonn@google.com45327112013-06-13 20:02:29 +0000154 def addClass(self, name, base='Object', comment=''):
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000155 if name == 'Object':
edisonn@google.com45327112013-06-13 20:02:29 +0000156 cls = PdfClass(name, '', comment)
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000157 else:
edisonn@google.com45327112013-06-13 20:02:29 +0000158 cls = PdfClass(name, base, comment)
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000159 self.fClasses[name] = cls
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000160 self.fClassesNamesInOrder.append(name)
edisonn@google.com1a191c62013-06-11 21:44:08 +0000161 return cls
162
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000163 def longName(self, name):
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000164 #return name
165 # TODO(edisonn): we need the long name to nenerate and sort enums, but we can generate them recursively
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000166 ret = ''
167 while name != '':
168 cls = self.fClasses[name]
169 ret = name + ret
170 name = cls.fBase
171
172 return ret
173
174
175 def writeEnum(self, enum, enumToCls):
176 print(' ' + enum + ',')
177 cls = enumToCls[enum]
178 cls.fEnumSubclasses.sort()
179
180 cnt = 0
181 for sub in cls.fEnumSubclasses:
182 self.writeEnum(cls.fEnumSubclasses[cnt], enumToCls)
183 cnt = cnt + 1
184
185 if cnt != 0:
186 print(' ' + cls.fEnumEnd + ',')
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000187
188
189 def writeAsNull(self, cls, enumToCls):
190 print(' virtual SkPdf' + cls.fName +'* as' + cls.fName + '() {return NULL;}')
191 print(' virtual const SkPdf' + cls.fName +'* as' + cls.fName + '() const {return NULL;}')
192 print
193
194 cnt = 0
195 for sub in cls.fEnumSubclasses:
196 self.writeAsNull(enumToCls[cls.fEnumSubclasses[cnt]], enumToCls)
197 cnt = cnt + 1
198
199
200 def writeAsFoo(self, cls, enumToCls):
201 # TODO(edisonn): add a container, with sections, public, private, default, ...
202 # the end code will be grouped
203
204 # me
205 print('public:')
206 print(' virtual SkPdf' + cls.fName +'* as' + cls.fName + '() {return this;}')
207 print(' virtual const SkPdf' + cls.fName +'* as' + cls.fName + '() const {return this;}')
208 print
209
210 if cls.fName == 'Object':
211 cnt = 0
212 for sub in cls.fEnumSubclasses:
213 self.writeAsNull(enumToCls[cls.fEnumSubclasses[cnt]], enumToCls)
214 cnt = cnt + 1
215
216 if cls.fName != 'Object':
217 print('private:')
218 base = self.fClasses[cls.fBase]
219 cnt = 0
220 for sub in base.fEnumSubclasses:
221 if enumToCls[base.fEnumSubclasses[cnt]].fName != cls.fName:
222 self.writeAsNull(enumToCls[base.fEnumSubclasses[cnt]], enumToCls)
223 cnt = cnt + 1
224
225
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000226
edisonn@google.com1a191c62013-06-11 21:44:08 +0000227 def write(self):
edisonn@google.com1277cf02013-06-17 23:36:45 +0000228
229 global knowTypes
230
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000231 # generate enum
232 enumsRoot = []
233
234 enumToCls = {}
235
236 for name in self.fClasses:
237 cls = self.fClasses[name]
238 enum = self.longName(name)
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000239 cls.fEnum = 'k' + enum + '_SkPdfObjectType'
240 cls.fEnumEnd = 'k' + enum + '__End_SkPdfObjectType'
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000241
242 if cls.fBase != '':
243 self.fClasses[cls.fBase].fEnumSubclasses.append(cls.fEnum)
244
245 if cls.fBase == '':
246 enumsRoot.append(cls.fEnum)
247
248 enumToCls[cls.fEnum] = cls
249
250 enumsRoot.sort()
251
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000252
253 # TODO(edisonn): move each .h in it's own file
254 # write imports
255
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000256 # write enums
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000257 print('enum SkPdfObjectType {')
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000258 for enum in enumsRoot:
259 self.writeEnum(enum, enumToCls)
260 print('};')
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000261 print
262
263 # write forward class declaration
264 for name in self.fClassesNamesInOrder:
265 print('class SkPdf' + name + ';')
266 print
267
268 for name in self.fClassesNamesInOrder:
269 cls = self.fClasses[name]
270 enum = cls.fEnum
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000271
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000272 if cls.fBase == '':
273 print('class SkPdf' + cls.fName + ' {')
274 else:
275 print('class SkPdf' + cls.fName + ' : public SkPdf' + cls.fBase + ' {')
276
277 print('public:')
278 print(' virtual SkPdfObjectType getType() const { return ' + cls.fEnum + ';}')
279 if len(cls.fEnumSubclasses) == 0:
280 print(' virtual SkPdfObjectType getTypeEnd() const { return (SkPdfObjectType)(' + cls.fEnum + ' + 1);}')
281 else:
282 print(' virtual SkPdfObjectType getTypeEnd() const { return ' + cls.fEnumEnd + ';}')
283
284
285 self.writeAsFoo(cls, enumToCls)
286
287 print('public:')
288 for cc in cls.fCCPublic:
289 print(' ' + cc)
290
291 print('private:')
292 for cc in cls.fCCPrivate:
293 print(' ' + cc)
294
295 if cls.fBase == '':
296 print('protected:')
297 print(' const PdfMemDocument* fPodofoDoc;')
298 print(' const PdfObject* fPodofoObj;')
299 print
300 print('public:')
edisonn@google.com68d15c82013-06-17 20:46:27 +0000301 print(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc = NULL, const PdfObject* podofoObj = NULL) : fPodofoDoc(podofoDoc), fPodofoObj(podofoObj) {}')
302 print(' const PdfMemDocument* doc() const { return fPodofoDoc;}')
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000303 print(' const PdfObject* podofo() const { return fPodofoObj;}')
304 else:
305 print('public:')
edisonn@google.com68d15c82013-06-17 20:46:27 +0000306 print(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc = NULL, const PdfObject* podofoObj = NULL) : SkPdf' + cls.fBase + '(podofoDoc, podofoObj) {}')
edisonn@google.com45327112013-06-13 20:02:29 +0000307 print
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000308
309 #check required fieds, also, there should be an internal_valid() manually wrote for complex
310 # situations
311 # right now valid return true
312 print(' virtual bool valid() const {return true;}')
edisonn@google.com45327112013-06-13 20:02:29 +0000313 print
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000314
edisonn@google.com68d15c82013-06-17 20:46:27 +0000315 print(' SkPdf' + cls.fName + '& operator=(const SkPdf' + cls.fName + '& from) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPodofoObj; return *this;}')
316 print
317
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000318 for field in cls.fFields:
319 prop = field.fProp
320 if prop.fCppName != '':
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000321 if prop.fCppName[0] == '[':
322 print('/*') # comment code of the atributes that can have any name
edisonn@google.com1277cf02013-06-17 23:36:45 +0000323
324 # TODO(edisonn): has_foo();
325 print(' bool has_' + prop.fCppName + '() const {')
326 print(' return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", NULL));')
327 print(' }')
328
329 if len(prop.fTypes.split()) == 1:
330 t = prop.fTypes.strip()
331 print(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '() const {')
332 print(' ' + knowTypes[t][0] + ' ret;')
333 print(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPodofoObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) return ret;')
334 if field.fRequired == False and prop.fDefault != '':
335 print(' return ' + prop.fDefault.toCpp() + ';');
336 else:
337 print(' // TODO(edisonn): warn about missing required field, assert for known good pdfs')
338 print(' return ' + knowTypes[t][2].toCpp() + ';');
339 print(' }')
340 print
341 else:
342 for type in prop.fTypes.split():
343 t = type.strip()
344 print(' bool is' + prop.fCppName + 'A' + t.title() + '() const {')
345 print(' SkPdfObject* ret = NULL;')
346 print(' if (!ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) return false;')
347 print(' return ' + knowTypes[t][3] + ';')
348 print(' }')
349 print
350
351 print(' ' + knowTypes[t][0] + ' get' + prop.fCppName + 'As' + t.title() + '() const {')
352 print(' ' + knowTypes[t][0] + ' ret = ' + knowTypes[t][2].toCpp() + ';')
353 print(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPodofoObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) return ret;')
354 print(' // TODO(edisonn): warn about missing required field, assert for known good pdfs')
355 print(' return ' + knowTypes[t][2].toCpp() + ';')
356 print(' }')
357 print
358
edisonn@google.com45327112013-06-13 20:02:29 +0000359
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000360 if prop.fCppName[0] == '[':
361 print('*/') # comment code of the atributes that can have any name
edisonn@google.com45327112013-06-13 20:02:29 +0000362
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000363
364 print('};')
365 print
366 print
367
368
369
370 # generate constructor when knowing the type
371 # later, p2, generate constructor when not knowing the type - very similar with parsing?
372
edisonn@google.comf7dd4912013-06-11 23:06:16 +0000373 # generate parser
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000374
375 # TODO(edisonn): fast recognition based on must attributes.
376 print('class PodofoMapper {')
377 print('public:')
378 for name in self.fClassesNamesInOrder:
379 cls = self.fClasses[name]
380
edisonn@google.com68d15c82013-06-17 20:46:27 +0000381
382 print(' static bool map(const SkPdfObject& in, SkPdf' + name + '** out) {')
383 print(' return map(*in.doc(), *in.podofo(), out);')
384 print(' }')
385 print
386
387 print(' static bool map(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj, SkPdf' + name + '** out) {')
edisonn@google.com1277cf02013-06-17 23:36:45 +0000388 print(' if (!is' + name + '(podofoDoc, podofoObj)) return false;')
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000389 print
390
391 for sub in cls.fEnumSubclasses:
edisonn@google.com68d15c82013-06-17 20:46:27 +0000392 print(' if (map(podofoDoc, podofoObj, (SkPdf' + enumToCls[sub].fName + '**)out)) return true;')
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000393
394 print
395
396 print(' *out = new SkPdf' + name + '(&podofoDoc, &podofoObj);')
397 print(' return true;')
398 print(' }')
399 print
400
401 for name in self.fClassesNamesInOrder:
402 cls = self.fClasses[name]
403
edisonn@google.com1277cf02013-06-17 23:36:45 +0000404 print(' static bool is' + name + '(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj) {')
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000405
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000406 if cls.fCheck != '':
407 print(' return ' + cls.fCheck + ';')
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000408 else:
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000409 cntMust = 0
410 for field in cls.fFields:
411 prop = field.fProp
412 if prop.fHasMust:
413 cntMust = cntMust + 1
edisonn@google.com1277cf02013-06-17 23:36:45 +0000414 print(' ' + knowTypes[prop.fTypes.strip()][0] + ' ' + prop.fCppName + ';')
415 print(' if (!' + knowTypes[prop.fTypes.strip()][1] + '(&podofoDoc, podofoObj.GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &' + prop.fCppName + ')) return false;')
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000416 print(' if (' + prop.fCppName + ' != ' + prop.fMustBe.toCpp() + ') return false;')
417 print
418
edisonn@google.com68d15c82013-06-17 20:46:27 +0000419 print(' return true;')
edisonn@google.comaf3daa02013-06-12 19:07:45 +0000420
421 print(' }')
422 print
423
424 print('};')
425 print
426
edisonn@google.com1a191c62013-06-11 21:44:08 +0000427 return
428
429def generateCode():
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000430 manager = PdfClassManager()
edisonn@google.com1a191c62013-06-11 21:44:08 +0000431
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000432 manager.addClass('Object')
edisonn@google.com1a191c62013-06-11 21:44:08 +0000433
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000434 manager.addClass('Null').check('podofoObj.GetDataType() == ePdfDataType_Null')
edisonn@google.com60533dc2013-06-18 14:51:21 +0000435 manager.addClass('Boolean').check('podofoObj.GetDataType() == ePdfDataType_Bool')\
436 .carbonCopyPublic('bool value() const {return fPodofoObj->GetBool();}')
437
438 manager.addClass('Integer').check('podofoObj.GetDataType() == ePdfDataType_Number')\
439 .carbonCopyPublic('long value() const {return fPodofoObj->GetNumber();}')
440
441 manager.addClass('Number').check('podofoObj.GetDataType() == ePdfDataType_Real')\
442 .carbonCopyPublic('double value() const {return fPodofoObj->GetReal();}')
443
444 manager.addClass('Name').check('podofoObj.GetDataType() == ePdfDataType_Name')\
445 .carbonCopyPublic('const std::string& value() const {return fPodofoObj->GetName().GetName();}')
446
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000447 #manager.addClass('Stream') - attached to a dictionary
448 manager.addClass('Reference').check('podofoObj.GetDataType() == ePdfDataType_Reference')
edisonn@google.com60533dc2013-06-18 14:51:21 +0000449
450 manager.addClass('Array').check('podofoObj.GetDataType() == ePdfDataType_Array')\
451 .carbonCopyPublic('const int size() const {return fPodofoObj->GetArray().GetSize();}')\
452 .carbonCopyPublic('const SkPdfObject operator[](int i) const {return SkPdfObject(fPodofoDoc, &fPodofoObj->GetArray()[i]);}')\
453 .carbonCopyPublic('SkPdfObject operator[](int i) {return SkPdfObject(fPodofoDoc, &fPodofoObj->GetArray()[i]);}')
454
455 manager.addClass('String').check('podofoObj.GetDataType() == ePdfDataType_String')\
456 .carbonCopyPublic('const std::string& value() const {return fPodofoObj->GetString().GetStringUtf8();}')
457
458 manager.addClass('HexString').check('podofoObj.GetDataType() == ePdfDataType_HexString')\
459 .carbonCopyPublic('const std::string& value() const {return fPodofoObj->GetString().GetStringUtf8();}')
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000460
461 manager.addClass('Dictionary').check('podofoObj.GetDataType() == ePdfDataType_Dictionary')
462
463 # these classes are not explicitely backed by a table in the pdf spec
464 manager.addClass('XObjectDictionary', 'Dictionary')
465
466 manager.addClass('FontDictionary', 'Dictionary')
467
468 manager.addClass('TrueTypeFontDictionary', 'FontDictionary')
469
470 pdfspec_autogen.buildPdfSpec(manager)
edisonn@google.com1a191c62013-06-11 21:44:08 +0000471
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000472 manager.addClass('MultiMasterFontDictionary', 'Type1FontDictionary')\
473 .required('NULL')\
474 .field('Subtype')\
475 .name('Subtype')\
edisonn@google.com45327112013-06-13 20:02:29 +0000476 .type('name')\
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000477 .comment('')\
478 .must(datatypes.PdfName('MMType1'))\
edisonn@google.com45327112013-06-13 20:02:29 +0000479 .done().done()\
edisonn@google.com45327112013-06-13 20:02:29 +0000480
481
edisonn@google.coma2fab9d2013-06-14 19:22:19 +0000482 manager.write()
edisonn@google.com1a191c62013-06-11 21:44:08 +0000483
484 return 1
485
486if '__main__' == __name__:
487 sys.exit(generateCode())
edisonn@google.com45327112013-06-13 20:02:29 +0000488
489