| 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 from autogen.pdfspec_autogen import * |
| 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'], |
| 11 '(various)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true
'], | 11 '(various)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true
'], |
| 12 'array': ['SkPdfArray', 'ArrayFromDictionary', datatypes.PdfArrayNone(), 'ret->p
odofo()->GetDataType() == ePdfDataType_Array'], | 12 'array': ['SkPdfArray*', 'ArrayFromDictionary', datatypes.CppNull(), 'ret->podof
o()->GetDataType() == ePdfDataType_Array'], |
| 13 'boolean': ['bool', 'BoolFromDictionary', datatypes.PdfBoolean('false'), 'ret->p
odofo()->GetDataType() == ePdfDataType_Bool'], | 13 'boolean': ['bool', 'BoolFromDictionary', datatypes.PdfBoolean('false'), 'ret->p
odofo()->GetDataType() == ePdfDataType_Bool'], |
| 14 'date': ['SkPdfDate', 'DateFromDictionary', datatypes.PdfDateNever(), 'ret->podo
fo()->GetDataType() == ePdfDataType_Array'], | 14 'date': ['SkPdfDate', 'DateFromDictionary', datatypes.PdfDateNever(), 'ret->podo
fo()->GetDataType() == ePdfDataType_Array'], |
| 15 'dictionary': ['SkPdfDictionary*', 'DictionaryFromDictionary', datatypes.CppNull
(), 'ret->podofo()->GetDataType() == ePdfDataType_Dictionary'], | 15 'dictionary': ['SkPdfDictionary*', 'DictionaryFromDictionary', datatypes.CppNull
(), 'ret->podofo()->GetDataType() == ePdfDataType_Dictionary'], |
| 16 'function': ['SkPdfFunction', 'FunctionFromDictionary', datatypes.PdfFunctionNon
e(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'], | 16 'function': ['SkPdfFunction', 'FunctionFromDictionary', datatypes.PdfFunctionNon
e(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'], |
| 17 'integer': ['long', 'LongFromDictionary', datatypes.PdfInteger(0), 'ret->podofo(
)->GetDataType() == ePdfDataType_Number'], | 17 'integer': ['long', 'LongFromDictionary', datatypes.PdfInteger(0), 'ret->podofo(
)->GetDataType() == ePdfDataType_Number'], |
| 18 'file_specification': ['SkPdfFileSpec', 'FileSpecFromDictionary', datatypes.File
SpecNone(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'], | 18 'file_specification': ['SkPdfFileSpec', 'FileSpecFromDictionary', datatypes.File
SpecNone(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'], |
| 19 'name': ['std::string', 'NameFromDictionary', datatypes.PdfString('""'), 'ret->p
odofo()->GetDataType() == ePdfDataType_Name'], | 19 'name': ['std::string', 'NameFromDictionary', datatypes.PdfString('""'), 'ret->p
odofo()->GetDataType() == ePdfDataType_Name'], |
| 20 'tree': ['SkPdfTree*', 'TreeFromDictionary', datatypes.CppNull(), 'ret->podofo()
->GetDataType() == ePdfDataType_Reference'], | 20 'tree': ['SkPdfTree*', 'TreeFromDictionary', datatypes.CppNull(), 'ret->podofo()
->GetDataType() == ePdfDataType_Reference'], |
| 21 'number': ['double', 'DoubleFromDictionary', datatypes.PdfNumber(0), 'ret->podof
o()->GetDataType() == ePdfDataType_Real || ret->podofo()->GetDataType() == ePdfD
ataType_Number'], | 21 'number': ['double', 'DoubleFromDictionary', datatypes.PdfNumber(0), 'ret->podof
o()->GetDataType() == ePdfDataType_Real || ret->podofo()->GetDataType() == ePdfD
ataType_Number'], |
| 22 'rectangle': ['SkRect', 'SkRectFromDictionary', datatypes.PdfEmptyRect(), 'ret->
podofo()->GetDataType() == ePdfDataType_Array'], | 22 'rectangle': ['SkRect*', 'SkRectFromDictionary', datatypes.CppNull(), 'ret->podo
fo()->GetDataType() == ePdfDataType_Array && ret->podofo()->GetArray().GetLength
() == 4'], |
| 23 'stream': ['SkPdfStream*', 'StreamFromDictionary', datatypes.CppNull(), 'ret->p
odofo()->HasStream()'], | 23 'stream': ['SkPdfStream*', 'StreamFromDictionary', datatypes.CppNull(), 'ret->p
odofo()->HasStream()'], |
| 24 'string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 're
t->podofo()->GetDataType() == ePdfDataType_String || ret->podofo()->GetDataType(
) == ePdfDataType_HexString'], | 24 'string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 're
t->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'], | 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()->GetData
Type() == ePdfDataType_HexString'], | 26 'text string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""')
, 'ret->podofo()->GetDataType() == ePdfDataType_String || ret->podofo()->GetData
Type() == ePdfDataType_HexString'], |
| 27 'matrix': ['SkMatrix*', 'SkMatrixFromDictionary', datatypes.CppNull(), 'ret->pod
ofo()->GetDataType() == ePdfDataType_Array && ret->podofo()->GetArray().GetLengt
h() == 4'], |
| 27 } | 28 } |
| 28 | 29 |
| 29 | 30 |
| 30 class PdfField: | 31 class PdfField: |
| 31 def __init__(self, parent, name, abr): | 32 def __init__(self, parent, name, abr): |
| 32 self.fParent = parent | 33 self.fParent = parent |
| 33 self.fName = name | 34 self.fName = name |
| 34 self.fAbr = abr | 35 self.fAbr = abr |
| 35 | 36 |
| 36 self.fDefault = '' | 37 self.fDefault = '' |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 283 |
| 283 for name in self.fClassesNamesInOrder: | 284 for name in self.fClassesNamesInOrder: |
| 284 cls = self.fClasses[name] | 285 cls = self.fClasses[name] |
| 285 enum = cls.fEnum | 286 enum = cls.fEnum |
| 286 | 287 |
| 287 fileClass = open('SkPdf' + cls.fName + '_autogen.h', 'w') | 288 fileClass = open('SkPdf' + cls.fName + '_autogen.h', 'w') |
| 288 fileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') | 289 fileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') |
| 289 fileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') | 290 fileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') |
| 290 fileClass.write('\n') | 291 fileClass.write('\n') |
| 291 | 292 |
| 293 fileClass.write('#include "SkPdfUtils.h"\n') |
| 292 fileClass.write('#include "SkPdfEnums_autogen.h"\n') | 294 fileClass.write('#include "SkPdfEnums_autogen.h"\n') |
| 293 fileClass.write('#include "SkPdfArray_autogen.h"\n') | 295 fileClass.write('#include "SkPdfArray_autogen.h"\n') |
| 294 if cls.fBase != '': | 296 if cls.fBase != '': |
| 295 fileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n') | 297 fileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n') |
| 296 fileClass.write('\n') | 298 fileClass.write('\n') |
| 297 | 299 |
| 298 if cls.fComment != '': | 300 if cls.fComment != '': |
| 299 fileClass.write('// ' + cls.fComment + '\n') | 301 fileClass.write('// ' + cls.fComment + '\n') |
| 300 | 302 |
| 301 if cls.fBase == '': | 303 if cls.fBase == '': |
| (...skipping 18 matching lines...) Expand all Loading... |
| 320 for cc in cls.fCCPrivate: | 322 for cc in cls.fCCPrivate: |
| 321 fileClass.write(' ' + cc + '\n') | 323 fileClass.write(' ' + cc + '\n') |
| 322 | 324 |
| 323 if cls.fBase == '': | 325 if cls.fBase == '': |
| 324 fileClass.write('protected:\n') | 326 fileClass.write('protected:\n') |
| 325 fileClass.write(' const PdfMemDocument* fPodofoDoc;\n') | 327 fileClass.write(' const PdfMemDocument* fPodofoDoc;\n') |
| 326 fileClass.write(' const PdfObject* fPodofoObj;\n') | 328 fileClass.write(' const PdfObject* fPodofoObj;\n') |
| 327 fileClass.write('\n') | 329 fileClass.write('\n') |
| 328 fileClass.write('public:\n') | 330 fileClass.write('public:\n') |
| 329 fileClass.write(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDo
c = NULL, const PdfObject* podofoObj = NULL) : fPodofoDoc(podofoDoc), fPodofoObj
(podofoObj) {}\n') | 331 fileClass.write(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDo
c = NULL, const PdfObject* podofoObj = NULL) : fPodofoDoc(podofoDoc), fPodofoObj
(podofoObj) {}\n') |
| 332 fileClass.write(' SkPdf' + cls.fName + '(const SkPdf' + cls.fName + '&
from) : fPodofoDoc(from.fPodofoDoc), fPodofoObj(from.fPodofoObj) {}\n') |
| 333 fileClass.write('\n') |
| 330 fileClass.write(' const PdfMemDocument* doc() const { return fPodofoDoc
;}\n') | 334 fileClass.write(' const PdfMemDocument* doc() const { return fPodofoDoc
;}\n') |
| 331 fileClass.write(' const PdfObject* podofo() const { return fPodofoObj;}
\n') | 335 fileClass.write(' const PdfObject* podofo() const { return fPodofoObj;}
\n') |
| 332 else: | 336 else: |
| 333 fileClass.write('public:\n') | 337 fileClass.write('public:\n') |
| 334 fileClass.write(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDo
c = NULL, const PdfObject* podofoObj = NULL) : SkPdf' + cls.fBase + '(podofoDoc,
podofoObj) {}\n') | 338 fileClass.write(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDo
c = NULL, const PdfObject* podofoObj = NULL) : SkPdf' + cls.fBase + '(podofoDoc,
podofoObj) {}\n') |
| 335 fileClass.write('\n') | 339 fileClass.write('\n') |
| 340 fileClass.write(' SkPdf' + cls.fName + '(const SkPdf' + cls.fName + '&
from) : SkPdf' + cls.fBase + '(from.fPodofoDoc, from.fPodofoObj) {}\n') |
| 341 fileClass.write('\n') |
| 342 |
| 336 | 343 |
| 337 #check required fieds, also, there should be an internal_valid() manually
wrote for complex | 344 #check required fieds, also, there should be an internal_valid() manually
wrote for complex |
| 338 # situations | 345 # situations |
| 339 # right now valid return true | 346 # right now valid return true |
| 340 fileClass.write(' virtual bool valid() const {return true;}\n') | 347 fileClass.write(' virtual bool valid() const {return true;}\n') |
| 341 fileClass.write('\n') | 348 fileClass.write('\n') |
| 342 | 349 |
| 343 fileClass.write(' SkPdf' + cls.fName + '& operator=(const SkPdf' + cls.fN
ame + '& from) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPod
ofoObj; return *this;}\n') | 350 fileClass.write(' SkPdf' + cls.fName + '& operator=(const SkPdf' + cls.fN
ame + '& from) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPod
ofoObj; return *this;}\n') |
| 344 fileClass.write('\n') | 351 fileClass.write('\n') |
| 345 | 352 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 fileMapper.write('};\n') | 497 fileMapper.write('};\n') |
| 491 fileMapper.write('\n') | 498 fileMapper.write('\n') |
| 492 | 499 |
| 493 fileMapper.write('#endif // __DEFINED__SkPdfPodofoMapper\n') | 500 fileMapper.write('#endif // __DEFINED__SkPdfPodofoMapper\n') |
| 494 fileMapper.close() | 501 fileMapper.close() |
| 495 | 502 |
| 496 return | 503 return |
| 497 | 504 |
| 498 def generateCode(): | 505 def generateCode(): |
| 499 global fileHeaders | 506 global fileHeaders |
| 507 global knowTypes |
| 500 | 508 |
| 501 fileHeaders = open('SkPdfHeaders_autogen.h', 'w') | 509 fileHeaders = open('SkPdfHeaders_autogen.h', 'w') |
| 502 fileHeaders.write('#ifndef __DEFINED__SkPdfHeaders\n') | 510 fileHeaders.write('#ifndef __DEFINED__SkPdfHeaders\n') |
| 503 fileHeaders.write('#define __DEFINED__SkPdfHeaders\n') | 511 fileHeaders.write('#define __DEFINED__SkPdfHeaders\n') |
| 504 fileHeaders.write('\n') | 512 fileHeaders.write('\n') |
| 505 | 513 |
| 506 fileHeaders.write('#include "SkPdfEnums_autogen.h"\n') | 514 fileHeaders.write('#include "SkPdfEnums_autogen.h"\n') |
| 507 | 515 |
| 508 manager = PdfClassManager() | 516 manager = PdfClassManager() |
| 509 | 517 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 528 .carbonCopyPublic('const int size() const {return f
PodofoObj->GetArray().GetSize();}')\ | 536 .carbonCopyPublic('const int size() const {return f
PodofoObj->GetArray().GetSize();}')\ |
| 529 .carbonCopyPublic('SkPdfObject* operator[](int i) c
onst { SkPdfObject* ret = NULL; skpdfmap(*fPodofoDoc, fPodofoObj->GetArray()[i]
, &ret); return ret; }')\ | 537 .carbonCopyPublic('SkPdfObject* operator[](int i) c
onst { SkPdfObject* ret = NULL; skpdfmap(*fPodofoDoc, fPodofoObj->GetArray()[i]
, &ret); return ret; }')\ |
| 530 | 538 |
| 531 manager.addClass('String').check('podofoObj.GetDataType() == ePdfDataType_Stri
ng || podofoObj.GetDataType() == ePdfDataType_HexString')\ | 539 manager.addClass('String').check('podofoObj.GetDataType() == ePdfDataType_Stri
ng || podofoObj.GetDataType() == ePdfDataType_HexString')\ |
| 532 .carbonCopyPublic('const std::string& value() const
{return fPodofoObj->GetString().GetStringUtf8();}') | 540 .carbonCopyPublic('const std::string& value() const
{return fPodofoObj->GetString().GetStringUtf8();}') |
| 533 | 541 |
| 534 manager.addClass('HexString', 'String').check('podofoObj.GetDataType() == ePdf
DataType_HexString')\ | 542 manager.addClass('HexString', 'String').check('podofoObj.GetDataType() == ePdf
DataType_HexString')\ |
| 535 .carbonCopyPublic('const std::string& value() const
{return fPodofoObj->GetString().GetStringUtf8();}') | 543 .carbonCopyPublic('const std::string& value() const
{return fPodofoObj->GetString().GetStringUtf8();}') |
| 536 | 544 |
| 537 manager.addClass('Dictionary').check('podofoObj.GetDataType() == ePdfDataType_
Dictionary')\ | 545 manager.addClass('Dictionary').check('podofoObj.GetDataType() == ePdfDataType_
Dictionary')\ |
| 538 .carbonCopyPublic('const SkPdfObject get(const c
har* dictionaryKeyName) const {return SkPdfObject(fPodofoDoc, resolveReferenceOb
ject(fPodofoDoc, fPodofoObj->GetDictionary().GetKey(PdfName(dictionaryKeyName)))
);}')\ | 546 .carbonCopyPublic('SkPdfObject* get(const char*
dictionaryKeyName) const {return new SkPdfObject(fPodofoDoc, resolveReferenceObj
ect(fPodofoDoc, fPodofoObj->GetDictionary().GetKey(PdfName(dictionaryKeyName))))
;}')\ |
| 539 .carbonCopyPublic('SkPdfObject get(const char* d
ictionaryKeyName) {return SkPdfObject(fPodofoDoc, resolveReferenceObject(fPodofo
Doc, fPodofoObj->GetDictionary().GetKey(PdfName(dictionaryKeyName))));}')\ | 547 .carbonCopyPublic('SkPdfObject* get(const char*
dictionaryKeyName) {return new SkPdfObject(fPodofoDoc, resolveReferenceObject(fP
odofoDoc, fPodofoObj->GetDictionary().GetKey(PdfName(dictionaryKeyName))));}')\ |
| 540 | 548 |
| 541 manager.addClass('Stream') # attached to a dictionary in podofo | 549 manager.addClass('Stream') # attached to a dictionary in podofo |
| 542 | 550 |
| 543 | 551 |
| 544 # these classes are not explicitely backed by a table in the pdf spec | 552 # these classes are not explicitely backed by a table in the pdf spec |
| 545 manager.addClass('XObjectDictionary', 'Dictionary') | 553 manager.addClass('XObjectDictionary', 'Dictionary') |
| 546 | 554 |
| 547 manager.addClass('FontDictionary', 'Dictionary') | 555 manager.addClass('FontDictionary', 'Dictionary') |
| 548 | 556 |
| 549 manager.addClass('TrueTypeFontDictionary', 'Type1FontDictionary')\ | 557 manager.addClass('TrueTypeFontDictionary', 'Type1FontDictionary')\ |
| 550 .required('NULL')\ | 558 .required('NULL')\ |
| 551 .field('Subtype')\ | 559 .field('Subtype')\ |
| 552 .name('Subtype')\ | 560 .name('Subtype')\ |
| 553 .type('name')\ | 561 .type('name')\ |
| 554 .comment('')\ | 562 .comment('')\ |
| 555 .must([datatypes.PdfName('TrueType')])\ | 563 .must([datatypes.PdfName('TrueType')])\ |
| 556 .done().done()\ | 564 .done().done()\ |
| 557 | 565 |
| 558 pdfspec_autogen.buildPdfSpec(manager) | 566 |
| 567 addDictionaryTypesTo(knowTypes) |
| 568 buildPdfSpec(manager) |
| 559 | 569 |
| 560 manager.addClass('MultiMasterFontDictionary', 'Type1FontDictionary')\ | 570 manager.addClass('MultiMasterFontDictionary', 'Type1FontDictionary')\ |
| 561 .required('NULL')\ | 571 .required('NULL')\ |
| 562 .field('Subtype')\ | 572 .field('Subtype')\ |
| 563 .name('Subtype')\ | 573 .name('Subtype')\ |
| 564 .type('name')\ | 574 .type('name')\ |
| 565 .comment('')\ | 575 .comment('')\ |
| 566 .must([datatypes.PdfName('MMType1')])\ | 576 .must([datatypes.PdfName('MMType1')])\ |
| 567 .done().done()\ | 577 .done().done()\ |
| 568 | 578 |
| 569 | 579 |
| 570 manager.write() | 580 manager.write() |
| 571 | 581 |
| 572 fileHeaders.write('#endif // __DEFINED__SkPdfHeaders\n') | 582 fileHeaders.write('#endif // __DEFINED__SkPdfHeaders\n') |
| 573 fileHeaders.close() | 583 fileHeaders.close() |
| 574 | 584 |
| 575 return 1 | 585 return 1 |
| 576 | 586 |
| 577 if '__main__' == __name__: | 587 if '__main__' == __name__: |
| 578 sys.exit(generateCode()) | 588 sys.exit(generateCode()) |
| 579 | 589 |
| OLD | NEW |