OLD | NEW |
1 | 1 |
2 | 2 |
| 3 import os |
3 import sys | 4 import sys |
4 | 5 |
5 import datatypes | 6 import datatypes |
6 from autogen.pdfspec_autogen import * | 7 from autogen.pdfspec_autogen import * |
7 | 8 |
8 # TODO(edisonn): date and some other types are in fact strings, with a custom fo
rmat!!! | 9 # 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) | 10 # TODO(edisonn): refer to page 99 (PDF data types) |
10 knowTypes = { | 11 knowTypes = { |
11 '(any)': ['SkPdfObject*', 'ret', datatypes.CppNull(), 'true', 'use a mapper'], | 12 '(any)': ['SkPdfObject*', 'ret', datatypes.CppNull(), 'true', 'use a mapper'], |
12 # TODO(edisonn): return constant for undefined | 13 # TODO(edisonn): return constant for undefined |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 268 |
268 enumToCls[cls.fEnum] = cls | 269 enumToCls[cls.fEnum] = cls |
269 | 270 |
270 enumsRoot.sort() | 271 enumsRoot.sort() |
271 | 272 |
272 | 273 |
273 # TODO(edisonn): move each .h in it's own file | 274 # TODO(edisonn): move each .h in it's own file |
274 # write imports | 275 # write imports |
275 | 276 |
276 # write enums | 277 # write enums |
277 fileEnums = open(sys.argv[1] + 'autogen/SkPdfEnums_autogen.h', 'w') | 278 fileEnums = open(os.path.join(sys.argv[1], 'autogen', 'SkPdfEnums_autogen.h'
), 'w') |
278 fileEnums.write('#ifndef __DEFINED__SkPdfEnums\n') | 279 fileEnums.write('#ifndef __DEFINED__SkPdfEnums\n') |
279 fileEnums.write('#define __DEFINED__SkPdfEnums\n') | 280 fileEnums.write('#define __DEFINED__SkPdfEnums\n') |
280 fileEnums.write('\n') | 281 fileEnums.write('\n') |
281 | 282 |
282 fileEnums.write('enum SkPdfObjectType {\n') | 283 fileEnums.write('enum SkPdfObjectType {\n') |
283 fileEnums.write(' kNone_SkPdfObjectType = 0,\n') | 284 fileEnums.write(' kNone_SkPdfObjectType = 0,\n') |
284 for enum in enumsRoot: | 285 for enum in enumsRoot: |
285 self.writeEnum(fileEnums, enum, enumToCls) | 286 self.writeEnum(fileEnums, enum, enumToCls) |
286 fileEnums.write('};\n') | 287 fileEnums.write('};\n') |
287 fileEnums.write('\n') | 288 fileEnums.write('\n') |
288 | 289 |
289 # write forward class declaration | 290 # write forward class declaration |
290 for name in self.fClassesNamesInOrder: | 291 for name in self.fClassesNamesInOrder: |
291 fileEnums.write('class SkPdf' + name + ';\n') | 292 fileEnums.write('class SkPdf' + name + ';\n') |
292 fileEnums.write('\n') | 293 fileEnums.write('\n') |
293 | 294 |
294 fileEnums.write('#endif // __DEFINED__SkPdfEnums\n') | 295 fileEnums.write('#endif // __DEFINED__SkPdfEnums\n') |
295 fileEnums.close() | 296 fileEnums.close() |
296 | 297 |
297 for name in self.fClassesNamesInOrder: | 298 for name in self.fClassesNamesInOrder: |
298 cls = self.fClasses[name] | 299 cls = self.fClasses[name] |
299 enum = cls.fEnum | 300 enum = cls.fEnum |
300 | 301 |
301 nativeFileClass = open(sys.argv[1] + 'native/autogen/SkPdf' + cls.fName +
'_autogen.h', 'w') | 302 nativeFileClass = open(os.path.join(sys.argv[1], 'native', 'autogen', 'SkP
df' + cls.fName + '_autogen.h'), 'w') |
302 nativeFileClassCpp = open(sys.argv[1] + 'native/autogen/SkPdf' + cls.fName
+ '_autogen.cpp', 'w') | 303 nativeFileClassCpp = open(os.path.join(sys.argv[1], 'native', 'autogen', '
SkPdf' + cls.fName + '_autogen.cpp'), 'w') |
303 | 304 |
304 nativeFileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') | 305 nativeFileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') |
305 nativeFileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') | 306 nativeFileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') |
306 nativeFileClass.write('\n') | 307 nativeFileClass.write('\n') |
307 | 308 |
308 nativeFileClassCpp.write('#include "SkPdf' + cls.fName + '_autogen.h"\n\n'
) | 309 nativeFileClassCpp.write('#include "SkPdf' + cls.fName + '_autogen.h"\n\n'
) |
309 nativeFileClassCpp.write('\n') | 310 nativeFileClassCpp.write('\n') |
310 | 311 |
311 | 312 |
312 if cls.fBase == '': | 313 if cls.fBase == '': |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 nativeFileClass.write('#endif // __DEFINED__NATIVE_SkPdf' + cls.fName + '
\n') | 443 nativeFileClass.write('#endif // __DEFINED__NATIVE_SkPdf' + cls.fName + '
\n') |
443 | 444 |
444 nativeFileClass.close() | 445 nativeFileClass.close() |
445 nativeFileClassCpp.close() | 446 nativeFileClassCpp.close() |
446 | 447 |
447 # generate constructor when knowing the type | 448 # generate constructor when knowing the type |
448 # later, p2, generate constructor when not knowing the type - very similar
with parsing? | 449 # later, p2, generate constructor when not knowing the type - very similar
with parsing? |
449 | 450 |
450 # generate parser | 451 # generate parser |
451 # TODO(edisonn): fast recognition based on must attributes. | 452 # TODO(edisonn): fast recognition based on must attributes. |
452 fileMapperNative = open(sys.argv[1] + 'native/autogen/SkPdfMapper_autogen.h'
, 'w') | 453 fileMapperNative = open(os.path.join(sys.argv[1], 'native', 'autogen', 'SkPd
fMapper_autogen.h'), 'w') |
453 fileMapperNativeCpp = open(sys.argv[1] + 'native/autogen/SkPdfMapper_autogen
.cpp', 'w') | 454 fileMapperNativeCpp = open(os.path.join(sys.argv[1], 'native', 'autogen', 'S
kPdfMapper_autogen.cpp'), 'w') |
454 | 455 |
455 fileMapperNative.write('#ifndef __DEFINED__SkPdfMapper\n') | 456 fileMapperNative.write('#ifndef __DEFINED__SkPdfMapper\n') |
456 fileMapperNative.write('#define __DEFINED__SkPdfMapper\n') | 457 fileMapperNative.write('#define __DEFINED__SkPdfMapper\n') |
457 fileMapperNative.write('\n') | 458 fileMapperNative.write('\n') |
458 | 459 |
459 fileMapperNative.write('#include "SkPdfHeaders_autogen.h"\n') | 460 fileMapperNative.write('#include "SkPdfHeaders_autogen.h"\n') |
460 fileMapperNative.write('#include "SkNativeParsedPDF.h"\n') | 461 fileMapperNative.write('#include "SkNativeParsedPDF.h"\n') |
461 fileMapperNative.write('#include "SkPdfObject.h"\n') | 462 fileMapperNative.write('#include "SkPdfObject.h"\n') |
462 | 463 |
463 | 464 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 fileMapperNative.close() | 568 fileMapperNative.close() |
568 fileMapperNativeCpp.close() | 569 fileMapperNativeCpp.close() |
569 | 570 |
570 return | 571 return |
571 | 572 |
572 def generateCode(): | 573 def generateCode(): |
573 global fileHeadersNative | 574 global fileHeadersNative |
574 global fileHeadersNativeCpp | 575 global fileHeadersNativeCpp |
575 global knowTypes | 576 global knowTypes |
576 | 577 |
577 fileHeadersNative = open(sys.argv[1] + 'native/autogen/SkPdfHeaders_autogen.h'
, 'w') | 578 fileHeadersNative = open(os.path.join(sys.argv[1], 'native', 'autogen', 'SkPdf
Headers_autogen.h'), 'w') |
578 fileHeadersNativeCpp = open(sys.argv[1] + 'native/autogen/SkPdfHeaders_autogen
.cpp', 'w') | 579 fileHeadersNativeCpp = open(os.path.join(sys.argv[1], 'native', 'autogen', 'Sk
PdfHeaders_autogen.cpp'), 'w') |
579 | 580 |
580 fileHeadersNative.write('#ifndef __DEFINED__SkPdfHeaders\n') | 581 fileHeadersNative.write('#ifndef __DEFINED__SkPdfHeaders\n') |
581 fileHeadersNative.write('#define __DEFINED__SkPdfHeaders\n') | 582 fileHeadersNative.write('#define __DEFINED__SkPdfHeaders\n') |
582 fileHeadersNative.write('\n') | 583 fileHeadersNative.write('\n') |
583 | 584 |
584 fileHeadersNativeCpp.write('#include "SkPdfHeaders_autogen.h"\n') | 585 fileHeadersNativeCpp.write('#include "SkPdfHeaders_autogen.h"\n') |
585 | 586 |
586 manager = PdfClassManager() | 587 manager = PdfClassManager() |
587 | 588 |
588 # these classes are not explicitely backed by a table in the pdf spec | 589 # these classes are not explicitely backed by a table in the pdf spec |
(...skipping 28 matching lines...) Expand all Loading... |
617 | 618 |
618 fileHeadersNative.write('#endif // __DEFINED__SkPdfHeaders\n') | 619 fileHeadersNative.write('#endif // __DEFINED__SkPdfHeaders\n') |
619 | 620 |
620 fileHeadersNative.close() | 621 fileHeadersNative.close() |
621 fileHeadersNativeCpp.close() | 622 fileHeadersNativeCpp.close() |
622 | 623 |
623 if '__main__' == __name__: | 624 if '__main__' == __name__: |
624 #print sys.argv | 625 #print sys.argv |
625 sys.exit(generateCode()) | 626 sys.exit(generateCode()) |
626 | 627 |
OLD | NEW |