| OLD | NEW |
| 1 | 1 |
| 2 | 2 |
| 3 import sys | 3 import sys |
| 4 | 4 |
| 5 import datatypes | 5 import datatypes |
| 6 import pdfspec_autogen | 6 import pdfspec_autogen |
| 7 | 7 |
| 8 knowTypes = { | 8 knowTypes = { |
| 9 '(any)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true'], | 9 '(any)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true'], |
| 10 '(undefined)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'tr
ue'], | 10 '(undefined)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'tr
ue'], |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 self.fParent = parent | 32 self.fParent = parent |
| 33 self.fName = name | 33 self.fName = name |
| 34 self.fAbr = abr | 34 self.fAbr = abr |
| 35 | 35 |
| 36 self.fDefault = '' | 36 self.fDefault = '' |
| 37 self.fTypes = '' | 37 self.fTypes = '' |
| 38 self.fCppName = '' | 38 self.fCppName = '' |
| 39 self.fEnumValues = [] | 39 self.fEnumValues = [] |
| 40 self.fHasMust = False | 40 self.fHasMust = False |
| 41 self.fMustBe = '' | 41 self.fMustBe = '' |
| 42 self.fComment = '' |
| 42 | 43 |
| 43 def must(self, value): | 44 def must(self, value): |
| 44 self.fHasMust = True | 45 self.fHasMust = True |
| 45 self.fMustBe = value | 46 self.fMustBe = value |
| 46 return self | 47 return self |
| 47 | 48 |
| 48 def default(self, value): | 49 def default(self, value): |
| 49 self.fDefault = value | 50 self.fDefault = value |
| 50 return self | 51 return self |
| 51 | 52 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 63 types = types.replace('or', ' ') | 64 types = types.replace('or', ' ') |
| 64 types = types.replace(',', ' ') | 65 types = types.replace(',', ' ') |
| 65 types = types.replace('text', ' ') # TODO(edisonn): what is the difference b
etween 'text string' and 'string'? | 66 types = types.replace('text', ' ') # TODO(edisonn): what is the difference b
etween 'text string' and 'string'? |
| 66 types = types.replace('file specification', 'file_specification') | 67 types = types.replace('file specification', 'file_specification') |
| 67 | 68 |
| 68 | 69 |
| 69 self.fTypes = types | 70 self.fTypes = types |
| 70 return self | 71 return self |
| 71 | 72 |
| 72 def comment(self, comment): | 73 def comment(self, comment): |
| 74 self.fComment = comment |
| 73 return self | 75 return self |
| 74 | 76 |
| 75 def done(self): | 77 def done(self): |
| 76 return self.fParent | 78 return self.fParent |
| 77 | 79 |
| 78 | 80 |
| 79 class PdfClassField: | 81 class PdfClassField: |
| 80 def __init__(self, parent, required, version='', inheritable=False, comment=''
): | 82 def __init__(self, parent, required, version='', inheritable=False): |
| 81 #self.fProp = '' | 83 #self.fProp = '' |
| 82 self.fParent = parent | 84 self.fParent = parent |
| 83 self.fRequired = required | 85 self.fRequired = required |
| 84 self.fVersion = version | 86 self.fVersion = version |
| 85 self.fInheritable = inheritable | 87 self.fInheritable = inheritable |
| 86 self.fComment = comment | |
| 87 | 88 |
| 88 def field(self, name, abr=''): | 89 def field(self, name, abr=''): |
| 89 self.fProp = PdfField(self, name, abr) | 90 self.fProp = PdfField(self, name, abr) |
| 90 return self.fProp | 91 return self.fProp |
| 91 | 92 |
| 92 def done(self): | 93 def done(self): |
| 93 return self.fParent | 94 return self.fParent |
| 94 | 95 |
| 95 class PdfClass: | 96 class PdfClass: |
| 96 def __init__(self, name, base, comment): | 97 def __init__(self, name, base, comment): |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 cls = self.fClasses[name] | 267 cls = self.fClasses[name] |
| 267 enum = cls.fEnum | 268 enum = cls.fEnum |
| 268 | 269 |
| 269 fileClass = open('SkPdf' + cls.fName + '_autogen.h', 'w') | 270 fileClass = open('SkPdf' + cls.fName + '_autogen.h', 'w') |
| 270 fileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') | 271 fileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') |
| 271 fileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') | 272 fileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') |
| 272 fileClass.write('\n') | 273 fileClass.write('\n') |
| 273 | 274 |
| 274 fileClass.write('#include "SkPdfEnums_autogen.h"\n') | 275 fileClass.write('#include "SkPdfEnums_autogen.h"\n') |
| 275 fileClass.write('#include "SkPdfArray_autogen.h"\n') | 276 fileClass.write('#include "SkPdfArray_autogen.h"\n') |
| 277 if cls.fBase != '': |
| 278 fileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n') |
| 279 fileClass.write('\n') |
| 280 |
| 281 if cls.fComment != '': |
| 282 fileClass.write('// ' + cls.fComment + '\n') |
| 276 | 283 |
| 277 if cls.fBase == '': | 284 if cls.fBase == '': |
| 278 fileClass.write('\nclass SkPdf' + cls.fName + ' {\n') | 285 fileClass.write('class SkPdf' + cls.fName + ' {\n') |
| 279 else: | 286 else: |
| 280 fileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n') | 287 fileClass.write('class SkPdf' + cls.fName + ' : public SkPdf' + cls.fBas
e + ' {\n') |
| 281 fileClass.write('\nclass SkPdf' + cls.fName + ' : public SkPdf' + cls.fB
ase + ' {\n') | |
| 282 | 288 |
| 283 fileClass.write('public:\n') | 289 fileClass.write('public:\n') |
| 284 fileClass.write(' virtual SkPdfObjectType getType() const { return ' + cl
s.fEnum + ';}\n') | 290 fileClass.write(' virtual SkPdfObjectType getType() const { return ' + cl
s.fEnum + ';}\n') |
| 285 if len(cls.fEnumSubclasses) == 0: | 291 if len(cls.fEnumSubclasses) == 0: |
| 286 fileClass.write(' virtual SkPdfObjectType getTypeEnd() const { return (
SkPdfObjectType)(' + cls.fEnum + ' + 1);}\n') | 292 fileClass.write(' virtual SkPdfObjectType getTypeEnd() const { return (
SkPdfObjectType)(' + cls.fEnum + ' + 1);}\n') |
| 287 else: | 293 else: |
| 288 fileClass.write(' virtual SkPdfObjectType getTypeEnd() const { return '
+ cls.fEnumEnd + ';}\n') | 294 fileClass.write(' virtual SkPdfObjectType getTypeEnd() const { return '
+ cls.fEnumEnd + ';}\n') |
| 289 | 295 |
| 290 self.writeAsFoo(fileClass, cls, enumToCls) | 296 self.writeAsFoo(fileClass, cls, enumToCls) |
| 291 | 297 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 316 # right now valid return true | 322 # right now valid return true |
| 317 fileClass.write(' virtual bool valid() const {return true;}\n') | 323 fileClass.write(' virtual bool valid() const {return true;}\n') |
| 318 fileClass.write('\n') | 324 fileClass.write('\n') |
| 319 | 325 |
| 320 fileClass.write(' SkPdf' + cls.fName + '& operator=(const SkPdf' + cls.fN
ame + '& from) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPod
ofoObj; return *this;}\n') | 326 fileClass.write(' SkPdf' + cls.fName + '& operator=(const SkPdf' + cls.fN
ame + '& from) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPod
ofoObj; return *this;}\n') |
| 321 fileClass.write('\n') | 327 fileClass.write('\n') |
| 322 | 328 |
| 323 for field in cls.fFields: | 329 for field in cls.fFields: |
| 324 prop = field.fProp | 330 prop = field.fProp |
| 325 if prop.fCppName != '': | 331 if prop.fCppName != '': |
| 332 |
| 333 lines = prop.fComment.split('\n') |
| 334 if prop.fComment != '' and len(lines) > 0: |
| 335 fileClass.write('/** ' + lines[0] + '\n') |
| 336 for line in lines[1:]: |
| 337 fileClass.write(' * ' + line + '\n') |
| 338 fileClass.write('**/\n') |
| 339 |
| 326 if prop.fCppName[0] == '[': | 340 if prop.fCppName[0] == '[': |
| 327 fileClass.write('/*\n') # comment code of the atributes that can ha
ve any name | 341 fileClass.write('/*\n') # comment code of the atributes that can ha
ve any name |
| 328 | 342 |
| 329 # TODO(edisonn): has_foo(); | 343 # TODO(edisonn): has_foo(); |
| 330 fileClass.write(' bool has_' + prop.fCppName + '() const {\n') | 344 fileClass.write(' bool has_' + prop.fCppName + '() const {\n') |
| 331 fileClass.write(' return (ObjectFromDictionary(fPodofoDoc, fPodof
oObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", NULL));\n'
) | 345 fileClass.write(' return (ObjectFromDictionary(fPodofoDoc, fPodofoO
bj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", NULL));\n') |
| 332 fileClass.write(' }\n') | 346 fileClass.write(' }\n') |
| 347 fileClass.write('\n') |
| 333 | 348 |
| 334 if len(prop.fTypes.split()) == 1: | 349 if len(prop.fTypes.split()) == 1: |
| 335 t = prop.fTypes.strip() | 350 t = prop.fTypes.strip() |
| 336 fileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '() c
onst {\n') | 351 fileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '() c
onst {\n') |
| 337 fileClass.write(' ' + knowTypes[t][0] + ' ret;\n') | 352 fileClass.write(' ' + knowTypes[t][0] + ' ret;\n') |
| 338 fileClass.write(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPodofo
Obj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) retu
rn ret;\n') | 353 fileClass.write(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPodofo
Obj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) retu
rn ret;\n') |
| 339 if field.fRequired == False and prop.fDefault != '': | 354 if field.fRequired == False and prop.fDefault != '': |
| 340 fileClass.write(' return ' + prop.fDefault.toCpp() + ';\n'); | 355 fileClass.write(' return ' + prop.fDefault.toCpp() + ';\n'); |
| 341 else: | 356 else: |
| 342 fileClass.write(' // TODO(edisonn): warn about missing required
field, assert for known good pdfs\n') | 357 fileClass.write(' // TODO(edisonn): warn about missing required
field, assert for known good pdfs\n') |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 manager.write() | 524 manager.write() |
| 510 | 525 |
| 511 fileHeaders.write('#endif // __DEFINED__SkPdfHeaders\n') | 526 fileHeaders.write('#endif // __DEFINED__SkPdfHeaders\n') |
| 512 fileHeaders.close() | 527 fileHeaders.close() |
| 513 | 528 |
| 514 return 1 | 529 return 1 |
| 515 | 530 |
| 516 if '__main__' == __name__: | 531 if '__main__' == __name__: |
| 517 sys.exit(generateCode()) | 532 sys.exit(generateCode()) |
| 518 | 533 |
| OLD | NEW |