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

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

Issue 18536014: pdfviewer: more load references dinamically plumming (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 2
3 import sys 3 import sys
4 4
5 import datatypes 5 import datatypes
6 from autogen.pdfspec_autogen import * 6 from autogen.pdfspec_autogen import *
7 7
8 # TODO(edisonn): date and some other types are in fact strings, with a custom fo rmat!!! 8 # TODO(edisonn): date and some other types are in fact strings, with a custom fo rmat!!!
9 # TODO(edisonn): refer to page 99 (PDF data types) 9 # TODO(edisonn): refer to page 99 (PDF data types)
10 knowTypes = { 10 knowTypes = {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 nativeFileClass.write('**/\n') 367 nativeFileClass.write('**/\n')
368 368
369 if prop.fCppName[0] == '[': 369 if prop.fCppName[0] == '[':
370 nativeFileClass.write('/*\n') # comment code of the atributes that can have any name 370 nativeFileClass.write('/*\n') # comment code of the atributes that can have any name
371 nativeFileClassCpp.write('/*\n') # comment code of the atributes th at can have any name 371 nativeFileClassCpp.write('/*\n') # comment code of the atributes th at can have any name
372 372
373 373
374 if len(prop.fTypes.split()) == 1: 374 if len(prop.fTypes.split()) == 1:
375 t = prop.fTypes.strip() 375 t = prop.fTypes.strip()
376 376
377 nativeFileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '(const SkNativeParsedPDF* doc);\n') 377 nativeFileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '(SkNativeParsedPDF* doc);\n')
378 nativeFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + '::' + prop.fCppName + '(const SkNativeParsedPDF* doc) {\n') 378 nativeFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + '::' + prop.fCppName + '(SkNativeParsedPDF* doc) {\n')
379 nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fName + '\", \"' + prop.fAbr + '\");\n') 379 nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fName + '\", \"' + prop.fAbr + '\");\n')
380 nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference(re t);}\n') 380 nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference(re t);}\n')
381 nativeFileClassCpp.write(' if ((ret != NULL && ' + knowTypes[t][3] + ') || (doc == NULL && ret != NULL && ret->isReference())) return ' + knowTypes [t][1] + ';\n') 381 nativeFileClassCpp.write(' if ((ret != NULL && ' + knowTypes[t][3] + ') || (doc == NULL && ret != NULL && ret->isReference())) return ' + knowTypes [t][1] + ';\n')
382 382
383 if field.fRequired: 383 if field.fRequired:
384 nativeFileClassCpp.write(' // TODO(edisonn): warn about missing r equired field, assert for known good pdfs\n') 384 nativeFileClassCpp.write(' // TODO(edisonn): warn about missing r equired field, assert for known good pdfs\n')
385 nativeFileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ' ;\n'); 385 nativeFileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ' ;\n');
386 elif prop.fDefault != '': 386 elif prop.fDefault != '':
387 nativeFileClassCpp.write(' return ' + prop.fDefault.toCpp() + ';\ n'); 387 nativeFileClassCpp.write(' return ' + prop.fDefault.toCpp() + ';\ n');
388 else: 388 else:
389 nativeFileClassCpp.write(' // TODO(edisonn): warn about missing d efault value for optional fields\n') 389 nativeFileClassCpp.write(' // TODO(edisonn): warn about missing d efault value for optional fields\n')
390 nativeFileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ' ;\n'); 390 nativeFileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ' ;\n');
391 391
392 nativeFileClassCpp.write('}\n') 392 nativeFileClassCpp.write('}\n')
393 nativeFileClassCpp.write('\n') 393 nativeFileClassCpp.write('\n')
394 else: 394 else:
395 for type in prop.fTypes.split(): 395 for type in prop.fTypes.split():
396 t = type.strip() 396 t = type.strip()
397 397
398 nativeFileClass.write(' bool is' + prop.fCppName + 'A' + t.title( ) + '(const SkNativeParsedPDF* doc);\n') 398 nativeFileClass.write(' bool is' + prop.fCppName + 'A' + t.title( ) + '(SkNativeParsedPDF* doc);\n')
399 399
400 nativeFileClassCpp.write('bool SkPdf' + cls.fName + '::is' + prop. fCppName + 'A' + t.title() + '(const SkNativeParsedPDF* doc) {\n') 400 nativeFileClassCpp.write('bool SkPdf' + cls.fName + '::is' + prop. fCppName + 'A' + t.title() + '(SkNativeParsedPDF* doc) {\n')
401 nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fNam e + '\", \"' + prop.fAbr + '\");\n') 401 nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fNam e + '\", \"' + prop.fAbr + '\");\n')
402 nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference( ret);}\n') 402 nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference( ret);}\n')
403 nativeFileClassCpp.write(' return ret != NULL && ' + knowTypes[t] [3] + ';\n') 403 nativeFileClassCpp.write(' return ret != NULL && ' + knowTypes[t] [3] + ';\n')
404 nativeFileClassCpp.write('}\n') 404 nativeFileClassCpp.write('}\n')
405 nativeFileClassCpp.write('\n') 405 nativeFileClassCpp.write('\n')
406 406
407 nativeFileClass.write(' ' + knowTypes[t][0] + ' get' + prop.fCppN ame + 'As' + t.title() + '(const SkNativeParsedPDF* doc);\n') 407 nativeFileClass.write(' ' + knowTypes[t][0] + ' get' + prop.fCppN ame + 'As' + t.title() + '(SkNativeParsedPDF* doc);\n')
408 nativeFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fNa me + '::get' + prop.fCppName + 'As' + t.title() + '(const SkNativeParsedPDF* doc ) {\n') 408 nativeFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fNa me + '::get' + prop.fCppName + 'As' + t.title() + '(SkNativeParsedPDF* doc) {\n' )
409 409
410 nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fNam e + '\", \"' + prop.fAbr + '\");\n') 410 nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fNam e + '\", \"' + prop.fAbr + '\");\n')
411 nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference( ret);}\n') 411 nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference( ret);}\n')
412 nativeFileClassCpp.write(' if ((ret != NULL && ' + knowTypes[t][3 ] + ') || (doc == NULL && ret != NULL && ret->isReference())) return ' + knowTyp es[t][1] + ';\n') 412 nativeFileClassCpp.write(' if ((ret != NULL && ' + knowTypes[t][3 ] + ') || (doc == NULL && ret != NULL && ret->isReference())) return ' + knowTyp es[t][1] + ';\n')
413 413
414 414
415 if field.fRequired: 415 if field.fRequired:
416 nativeFileClassCpp.write(' // TODO(edisonn): warn about missing required field, assert for known good pdfs\n') 416 nativeFileClassCpp.write(' // TODO(edisonn): warn about missing required field, assert for known good pdfs\n')
417 nativeFileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ';\n'); 417 nativeFileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ';\n');
418 elif prop.fDefault != '': 418 elif prop.fDefault != '':
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 fileMapperNative.write('#include "SkPdfObject.h"\n') 461 fileMapperNative.write('#include "SkPdfObject.h"\n')
462 462
463 463
464 fileMapperNativeCpp.write('#include "SkPdfMapper_autogen.h"\n') 464 fileMapperNativeCpp.write('#include "SkPdfMapper_autogen.h"\n')
465 fileMapperNativeCpp.write('#include "SkPdfUtils.h"\n') 465 fileMapperNativeCpp.write('#include "SkPdfUtils.h"\n')
466 fileMapperNativeCpp.write('#include "SkPdfObject.h"\n') 466 fileMapperNativeCpp.write('#include "SkPdfObject.h"\n')
467 fileMapperNativeCpp.write('\n') 467 fileMapperNativeCpp.write('\n')
468 468
469 fileMapperNative.write('class SkPdfMapper {\n') 469 fileMapperNative.write('class SkPdfMapper {\n')
470 470
471 fileMapperNative.write(' const SkNativeParsedPDF* fParsedDoc;\n') 471 fileMapperNative.write(' SkNativeParsedPDF* fParsedDoc;\n')
472 472
473 fileMapperNative.write('public:\n') 473 fileMapperNative.write('public:\n')
474 474
475 fileMapperNative.write(' SkPdfMapper(const SkNativeParsedPDF* doc) : fParse dDoc(doc) {}\n') 475 fileMapperNative.write(' SkPdfMapper(SkNativeParsedPDF* doc) : fParsedDoc(d oc) {}\n')
476 fileMapperNative.write('\n') 476 fileMapperNative.write('\n')
477 477
478 for name in self.fClassesNamesInOrder: 478 for name in self.fClassesNamesInOrder:
479 cls = self.fClasses[name] 479 cls = self.fClasses[name]
480 480
481 fileMapperNative.write(' SkPdfObjectType map' + name + '(const SkPdfObjec t* in) const;\n') 481 fileMapperNative.write(' SkPdfObjectType map' + name + '(const SkPdfObjec t* in) const;\n')
482 482
483 fileMapperNativeCpp.write('SkPdfObjectType SkPdfMapper::map' + name + '(co nst SkPdfObject* in) const {\n') 483 fileMapperNativeCpp.write('SkPdfObjectType SkPdfMapper::map' + name + '(co nst SkPdfObject* in) const {\n')
484 fileMapperNativeCpp.write(' if (!is' + name + '(in)) return kNone_SkPdfOb jectType;\n') 484 fileMapperNativeCpp.write(' if (!is' + name + '(in)) return kNone_SkPdfOb jectType;\n')
485 fileMapperNativeCpp.write('\n') 485 fileMapperNativeCpp.write('\n')
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 617
618 fileHeadersNative.write('#endif // __DEFINED__SkPdfHeaders\n') 618 fileHeadersNative.write('#endif // __DEFINED__SkPdfHeaders\n')
619 619
620 fileHeadersNative.close() 620 fileHeadersNative.close()
621 fileHeadersNativeCpp.close() 621 fileHeadersNativeCpp.close()
622 622
623 if '__main__' == __name__: 623 if '__main__' == __name__:
624 #print sys.argv 624 #print sys.argv
625 sys.exit(generateCode()) 625 sys.exit(generateCode())
626 626
OLDNEW
« no previous file with comments | « no previous file | experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698