OLD | NEW |
1 #!/usr/local/bin/python | 1 #!/usr/local/bin/python |
2 # coding: utf-8 | 2 # coding: utf-8 |
3 | 3 |
4 import sys | 4 import sys |
5 import re | 5 import re |
6 | 6 |
7 # TODO(edisonn): put processed part of file in a new file | 7 # TODO(edisonn): put processed part of file in a new file |
8 # put unprocessed part, in a new file, so we see what we miss | 8 # put unprocessed part, in a new file, so we see what we miss |
9 # keep blank lines, and generate a version without the blank lines | 9 # keep blank lines, and generate a version without the blank lines |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 'TABLE 5.16': ['CMapDictionary', 'Additional entries in a CMap dictionary'], | 109 'TABLE 5.16': ['CMapDictionary', 'Additional entries in a CMap dictionary'], |
110 'TABLE 5.17': ['Type0FontDictionary', 'Entries in a Type 0 font dictionary', 'Fo
ntDictionary', {'Subtype': '[datatypes.PdfName(\'Type0\')]'}], | 110 'TABLE 5.17': ['Type0FontDictionary', 'Entries in a Type 0 font dictionary', 'Fo
ntDictionary', {'Subtype': '[datatypes.PdfName(\'Type0\')]'}], |
111 'TABLE 5.18': ['FontDescriptorDictionary', 'Entries common to all font descripto
rs', '', {'Type': '[datatypes.PdfName(\'FontDescriptor\')]'}], | 111 'TABLE 5.18': ['FontDescriptorDictionary', 'Entries common to all font descripto
rs', '', {'Type': '[datatypes.PdfName(\'FontDescriptor\')]'}], |
112 'TABLE 5.20': ['CIDFontDescriptorDictionary', 'Additional font descriptor entrie
s for CIDFonts'], | 112 'TABLE 5.20': ['CIDFontDescriptorDictionary', 'Additional font descriptor entrie
s for CIDFonts'], |
113 'TABLE 5.23': ['EmbeddedFontStreamDictionary', 'Additional entries in an embedde
d font stream dictionary'], | 113 'TABLE 5.23': ['EmbeddedFontStreamDictionary', 'Additional entries in an embedde
d font stream dictionary'], |
114 'TABLE 6.3': ['Type1HalftoneDictionary', 'Entries in a type 1 halftone dictionar
y'], | 114 'TABLE 6.3': ['Type1HalftoneDictionary', 'Entries in a type 1 halftone dictionar
y'], |
115 'TABLE 6.4': ['Type6HalftoneDictionary', 'Additional entries specific to a type
6 halftone dictionary'], | 115 'TABLE 6.4': ['Type6HalftoneDictionary', 'Additional entries specific to a type
6 halftone dictionary'], |
116 'TABLE 6.5': ['Type10HalftoneDictionary', 'Additional entries specific to a type
10 halftone dictionary'], | 116 'TABLE 6.5': ['Type10HalftoneDictionary', 'Additional entries specific to a type
10 halftone dictionary'], |
117 'TABLE 6.6': ['Type16HalftoneDictionary', 'Additional entries specific to a type
16 halftone dictionary'], | 117 'TABLE 6.6': ['Type16HalftoneDictionary', 'Additional entries specific to a type
16 halftone dictionary'], |
118 'TABLE 6.7': ['Type5HalftoneDictionary', 'Entries in a type 5 halftone dictionar
y'], | 118 'TABLE 6.7': ['Type5HalftoneDictionary', 'Entries in a type 5 halftone dictionar
y'], |
119 'TABLE 7.10': ['SoftMaskDictionary', 'Entries in a soft-mask dictionary'], | 119 'TABLE 7.10': ['SoftMaskDictionary', 'Entries in a soft-mask dictionary', '', {'
S': '[datatypes.PdfName(\'Alpha\'), datatypes.PdfName(\'Luminosity\')]'}], |
120 'TABLE 7.12': ['SoftMaskImageDictionary', 'Additional entry in a soft-mask image
dictionary'], | 120 'TABLE 7.12': ['SoftMaskImageDictionary', 'Additional entry in a soft-mask image
dictionary', 'ImageDictionary', {'Subtype': '[datatypes.PdfName(\'Image\')]', '
ColorSpace': '[datatypes.PdfName(\'DeviceGray\'), datatypes.PdfName(\'Gray\')]'}
], |
121 'TABLE 7.13': ['TransparencyGroupDictionary', 'Additional entries specific to a
transparency group attributes dictionary'], | 121 'TABLE 7.13': ['TransparencyGroupDictionary', 'Additional entries specific to a
transparency group attributes dictionary', 'XObjectDictionary', {'S': '[datatype
s.PdfName(\'Transparency\')]'}], |
122 'TABLE 8.1': ['ViewerPreferencesDictionary', 'Entries in a viewer preferences di
ctionary'], | 122 'TABLE 8.1': ['ViewerPreferencesDictionary', 'Entries in a viewer preferences di
ctionary'], |
123 'TABLE 8.3': ['OutlineDictionary', 'Entries in the outline dictionary'], | 123 'TABLE 8.3': ['OutlineDictionary', 'Entries in the outline dictionary'], |
124 'TABLE 8.4': ['OutlineItemDictionary', 'Entries in an outline item dictionary'], | 124 'TABLE 8.4': ['OutlineItemDictionary', 'Entries in an outline item dictionary'], |
125 'TABLE 8.6': ['PageLabelDictionary', 'Entries in a page label dictionary'], | 125 'TABLE 8.6': ['PageLabelDictionary', 'Entries in a page label dictionary'], |
126 'TABLE 8.7': ['ThreadDictionary', 'Entries in a thread dictionary'], | 126 'TABLE 8.7': ['ThreadDictionary', 'Entries in a thread dictionary'], |
127 'TABLE 8.8': ['BeadDictionary', 'Entries in a bead dictionary'], | 127 'TABLE 8.8': ['BeadDictionary', 'Entries in a bead dictionary'], |
128 'TABLE 8.9': ['TransitionDictionary', 'Entries in a transition dictionary'], | 128 'TABLE 8.9': ['TransitionDictionary', 'Entries in a transition dictionary'], |
129 'TABLE 8.10': ['AnnotationDictionary', 'Entries common to all annotation diction
aries'], | 129 'TABLE 8.10': ['AnnotationDictionary', 'Entries common to all annotation diction
aries'], |
130 'TABLE 8.12': ['BorderStyleDictionary', 'Entries in a border style dictionary'], | 130 'TABLE 8.12': ['BorderStyleDictionary', 'Entries in a border style dictionary'], |
131 'TABLE 8.13': ['AppearanceDictionary', 'Entries in an appearance dictionary'], | 131 'TABLE 8.13': ['AppearanceDictionary', 'Entries in an appearance dictionary'], |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 'TABLE 9.42': ['BoxStyleDictionary', 'Entries in a box style dictionary'], | 215 'TABLE 9.42': ['BoxStyleDictionary', 'Entries in a box style dictionary'], |
216 'TABLE 9.43': ['PrinterMarkAnnotationDictionary', 'Additional entries specific t
o a printer\'s mark annotation'], | 216 'TABLE 9.43': ['PrinterMarkAnnotationDictionary', 'Additional entries specific t
o a printer\'s mark annotation'], |
217 'TABLE 9.44': ['PrinterMarkFormDictionary', 'Additional entries specific to a pr
inter\'s mark form dictionary'], | 217 'TABLE 9.44': ['PrinterMarkFormDictionary', 'Additional entries specific to a pr
inter\'s mark form dictionary'], |
218 'TABLE 9.45': ['SeparationDictionary', 'Entries in a separation dictionary'], | 218 'TABLE 9.45': ['SeparationDictionary', 'Entries in a separation dictionary'], |
219 'TABLE 9.46': ['PDF_XOutputIntentDictionary', 'Entries in a PDF/X output intent
dictionary'], | 219 'TABLE 9.46': ['PDF_XOutputIntentDictionary', 'Entries in a PDF/X output intent
dictionary'], |
220 'TABLE 9.47': ['TrapNetworkAnnotationDictionary', 'Additional entries specific t
o a trap network annotation'], | 220 'TABLE 9.47': ['TrapNetworkAnnotationDictionary', 'Additional entries specific t
o a trap network annotation'], |
221 'TABLE 9.48': ['TrapNetworkAppearanceStreamDictionary', 'Additional entries spec
ific to a trap network appearance stream'], | 221 'TABLE 9.48': ['TrapNetworkAppearanceStreamDictionary', 'Additional entries spec
ific to a trap network appearance stream'], |
222 'TABLE 9.49': ['OpiVersionDictionary', 'Entry in an OPI version dictionary'], | 222 'TABLE 9.49': ['OpiVersionDictionary', 'Entry in an OPI version dictionary'], |
223 } | 223 } |
224 | 224 |
| 225 classTree = { |
| 226 } |
| 227 |
225 def buildKnownDictionaries(): | 228 def buildKnownDictionaries(): |
226 global tableToClassName | 229 global tableToClassName |
227 global knownTypes | 230 global knownTypes |
228 | 231 |
229 ret = {} | 232 ret = {} |
230 for e in tableToClassName: | 233 for e in tableToClassName: |
231 ret[tableToClassName[e][0]] = '' | 234 ret[tableToClassName[e][0]] = '' |
232 knownTypes.add(tableToClassName[e][0]) | 235 knownTypes.add(tableToClassName[e][0]) |
233 | 236 |
234 return ret | 237 return ret |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 ret = ret.replace('\n', '\\n') | 293 ret = ret.replace('\n', '\\n') |
291 | 294 |
292 | 295 |
293 return ret | 296 return ret |
294 | 297 |
295 def commitRow(fspecPy): | 298 def commitRow(fspecPy): |
296 global columnValues | 299 global columnValues |
297 global emitedDitionaryName | 300 global emitedDitionaryName |
298 global table | 301 global table |
299 global tableToClassName | 302 global tableToClassName |
| 303 global classTree |
| 304 global tableKey |
| 305 |
300 | 306 |
301 if columnValues == None: | 307 if columnValues == None: |
302 return | 308 return |
303 | 309 |
304 #print columnValues | 310 #print columnValues |
305 | 311 |
306 lastClosed = columnValues[2].find(')') | 312 lastClosed = columnValues[2].find(')') |
307 if lastClosed < 0: | 313 if lastClosed < 0: |
308 print 'ERRRRRRRRRRRRRRROR' | 314 print 'ERRRRRRRRRRRRRRROR' |
309 print columnValues | 315 print columnValues |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 #print emitedDitionaryName | 391 #print emitedDitionaryName |
386 #else: | 392 #else: |
387 #print table | 393 #print table |
388 | 394 |
389 #print tableKey | 395 #print tableKey |
390 #print('\'' + tableKey + '\': [\'' + emitedDitionaryName + '\', \'' + table[
len(tableKey) + 1:] + '\'],') | 396 #print('\'' + tableKey + '\': [\'' + emitedDitionaryName + '\', \'' + table[
len(tableKey) + 1:] + '\'],') |
391 | 397 |
392 emitedDitionaryName = tableToClassName[tableKey][0] | 398 emitedDitionaryName = tableToClassName[tableKey][0] |
393 comment = fix(tableToClassName[tableKey][1]) | 399 comment = fix(tableToClassName[tableKey][1]) |
394 | 400 |
| 401 |
395 if len(tableToClassName[tableKey]) >= 3 and tableToClassName[tableKey][2] !=
'': | 402 if len(tableToClassName[tableKey]) >= 3 and tableToClassName[tableKey][2] !=
'': |
396 fspecPy.write(' pdfspec.addClass(\'' + emitedDitionaryName + '\', \'' + t
ableToClassName[tableKey][2] + '\', \'' + comment + '\')\\\n') | 403 fspecPy.write(' pdfspec.addClass(\'' + emitedDitionaryName + '\', \'' + t
ableToClassName[tableKey][2] + '\', \'' + comment + '\')\\\n') |
| 404 classTree[emitedDitionaryName] = [tableToClassName[tableKey][2], {}] |
397 else: | 405 else: |
398 fspecPy.write(' pdfspec.addClass(\'' + emitedDitionaryName + '\', \'Dicti
onary\', \'' + comment + '\')\\\n') | 406 fspecPy.write(' pdfspec.addClass(\'' + emitedDitionaryName + '\', \'Dicti
onary\', \'' + comment + '\')\\\n') |
| 407 classTree[emitedDitionaryName] = ['Dictionary', {}] |
399 | 408 |
400 if len(tableToClassName[tableKey]) >= 4 and columnValues[0] in tableToClassNam
e[tableKey][3]: | 409 if len(tableToClassName[tableKey]) >= 4 and columnValues[0] in tableToClassNam
e[tableKey][3]: |
401 required = True | 410 required = True |
402 | 411 |
403 if required: | 412 if required: |
404 fspecPy.write(' .required(\'NULL\')\\\n') | 413 fspecPy.write(' .required(\'NULL\')\\\n') |
405 else: | 414 else: |
406 fspecPy.write(' .optional()\\\n') | 415 fspecPy.write(' .optional()\\\n') |
407 | 416 |
408 fspecPy.write(' .field(\'' + columnValues[0] + '\')\\\n') | 417 fspecPy.write(' .field(\'' + columnValues[0] + '\')\\\n') |
409 fspecPy.write(' .name(\'' + columnValues[0] + '\')\\\n') | 418 fspecPy.write(' .name(\'' + columnValues[0] + '\')\\\n') |
410 fspecPy.write(' .type(\'' + columnValues[1] + '\')\\\n') | 419 fspecPy.write(' .type(\'' + columnValues[1] + '\')\\\n') |
411 fspecPy.write(' .comment(\'' + columnValues[2] + '\')\\\n') | 420 fspecPy.write(' .comment(\'' + columnValues[2] + '\')\\\n') |
| 421 |
| 422 classTree[emitedDitionaryName][1][columnValues[0]] = ' .field(\'' +
columnValues[0] + '\')\\\n' + \ |
| 423 ' .name(\'' + columnValues[0] + '\')\\\n' + \ |
| 424 ' .type(\'' + columnValues[1] + '\')\\\n' + \ |
| 425 ' .comment(\'\')\\\n' |
| 426 |
412 | 427 |
413 if len(tableToClassName[tableKey]) >= 4 and columnValues[0] in tableToClassNam
e[tableKey][3]: | 428 if len(tableToClassName[tableKey]) >= 4 and columnValues[0] in tableToClassNam
e[tableKey][3]: |
414 fspecPy.write(' .must(' + tableToClassName[tableKey][3][columnValue
s[0]] + ')\\\n') | 429 fspecPy.write(' .must(' + tableToClassName[tableKey][3][columnValue
s[0]] + ')\\\n') |
415 | 430 |
416 fspecPy.write(' .done().done()\\\n') | 431 fspecPy.write(' .done().done()\\\n') |
417 | 432 |
418 | 433 |
419 columnValues = None | 434 columnValues = None |
420 | 435 |
421 def newRow(first, second, third): | 436 def newRow(first, second, third): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 if words[i].startswith('(Required'): | 469 if words[i].startswith('(Required'): |
455 columnWidth[1] = line.find('(Required') - columnWidth[0] | 470 columnWidth[1] = line.find('(Required') - columnWidth[0] |
456 return True | 471 return True |
457 | 472 |
458 return False | 473 return False |
459 | 474 |
460 | 475 |
461 def stopTable(fspecPy): | 476 def stopTable(fspecPy): |
462 global tableHeaderFound | 477 global tableHeaderFound |
463 global emitedDitionaryName | 478 global emitedDitionaryName |
464 | 479 global tableKey |
| 480 global classTree |
| 481 |
465 if not inTable(): | 482 if not inTable(): |
466 return | 483 return |
467 | 484 |
468 commitRow(fspecPy) | 485 commitRow(fspecPy) |
| 486 |
| 487 #print tableKey |
| 488 |
| 489 # TODO(edisonn): iterate on all requited key in the def, and if not on the def
inition, get definition from parent and export them |
| 490 if len(tableToClassName[tableKey]) >= 4: |
| 491 for field in tableToClassName[tableKey][3]: |
| 492 #print field |
| 493 if not field in classTree[emitedDitionaryName][1]: |
| 494 fieldDef = '' |
| 495 searchKey = classTree[emitedDitionaryName][0] |
| 496 while searchKey != 'Dictionary' and (not field in classTree[searchKey][1
]): |
| 497 searchKey = classTree[searchKey][0] |
| 498 |
| 499 if searchKey != 'Dictionary' and (field in classTree[searchKey][1]): |
| 500 #print tableToClassName[tableKey][3][field] |
| 501 #print classTree[searchKey][1][field] |
| 502 # TODO(edisonns): hack - for required fields, they need to be downgrad
ed to only a type |
| 503 classTree[searchKey][1][field] = classTree[searchKey][1][field].replac
e(' or array', '') |
| 504 classTree[searchKey][1][field] = classTree[searchKey][1][field].replac
e(' or distionary', '') |
| 505 fspecPy.write(' .required(\'NULL\')\\\n') |
| 506 fspecPy.write(classTree[searchKey][1][field]) |
| 507 fspecPy.write(' .must(' + tableToClassName[tableKey][3][field
] + ')\\\n') |
| 508 fspecPy.write(' .done().done()\\\n') |
| 509 else: |
| 510 print 'ERROR' + tableKey + '.' + field; |
| 511 |
469 tableHeaderFound = False | 512 tableHeaderFound = False |
470 emitedDitionaryName = '' | 513 emitedDitionaryName = '' |
471 fspecPy.write(' .done()\n') | 514 fspecPy.write(' .done()\n') |
472 fspecPy.write('\n') | 515 fspecPy.write('\n') |
473 | 516 |
474 | 517 |
475 def killTable(): | 518 def killTable(): |
476 return | 519 return |
477 | 520 |
478 def processLineCore(fspecPy, line): | 521 def processLineCore(fspecPy, line): |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 | 605 |
563 if first == '' and second != '' and second[0] != ' ': | 606 if first == '' and second != '' and second[0] != ' ': |
564 if acceptType(second): | 607 if acceptType(second): |
565 appendRow(second, third) | 608 appendRow(second, third) |
566 return True | 609 return True |
567 else: | 610 else: |
568 stopTable(fspecPy) | 611 stopTable(fspecPy) |
569 return False | 612 return False |
570 | 613 |
571 if first != '' and second != '' and third[0] != '(': | 614 if first != '' and second != '' and third[0] != '(': |
572 stopTable() | 615 stopTable(fspecPy) |
573 return False | 616 return False |
574 | 617 |
575 if first == '' and second != '' and second[0] == ' ': | 618 if first == '' and second != '' and second[0] == ' ': |
576 stopTable(fspecPy) | 619 stopTable(fspecPy) |
577 return False | 620 return False |
578 | 621 |
579 if first != '' and second != '' and third[0] == '(': | 622 if first != '' and second != '' and third[0] == '(': |
580 commitRow(fspecPy) | 623 commitRow(fspecPy) |
581 newRow(first, second, third) | 624 newRow(first, second, third) |
582 return True | 625 return True |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 #TODO(edisonn): build this map | 673 #TODO(edisonn): build this map |
631 | 674 |
632 fspecPy.write(' knowTypes[\'' + tableToClassName[e][0] + '\'] = [\'SkPdf' +
tableToClassName[e][0] + '*\', \'(SkPdf' + tableToClassName[e][0] + '*)ret\', d
atatypes.CppNull(), \'ret->isDictionary() && ((SkPdf' + tableToClassName[e][0] +
'*)ret)->valid()\', \'A_DICTIONARY\']\n') | 675 fspecPy.write(' knowTypes[\'' + tableToClassName[e][0] + '\'] = [\'SkPdf' +
tableToClassName[e][0] + '*\', \'(SkPdf' + tableToClassName[e][0] + '*)ret\', d
atatypes.CppNull(), \'ret->isDictionary() && ((SkPdf' + tableToClassName[e][0] +
'*)ret)->valid()\', \'A_DICTIONARY\']\n') |
633 fspecPy.write('\n') | 676 fspecPy.write('\n') |
634 | 677 |
635 #print lines | 678 #print lines |
636 #fnewspec.close() | 679 #fnewspec.close() |
637 | 680 |
638 if '__main__' == __name__: | 681 if '__main__' == __name__: |
639 sys.exit(generateDef()) | 682 sys.exit(generateDef()) |
OLD | NEW |