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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 'TABLE 3.23': ['NameTreeNodeDictionary', 'Entries in a name tree node dictionary
'], | 73 'TABLE 3.23': ['NameTreeNodeDictionary', 'Entries in a name tree node dictionary
'], |
74 'TABLE 3.25': ['NumberTreeNodeDictionary', 'Entries in a number tree node dictio
nary'], | 74 'TABLE 3.25': ['NumberTreeNodeDictionary', 'Entries in a number tree node dictio
nary'], |
75 'TABLE 3.26': ['FunctionCommonDictionary', 'Entries common to all function dicti
onaries'], | 75 'TABLE 3.26': ['FunctionCommonDictionary', 'Entries common to all function dicti
onaries'], |
76 'TABLE 3.27': ['Type0FunctionDictionary', 'Additional entries specific to a type
0 function dictionary'], | 76 'TABLE 3.27': ['Type0FunctionDictionary', 'Additional entries specific to a type
0 function dictionary'], |
77 'TABLE 3.28': ['Type2FunctionDictionary', 'Additional entries specific to a type
2 function dictionary'], | 77 'TABLE 3.28': ['Type2FunctionDictionary', 'Additional entries specific to a type
2 function dictionary'], |
78 'TABLE 3.29': ['Type3FunctionDictionary', 'Additional entries specific to a type
3 function dictionary'], | 78 'TABLE 3.29': ['Type3FunctionDictionary', 'Additional entries specific to a type
3 function dictionary'], |
79 'TABLE 3.32': ['FileSpecificationDictionary', 'Entries in a file specification d
ictionary'], | 79 'TABLE 3.32': ['FileSpecificationDictionary', 'Entries in a file specification d
ictionary'], |
80 'TABLE 3.33': ['EmbeddedFileStreamDictionary', 'Additional entries in an embedde
d file stream dictionary'], | 80 'TABLE 3.33': ['EmbeddedFileStreamDictionary', 'Additional entries in an embedde
d file stream dictionary'], |
81 'TABLE 3.34': ['EmbeddedFileParameterDictionary', 'Entries in an embedded file p
arameter dictionary'], | 81 'TABLE 3.34': ['EmbeddedFileParameterDictionary', 'Entries in an embedded file p
arameter dictionary'], |
82 'TABLE 3.35': ['MacOsFileInformationDictionary', 'Entries in a Mac OS file infor
mation dictionary'], | 82 'TABLE 3.35': ['MacOsFileInformationDictionary', 'Entries in a Mac OS file infor
mation dictionary'], |
| 83 'TABLE 4.8': ['GraphicsStateDictionary', 'Entries in a graphics state parameter
dictionary'], |
83 'TABLE 4.13': ['CalgrayColorSpaceDictionary', 'Entries in a CalGray color space
dictionary'], | 84 'TABLE 4.13': ['CalgrayColorSpaceDictionary', 'Entries in a CalGray color space
dictionary'], |
84 'TABLE 4.14': ['CalrgbColorSpaceDictionary', 'Entries in a CalRGB color space di
ctionary'], | 85 'TABLE 4.14': ['CalrgbColorSpaceDictionary', 'Entries in a CalRGB color space di
ctionary'], |
85 'TABLE 4.15': ['LabColorSpaceDictionary', 'Entries in a Lab color space dictiona
ry'], | 86 'TABLE 4.15': ['LabColorSpaceDictionary', 'Entries in a Lab color space dictiona
ry'], |
86 'TABLE 4.16': ['IccProfileStreamDictionary', 'Additional entries specific to an
ICC profile stream dictionary'], | 87 'TABLE 4.16': ['IccProfileStreamDictionary', 'Additional entries specific to an
ICC profile stream dictionary'], |
87 'TABLE 4.20': ['DeviceNColorSpaceDictionary', 'Entry in a DeviceN color space at
tributes dictionary'], | 88 'TABLE 4.20': ['DeviceNColorSpaceDictionary', 'Entry in a DeviceN color space at
tributes dictionary'], |
88 'TABLE 4.22': ['Type1PatternDictionary', 'Additional entries specific to a type
1 pattern dictionary'], | 89 'TABLE 4.22': ['Type1PatternDictionary', 'Additional entries specific to a type
1 pattern dictionary'], |
89 'TABLE 4.23': ['Type2PatternDictionary', 'Entries in a type 2 pattern dictionary
'], | 90 'TABLE 4.23': ['Type2PatternDictionary', 'Entries in a type 2 pattern dictionary
'], |
90 'TABLE 4.25': ['ShadingDictionary', 'Entries common to all shading dictionaries'
], | 91 'TABLE 4.25': ['ShadingDictionary', 'Entries common to all shading dictionaries'
], |
91 'TABLE 4.26': ['Type1ShadingDictionary', 'Additional entries specific to a type
1 shading dictionary', 'ShadingDictionary'], | 92 'TABLE 4.26': ['Type1ShadingDictionary', 'Additional entries specific to a type
1 shading dictionary', 'ShadingDictionary'], |
92 'TABLE 4.27': ['Type2ShadingDictionary', 'Additional entries specific to a type
2 shading dictionary', 'ShadingDictionary'], | 93 'TABLE 4.27': ['Type2ShadingDictionary', 'Additional entries specific to a type
2 shading dictionary', 'ShadingDictionary'], |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 global columnValues | 411 global columnValues |
411 if second.rstrip() != '': | 412 if second.rstrip() != '': |
412 columnValues[1] = columnValues[1] + ' ' + second.rstrip() | 413 columnValues[1] = columnValues[1] + ' ' + second.rstrip() |
413 if third.rstrip() != '': | 414 if third.rstrip() != '': |
414 columnValues[2] = columnValues[2] + '\n' + third.rstrip() | 415 columnValues[2] = columnValues[2] + '\n' + third.rstrip() |
415 | 416 |
416 def rebaseTable(line): | 417 def rebaseTable(line): |
417 global knownTypes | 418 global knownTypes |
418 global columnWidth | 419 global columnWidth |
419 | 420 |
420 words = line.split() | 421 line2 = line.replace(',', ' , ') |
| 422 |
| 423 words = line2.split() |
421 | 424 |
422 if len(words) < 3: | 425 if len(words) < 3: |
423 return False | 426 return False |
424 | 427 |
425 i = 1 | 428 i = 1 |
426 while i < len(words) - 1 and words[i] in knownTypes: | 429 while i < len(words) - 1 and words[i] in knownTypes: |
427 i = i + 1 | 430 i = i + 1 |
428 | 431 |
429 if words[i].startswith('(Optional') or words[i].startswith('(Required'): | 432 if words[i].startswith('(Optional') or words[i].startswith('(Required'): |
430 commitRow() | 433 commitRow() |
(...skipping 19 matching lines...) Expand all Loading... |
450 commitRow() | 453 commitRow() |
451 tableHeaderFound = False | 454 tableHeaderFound = False |
452 emitedDitionaryName = '' | 455 emitedDitionaryName = '' |
453 print(' .done()') | 456 print(' .done()') |
454 print | 457 print |
455 | 458 |
456 | 459 |
457 def killTable(): | 460 def killTable(): |
458 return | 461 return |
459 | 462 |
460 def processLine(line): | 463 def processLineCore(line): |
461 global lines | 464 global lines |
462 global tableLine | 465 global tableLine |
463 global tableRow | 466 global tableRow |
464 global columnWidth | 467 global columnWidth |
465 global columnValues | 468 global columnValues |
466 global mustFollowTableHeader | 469 global mustFollowTableHeader |
467 | 470 |
| 471 global fnewspec |
| 472 |
468 lines = lines + 1 | 473 lines = lines + 1 |
469 | 474 |
470 line = unicode(line, 'utf8') | 475 line = unicode(line, 'utf8') |
471 | 476 |
472 striped = line.rstrip() | 477 striped = line.rstrip() |
473 | 478 |
474 words = line.split() | 479 words = line.split() |
475 if len(words) == 0: | 480 if len(words) == 0: |
476 stopTable() | 481 stopTable() |
477 return | 482 return False |
478 | 483 |
479 isTableHeader = re.search('^[\s]*(TABLE [0-9].[0-9][0-9]?)', striped) | 484 isTableHeader = re.search('^[\s]*(TABLE [0-9].[0-9][0-9]?)', striped) |
480 if isTableHeader: | 485 if isTableHeader: |
481 stopTable() | 486 stopTable() |
482 tableDescriptionFound(striped) | 487 tableDescriptionFound(striped) |
483 mustFollowTableHeader = True | 488 mustFollowTableHeader = True |
484 return | 489 return False |
485 | 490 |
486 if mustFollowTableHeader: | 491 if mustFollowTableHeader: |
487 mustFollowTableHeader = False | 492 mustFollowTableHeader = False |
488 if len(words) != 3: | 493 if len(words) != 3: |
489 killTable() | 494 killTable() |
| 495 return False |
490 | 496 |
491 # TODO(edisonn): support for generic table! | 497 # TODO(edisonn): support for generic table! |
492 if words[0] != 'KEY' or words[1] != 'TYPE' or words[2] != 'VALUE': | 498 if words[0] != 'KEY' or words[1] != 'TYPE' or words[2] != 'VALUE': |
493 killTable() | 499 killTable() |
494 return | 500 return False |
495 | 501 |
496 tableHasHeader() | 502 tableHasHeader() |
497 columnWidth = [0, 0, 0] | 503 columnWidth = [0, 0, 0] |
498 columnWidth[0] = striped.index('TYPE') | 504 columnWidth[0] = striped.index('TYPE') |
499 columnWidth[1] = striped.index('VALUE') - striped.index('TYPE') | 505 columnWidth[1] = striped.index('VALUE') - striped.index('TYPE') |
500 columnWidth[2] = 0 | 506 columnWidth[2] = 0 |
501 return | 507 return True |
502 | 508 |
503 if inTable(): | 509 if inTable(): |
504 tableLine = tableLine + 1 | 510 tableLine = tableLine + 1 |
505 first = striped[0 : columnWidth[0]] | 511 first = striped[0 : columnWidth[0]] |
506 second = striped[columnWidth[0] : columnWidth[0] + columnWidth[1]] | 512 second = striped[columnWidth[0] : columnWidth[0] + columnWidth[1]] |
507 third = striped[columnWidth[0] + columnWidth[1] :] | 513 third = striped[columnWidth[0] + columnWidth[1] :] |
508 | 514 |
509 | |
510 | |
511 | |
512 if tableLine == 1: | 515 if tableLine == 1: |
513 if third[0] != '(': | 516 if third[0] != '(': |
514 killTable() | 517 killTable() |
515 return | 518 return False |
516 | 519 |
517 newRow(first, second, third) | 520 newRow(first, second, third) |
518 return | 521 return True |
519 | 522 |
520 if rebaseTable(striped): | 523 if rebaseTable(striped): |
521 first = striped[0 : columnWidth[0]] | 524 first = striped[0 : columnWidth[0]] |
522 second = striped[columnWidth[0] : columnWidth[0] + columnWidth[1]] | 525 second = striped[columnWidth[0] : columnWidth[0] + columnWidth[1]] |
523 third = striped[columnWidth[0] + columnWidth[1] :] | 526 third = striped[columnWidth[0] + columnWidth[1] :] |
524 | 527 |
525 first = first.rstrip() | 528 first = first.rstrip() |
526 second = second.rstrip() | 529 second = second.rstrip() |
527 third = third.rstrip() | 530 third = third.rstrip() |
528 | 531 |
529 if first == '' and second == '' and third != '': | 532 if first == '' and second == '' and third != '': |
530 appendRow(second, third) | 533 appendRow(second, third) |
531 return | 534 return True |
532 | 535 |
533 if len(first.split()) > 1: | 536 if len(first.split()) > 1: |
534 stopTable() | 537 stopTable() |
535 return | 538 return False |
536 | 539 |
537 if first != '' and first[0] == ' ': | 540 if first != '' and first[0] == ' ': |
538 stopTable() | 541 stopTable() |
539 return | 542 return False |
540 | 543 |
541 if first != '' and second != '' and third == '': | 544 if first != '' and second != '' and third == '': |
542 stopTable() | 545 stopTable() |
543 return | 546 return False |
544 | 547 |
545 if first == '' and second != '' and second[0] != ' ': | 548 if first == '' and second != '' and second[0] != ' ': |
546 if acceptType(second): | 549 if acceptType(second): |
547 appendRow(second, third) | 550 appendRow(second, third) |
| 551 return True |
548 else: | 552 else: |
549 stopTable() | 553 stopTable() |
550 return | 554 return False |
551 | 555 |
552 if first != '' and second != '' and third[0] != '(': | 556 if first != '' and second != '' and third[0] != '(': |
553 stopTable() | 557 stopTable() |
554 return | 558 return False |
555 | 559 |
556 if first == '' and second != '' and second[0] == ' ': | 560 if first == '' and second != '' and second[0] == ' ': |
557 stopTable() | 561 stopTable() |
558 return | 562 return False |
559 | 563 |
560 if first != '' and second != '' and third[0] == '(': | 564 if first != '' and second != '' and third[0] == '(': |
561 commitRow() | 565 commitRow() |
562 newRow(first, second, third) | 566 newRow(first, second, third) |
563 return | 567 return True |
| 568 |
| 569 return False |
| 570 return False |
| 571 |
| 572 def processLine(line): |
| 573 global fnewspec |
| 574 |
| 575 inSpec = processLineCore(line) |
| 576 |
| 577 #just return, use the next lines if you wish to rewrite spec |
| 578 return |
| 579 |
| 580 if inSpec: |
| 581 #resize colum with types |
| 582 line = line[:columnWidth[0] + columnWidth[1]] + (' ' * (60 - columnWidth[1])
) + line[columnWidth[0] + columnWidth[1]:] |
| 583 line = line[:columnWidth[0]] + (' ' * (40 - columnWidth[0])) + line[columnWi
dth[0]:] |
| 584 |
| 585 fnewspec.write(line) |
564 | 586 |
565 | 587 |
566 def generateDef(): | 588 def generateDef(): |
567 global lines | 589 global lines |
| 590 global fnewspec |
| 591 |
| 592 #fnewspec = open('PdfReference-okular-2.txt', 'w') |
568 | 593 |
569 print 'import datatypes' | 594 print 'import datatypes' |
570 print | 595 print |
571 | 596 |
572 print 'def buildPdfSpec(pdfspec):' | 597 print 'def buildPdfSpec(pdfspec):' |
573 | 598 |
574 for line in sys.stdin: | 599 for line in sys.stdin: |
575 processLine(line) | 600 processLine(line) |
576 | 601 |
577 # close last table if it was not closed already | 602 # close last table if it was not closed already |
578 stopTable() | 603 stopTable() |
579 | 604 |
580 print | 605 print |
581 | 606 |
582 #print lines | 607 #print lines |
| 608 #fnewspec.close() |
583 | 609 |
584 if '__main__' == __name__: | 610 if '__main__' == __name__: |
585 sys.exit(generateDef()) | 611 sys.exit(generateDef()) |
OLD | NEW |