OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* cffparse.c */ | 3 /* cffparse.c */ |
4 /* */ | 4 /* */ |
5 /* CFF token stream parser (body) */ | 5 /* CFF token stream parser (body) */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2004, 2007-2011 by */ | 7 /* Copyright 1996-2004, 2007-2011 by */ |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
9 /* */ | 9 /* */ |
10 /* This file is part of the FreeType project, and may only be used, */ | 10 /* This file is part of the FreeType project, and may only be used, */ |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 FT_Error error = CFF_Err_Stack_Underflow; | 453 FT_Error error = CFF_Err_Stack_Underflow; |
454 | 454 |
455 | 455 |
456 if ( parser->top >= parser->stack + 6 ) | 456 if ( parser->top >= parser->stack + 6 ) |
457 { | 457 { |
458 FT_Long scaling; | 458 FT_Long scaling; |
459 | 459 |
460 | 460 |
461 error = CFF_Err_Ok; | 461 error = CFF_Err_Ok; |
462 | 462 |
| 463 dict->has_font_matrix = TRUE; |
| 464 |
463 /* We expect a well-formed font matrix, this is, the matrix elements */ | 465 /* We expect a well-formed font matrix, this is, the matrix elements */ |
464 /* `xx' and `yy' are of approximately the same magnitude. To avoid */ | 466 /* `xx' and `yy' are of approximately the same magnitude. To avoid */ |
465 /* loss of precision, we use the magnitude of element `xx' to scale */ | 467 /* loss of precision, we use the magnitude of element `xx' to scale */ |
466 /* all other elements. The scaling factor is then contained in the */ | 468 /* all other elements. The scaling factor is then contained in the */ |
467 /* `units_per_em' value. */ | 469 /* `units_per_em' value. */ |
468 | 470 |
469 matrix->xx = cff_parse_fixed_dynamic( data++, &scaling ); | 471 matrix->xx = cff_parse_fixed_dynamic( data++, &scaling ); |
470 | 472 |
471 scaling = -scaling; | 473 scaling = -scaling; |
472 | 474 |
(...skipping 18 matching lines...) Expand all Loading... |
491 } | 493 } |
492 | 494 |
493 matrix->yx = cff_parse_fixed_scaled( data++, scaling ); | 495 matrix->yx = cff_parse_fixed_scaled( data++, scaling ); |
494 matrix->xy = cff_parse_fixed_scaled( data++, scaling ); | 496 matrix->xy = cff_parse_fixed_scaled( data++, scaling ); |
495 matrix->yy = cff_parse_fixed_scaled( data++, scaling ); | 497 matrix->yy = cff_parse_fixed_scaled( data++, scaling ); |
496 offset->x = cff_parse_fixed_scaled( data++, scaling ); | 498 offset->x = cff_parse_fixed_scaled( data++, scaling ); |
497 offset->y = cff_parse_fixed_scaled( data, scaling ); | 499 offset->y = cff_parse_fixed_scaled( data, scaling ); |
498 | 500 |
499 *upm = power_tens[scaling]; | 501 *upm = power_tens[scaling]; |
500 | 502 |
501 FT_TRACE4(( " font matrix: [%f %f %f %f]\n", | 503 FT_TRACE4(( " [%f %f %f %f %f %f]\n", |
502 (double)matrix->xx / *upm / 65536, | 504 (double)matrix->xx / *upm / 65536, |
503 (double)matrix->xy / *upm / 65536, | 505 (double)matrix->xy / *upm / 65536, |
504 (double)matrix->yx / *upm / 65536, | 506 (double)matrix->yx / *upm / 65536, |
505 (double)matrix->yy / *upm / 65536 )); | 507 (double)matrix->yy / *upm / 65536, |
| 508 (double)offset->x / *upm / 65536, |
| 509 (double)offset->y / *upm / 65536 )); |
506 } | 510 } |
507 | 511 |
508 Exit: | 512 Exit: |
509 return error; | 513 return error; |
510 } | 514 } |
511 | 515 |
512 | 516 |
513 static FT_Error | 517 static FT_Error |
514 cff_parse_font_bbox( CFF_Parser parser ) | 518 cff_parse_font_bbox( CFF_Parser parser ) |
515 { | 519 { |
516 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 520 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
517 FT_BBox* bbox = &dict->font_bbox; | 521 FT_BBox* bbox = &dict->font_bbox; |
518 FT_Byte** data = parser->stack; | 522 FT_Byte** data = parser->stack; |
519 FT_Error error; | 523 FT_Error error; |
520 | 524 |
521 | 525 |
522 error = CFF_Err_Stack_Underflow; | 526 error = CFF_Err_Stack_Underflow; |
523 | 527 |
524 if ( parser->top >= parser->stack + 4 ) | 528 if ( parser->top >= parser->stack + 4 ) |
525 { | 529 { |
526 bbox->xMin = FT_RoundFix( cff_parse_fixed( data++ ) ); | 530 bbox->xMin = FT_RoundFix( cff_parse_fixed( data++ ) ); |
527 bbox->yMin = FT_RoundFix( cff_parse_fixed( data++ ) ); | 531 bbox->yMin = FT_RoundFix( cff_parse_fixed( data++ ) ); |
528 bbox->xMax = FT_RoundFix( cff_parse_fixed( data++ ) ); | 532 bbox->xMax = FT_RoundFix( cff_parse_fixed( data++ ) ); |
529 bbox->yMax = FT_RoundFix( cff_parse_fixed( data ) ); | 533 bbox->yMax = FT_RoundFix( cff_parse_fixed( data ) ); |
530 error = CFF_Err_Ok; | 534 error = CFF_Err_Ok; |
531 | 535 |
532 FT_TRACE4(( " bbox: [%d %d %d %d]\n", | 536 FT_TRACE4(( " [%d %d %d %d]\n", |
533 bbox->xMin / 65536, | 537 bbox->xMin / 65536, |
534 bbox->yMin / 65536, | 538 bbox->yMin / 65536, |
535 bbox->xMax / 65536, | 539 bbox->xMax / 65536, |
536 bbox->yMax / 65536 )); | 540 bbox->yMax / 65536 )); |
537 } | 541 } |
538 | 542 |
539 return error; | 543 return error; |
540 } | 544 } |
541 | 545 |
542 | 546 |
543 static FT_Error | 547 static FT_Error |
544 cff_parse_private_dict( CFF_Parser parser ) | 548 cff_parse_private_dict( CFF_Parser parser ) |
545 { | 549 { |
546 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 550 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
547 FT_Byte** data = parser->stack; | 551 FT_Byte** data = parser->stack; |
548 FT_Error error; | 552 FT_Error error; |
549 | 553 |
550 | 554 |
551 error = CFF_Err_Stack_Underflow; | 555 error = CFF_Err_Stack_Underflow; |
552 | 556 |
553 if ( parser->top >= parser->stack + 2 ) | 557 if ( parser->top >= parser->stack + 2 ) |
554 { | 558 { |
555 dict->private_size = cff_parse_num( data++ ); | 559 dict->private_size = cff_parse_num( data++ ); |
556 dict->private_offset = cff_parse_num( data ); | 560 dict->private_offset = cff_parse_num( data ); |
| 561 FT_TRACE4(( " %lu %lu\n", |
| 562 dict->private_size, dict->private_offset )); |
| 563 |
557 error = CFF_Err_Ok; | 564 error = CFF_Err_Ok; |
558 } | 565 } |
559 | 566 |
560 return error; | 567 return error; |
561 } | 568 } |
562 | 569 |
563 | 570 |
564 static FT_Error | 571 static FT_Error |
565 cff_parse_cid_ros( CFF_Parser parser ) | 572 cff_parse_cid_ros( CFF_Parser parser ) |
566 { | 573 { |
567 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; | 574 CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; |
568 FT_Byte** data = parser->stack; | 575 FT_Byte** data = parser->stack; |
569 FT_Error error; | 576 FT_Error error; |
570 | 577 |
571 | 578 |
572 error = CFF_Err_Stack_Underflow; | 579 error = CFF_Err_Stack_Underflow; |
573 | 580 |
574 if ( parser->top >= parser->stack + 3 ) | 581 if ( parser->top >= parser->stack + 3 ) |
575 { | 582 { |
576 dict->cid_registry = (FT_UInt)cff_parse_num( data++ ); | 583 dict->cid_registry = (FT_UInt)cff_parse_num( data++ ); |
577 dict->cid_ordering = (FT_UInt)cff_parse_num( data++ ); | 584 dict->cid_ordering = (FT_UInt)cff_parse_num( data++ ); |
578 if ( **data == 30 ) | 585 if ( **data == 30 ) |
579 FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" )); | 586 FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" )); |
580 dict->cid_supplement = cff_parse_num( data ); | 587 dict->cid_supplement = cff_parse_num( data ); |
581 if ( dict->cid_supplement < 0 ) | 588 if ( dict->cid_supplement < 0 ) |
582 FT_TRACE1(( "cff_parse_cid_ros: negative supplement %d is found\n", | 589 FT_TRACE1(( "cff_parse_cid_ros: negative supplement %d is found\n", |
583 dict->cid_supplement )); | 590 dict->cid_supplement )); |
584 error = CFF_Err_Ok; | 591 error = CFF_Err_Ok; |
585 | 592 |
586 FT_TRACE4(( " ROS: registry sid %d, ordering sid %d, supplement %d\n", | 593 FT_TRACE4(( " %d %d %d\n", |
587 dict->cid_registry, | 594 dict->cid_registry, |
588 dict->cid_ordering, | 595 dict->cid_ordering, |
589 dict->cid_supplement )); | 596 dict->cid_supplement )); |
590 } | 597 } |
591 | 598 |
592 return error; | 599 return error; |
593 } | 600 } |
594 | 601 |
595 | 602 |
596 #define CFF_FIELD_NUM( code, name ) \ | 603 #define CFF_FIELD_NUM( code, name, id ) \ |
597 CFF_FIELD( code, name, cff_kind_num ) | 604 CFF_FIELD( code, name, id, cff_kind_num ) |
598 #define CFF_FIELD_FIXED( code, name ) \ | 605 #define CFF_FIELD_FIXED( code, name, id ) \ |
599 CFF_FIELD( code, name, cff_kind_fixed ) | 606 CFF_FIELD( code, name, id, cff_kind_fixed ) |
600 #define CFF_FIELD_FIXED_1000( code, name ) \ | 607 #define CFF_FIELD_FIXED_1000( code, name, id ) \ |
601 CFF_FIELD( code, name, cff_kind_fixed_thousand ) | 608 CFF_FIELD( code, name, id, cff_kind_fixed_thousand ) |
602 #define CFF_FIELD_STRING( code, name ) \ | 609 #define CFF_FIELD_STRING( code, name, id ) \ |
603 CFF_FIELD( code, name, cff_kind_string ) | 610 CFF_FIELD( code, name, id, cff_kind_string ) |
604 #define CFF_FIELD_BOOL( code, name ) \ | 611 #define CFF_FIELD_BOOL( code, name, id ) \ |
605 CFF_FIELD( code, name, cff_kind_bool ) | 612 CFF_FIELD( code, name, id, cff_kind_bool ) |
606 #define CFF_FIELD_DELTA( code, name, max ) \ | |
607 CFF_FIELD( code, name, cff_kind_delta ) | |
608 | 613 |
609 #define CFFCODE_TOPDICT 0x1000 | 614 #define CFFCODE_TOPDICT 0x1000 |
610 #define CFFCODE_PRIVATE 0x2000 | 615 #define CFFCODE_PRIVATE 0x2000 |
611 | 616 |
| 617 |
612 #ifndef FT_CONFIG_OPTION_PIC | 618 #ifndef FT_CONFIG_OPTION_PIC |
613 | 619 |
614 #define CFF_FIELD_CALLBACK( code, name ) \ | 620 |
615 { \ | 621 #undef CFF_FIELD |
616 cff_kind_callback, \ | 622 #undef CFF_FIELD_DELTA |
617 code | CFFCODE, \ | 623 |
618 0, 0, \ | 624 |
619 cff_parse_ ## name, \ | 625 #ifndef FT_DEBUG_LEVEL_TRACE |
620 0, 0 \ | 626 |
| 627 |
| 628 #define CFF_FIELD_CALLBACK( code, name, id ) \ |
| 629 { \ |
| 630 cff_kind_callback, \ |
| 631 code | CFFCODE, \ |
| 632 0, 0, \ |
| 633 cff_parse_ ## name, \ |
| 634 0, 0 \ |
621 }, | 635 }, |
622 | 636 |
623 #undef CFF_FIELD | 637 #define CFF_FIELD( code, name, id, kind ) \ |
624 #define CFF_FIELD( code, name, kind ) \ | 638 { \ |
625 { \ | 639 kind, \ |
626 kind, \ | 640 code | CFFCODE, \ |
627 code | CFFCODE, \ | 641 FT_FIELD_OFFSET( name ), \ |
628 FT_FIELD_OFFSET( name ), \ | 642 FT_FIELD_SIZE( name ), \ |
629 FT_FIELD_SIZE( name ), \ | 643 0, 0, 0 \ |
630 0, 0, 0 \ | |
631 }, | 644 }, |
632 | 645 |
633 #undef CFF_FIELD_DELTA | 646 #define CFF_FIELD_DELTA( code, name, max, id ) \ |
634 #define CFF_FIELD_DELTA( code, name, max ) \ | 647 { \ |
635 { \ | 648 cff_kind_delta, \ |
636 cff_kind_delta, \ | 649 code | CFFCODE, \ |
637 code | CFFCODE, \ | 650 FT_FIELD_OFFSET( name ), \ |
638 FT_FIELD_OFFSET( name ), \ | 651 FT_FIELD_SIZE_DELTA( name ), \ |
639 FT_FIELD_SIZE_DELTA( name ), \ | 652 0, \ |
640 0, \ | 653 max, \ |
641 max, \ | 654 FT_FIELD_OFFSET( num_ ## name ) \ |
642 FT_FIELD_OFFSET( num_ ## name ) \ | 655 }, |
643 }, | |
644 | 656 |
645 static const CFF_Field_Handler cff_field_handlers[] = | 657 static const CFF_Field_Handler cff_field_handlers[] = |
646 { | 658 { |
647 | 659 |
648 #include "cfftoken.h" | 660 #include "cfftoken.h" |
649 | 661 |
650 { 0, 0, 0, 0, 0, 0, 0 } | 662 { 0, 0, 0, 0, 0, 0, 0 } |
651 }; | 663 }; |
652 | 664 |
653 | 665 |
| 666 #else /* FT_DEBUG_LEVEL_TRACE */ |
| 667 |
| 668 |
| 669 |
| 670 #define CFF_FIELD_CALLBACK( code, name, id ) \ |
| 671 { \ |
| 672 cff_kind_callback, \ |
| 673 code | CFFCODE, \ |
| 674 0, 0, \ |
| 675 cff_parse_ ## name, \ |
| 676 0, 0, \ |
| 677 id \ |
| 678 }, |
| 679 |
| 680 #define CFF_FIELD( code, name, id, kind ) \ |
| 681 { \ |
| 682 kind, \ |
| 683 code | CFFCODE, \ |
| 684 FT_FIELD_OFFSET( name ), \ |
| 685 FT_FIELD_SIZE( name ), \ |
| 686 0, 0, 0, \ |
| 687 id \ |
| 688 }, |
| 689 |
| 690 #define CFF_FIELD_DELTA( code, name, max, id ) \ |
| 691 { \ |
| 692 cff_kind_delta, \ |
| 693 code | CFFCODE, \ |
| 694 FT_FIELD_OFFSET( name ), \ |
| 695 FT_FIELD_SIZE_DELTA( name ), \ |
| 696 0, \ |
| 697 max, \ |
| 698 FT_FIELD_OFFSET( num_ ## name ), \ |
| 699 id \ |
| 700 }, |
| 701 |
| 702 static const CFF_Field_Handler cff_field_handlers[] = |
| 703 { |
| 704 |
| 705 #include "cfftoken.h" |
| 706 |
| 707 { 0, 0, 0, 0, 0, 0, 0, 0 } |
| 708 }; |
| 709 |
| 710 |
| 711 #endif /* FT_DEBUG_LEVEL_TRACE */ |
| 712 |
| 713 |
654 #else /* FT_CONFIG_OPTION_PIC */ | 714 #else /* FT_CONFIG_OPTION_PIC */ |
655 | 715 |
656 void FT_Destroy_Class_cff_field_handlers(FT_Library library, CFF_Field_Handler
* clazz) | 716 |
| 717 void |
| 718 FT_Destroy_Class_cff_field_handlers( FT_Library library, |
| 719 CFF_Field_Handler* clazz ) |
657 { | 720 { |
658 FT_Memory memory = library->memory; | 721 FT_Memory memory = library->memory; |
| 722 |
| 723 |
659 if ( clazz ) | 724 if ( clazz ) |
660 FT_FREE( clazz ); | 725 FT_FREE( clazz ); |
661 } | 726 } |
662 | 727 |
663 FT_Error FT_Create_Class_cff_field_handlers(FT_Library library, CFF_Field_Hand
ler** output_class) | 728 |
| 729 FT_Error |
| 730 FT_Create_Class_cff_field_handlers( FT_Library library, |
| 731 CFF_Field_Handler** output_class ) |
664 { | 732 { |
665 CFF_Field_Handler* clazz; | 733 CFF_Field_Handler* clazz; |
666 FT_Error error; | 734 FT_Error error; |
667 FT_Memory memory = library->memory; | 735 FT_Memory memory = library->memory; |
668 int i=0; | 736 |
| 737 int i = 0; |
| 738 |
669 | 739 |
670 #undef CFF_FIELD | 740 #undef CFF_FIELD |
| 741 #define CFF_FIELD( code, name, id, kind ) i++; |
671 #undef CFF_FIELD_DELTA | 742 #undef CFF_FIELD_DELTA |
| 743 #define CFF_FIELD_DELTA( code, name, max, id ) i++; |
672 #undef CFF_FIELD_CALLBACK | 744 #undef CFF_FIELD_CALLBACK |
673 #define CFF_FIELD_CALLBACK( code, name ) i++; | 745 #define CFF_FIELD_CALLBACK( code, name, id ) i++; |
674 #define CFF_FIELD( code, name, kind ) i++; | 746 |
675 #define CFF_FIELD_DELTA( code, name, max ) i++; | 747 #include "cfftoken.h" |
676 | 748 |
677 #include "cfftoken.h" | 749 i++; /* { 0, 0, 0, 0, 0, 0, 0 } */ |
678 i++;/*{ 0, 0, 0, 0, 0, 0, 0 }*/ | 750 |
679 | 751 if ( FT_ALLOC( clazz, sizeof ( CFF_Field_Handler ) * i ) ) |
680 if ( FT_ALLOC( clazz, sizeof(CFF_Field_Handler)*i ) ) | |
681 return error; | 752 return error; |
682 | 753 |
683 i=0; | 754 i = 0; |
684 #undef CFF_FIELD | 755 |
685 #undef CFF_FIELD_DELTA | 756 |
| 757 #ifndef FT_DEBUG_LEVEL_TRACE |
| 758 |
| 759 |
686 #undef CFF_FIELD_CALLBACK | 760 #undef CFF_FIELD_CALLBACK |
687 | 761 #define CFF_FIELD_CALLBACK( code_, name_, id_ ) \ |
688 #define CFF_FIELD_CALLBACK( code_, name_ ) \ | 762 clazz[i].kind = cff_kind_callback; \ |
689 clazz[i].kind = cff_kind_callback; \ | 763 clazz[i].code = code_ | CFFCODE; \ |
690 clazz[i].code = code_ | CFFCODE; \ | 764 clazz[i].offset = 0; \ |
691 clazz[i].offset = 0; \ | 765 clazz[i].size = 0; \ |
692 clazz[i].size = 0; \ | 766 clazz[i].reader = cff_parse_ ## name_; \ |
693 clazz[i].reader = cff_parse_ ## name_; \ | 767 clazz[i].array_max = 0; \ |
694 clazz[i].array_max = 0; \ | 768 clazz[i].count_offset = 0; \ |
695 clazz[i].count_offset = 0; \ | 769 i++; |
696 i++; | |
697 | 770 |
698 #undef CFF_FIELD | 771 #undef CFF_FIELD |
699 #define CFF_FIELD( code_, name_, kind_ ) \ | 772 #define CFF_FIELD( code_, name_, id_, kind_ ) \ |
700 clazz[i].kind = kind_; \ | 773 clazz[i].kind = kind_; \ |
701 clazz[i].code = code_ | CFFCODE; \ | 774 clazz[i].code = code_ | CFFCODE; \ |
702 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ | 775 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ |
703 clazz[i].size = FT_FIELD_SIZE( name_ ); \ | 776 clazz[i].size = FT_FIELD_SIZE( name_ ); \ |
704 clazz[i].reader = 0; \ | 777 clazz[i].reader = 0; \ |
705 clazz[i].array_max = 0; \ | 778 clazz[i].array_max = 0; \ |
706 clazz[i].count_offset = 0; \ | 779 clazz[i].count_offset = 0; \ |
707 i++; \ | 780 i++; \ |
708 | 781 |
709 #undef CFF_FIELD_DELTA | 782 #undef CFF_FIELD_DELTA |
710 #define CFF_FIELD_DELTA( code_, name_, max_ ) \ | 783 #define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \ |
711 clazz[i].kind = cff_kind_delta; \ | 784 clazz[i].kind = cff_kind_delta; \ |
712 clazz[i].code = code_ | CFFCODE; \ | 785 clazz[i].code = code_ | CFFCODE; \ |
713 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ | 786 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ |
714 clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \ | 787 clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \ |
715 clazz[i].reader = 0; \ | 788 clazz[i].reader = 0; \ |
716 clazz[i].array_max = max_; \ | 789 clazz[i].array_max = max_; \ |
717 clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \ | 790 clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \ |
718 i++; | 791 i++; |
719 | 792 |
720 #include "cfftoken.h" | 793 #include "cfftoken.h" |
721 | 794 |
722 clazz[i].kind = 0; | 795 clazz[i].kind = 0; |
723 clazz[i].code = 0; | 796 clazz[i].code = 0; |
724 clazz[i].offset = 0; | 797 clazz[i].offset = 0; |
725 clazz[i].size = 0; | 798 clazz[i].size = 0; |
726 clazz[i].reader = 0; | 799 clazz[i].reader = 0; |
727 clazz[i].array_max = 0; | 800 clazz[i].array_max = 0; |
728 clazz[i].count_offset = 0; | 801 clazz[i].count_offset = 0; |
729 | 802 |
| 803 |
| 804 #else /* FT_DEBUG_LEVEL_TRACE */ |
| 805 |
| 806 |
| 807 #undef CFF_FIELD_CALLBACK |
| 808 #define CFF_FIELD_CALLBACK( code_, name_, id_ ) \ |
| 809 clazz[i].kind = cff_kind_callback; \ |
| 810 clazz[i].code = code_ | CFFCODE; \ |
| 811 clazz[i].offset = 0; \ |
| 812 clazz[i].size = 0; \ |
| 813 clazz[i].reader = cff_parse_ ## name_; \ |
| 814 clazz[i].array_max = 0; \ |
| 815 clazz[i].count_offset = 0; \ |
| 816 clazz[i].id = id_; \ |
| 817 i++; |
| 818 |
| 819 #undef CFF_FIELD |
| 820 #define CFF_FIELD( code_, name_, id_, kind_ ) \ |
| 821 clazz[i].kind = kind_; \ |
| 822 clazz[i].code = code_ | CFFCODE; \ |
| 823 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ |
| 824 clazz[i].size = FT_FIELD_SIZE( name_ ); \ |
| 825 clazz[i].reader = 0; \ |
| 826 clazz[i].array_max = 0; \ |
| 827 clazz[i].count_offset = 0; \ |
| 828 clazz[i].id = id_; \ |
| 829 i++; \ |
| 830 |
| 831 #undef CFF_FIELD_DELTA |
| 832 #define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \ |
| 833 clazz[i].kind = cff_kind_delta; \ |
| 834 clazz[i].code = code_ | CFFCODE; \ |
| 835 clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ |
| 836 clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \ |
| 837 clazz[i].reader = 0; \ |
| 838 clazz[i].array_max = max_; \ |
| 839 clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \ |
| 840 clazz[i].id = id_; \ |
| 841 i++; |
| 842 |
| 843 #include "cfftoken.h" |
| 844 |
| 845 clazz[i].kind = 0; |
| 846 clazz[i].code = 0; |
| 847 clazz[i].offset = 0; |
| 848 clazz[i].size = 0; |
| 849 clazz[i].reader = 0; |
| 850 clazz[i].array_max = 0; |
| 851 clazz[i].count_offset = 0; |
| 852 clazz[i].id = 0; |
| 853 |
| 854 |
| 855 #endif /* FT_DEBUG_LEVEL_TRACE */ |
| 856 |
| 857 |
730 *output_class = clazz; | 858 *output_class = clazz; |
| 859 |
731 return CFF_Err_Ok; | 860 return CFF_Err_Ok; |
732 } | 861 } |
733 | 862 |
734 | 863 |
735 #endif /* FT_CONFIG_OPTION_PIC */ | 864 #endif /* FT_CONFIG_OPTION_PIC */ |
736 | 865 |
737 | 866 |
738 FT_LOCAL_DEF( FT_Error ) | 867 FT_LOCAL_DEF( FT_Error ) |
739 cff_parser_run( CFF_Parser parser, | 868 cff_parser_run( CFF_Parser parser, |
740 FT_Byte* start, | 869 FT_Byte* start, |
741 FT_Byte* limit ) | 870 FT_Byte* limit ) |
742 { | 871 { |
743 FT_Byte* p = start; | 872 FT_Byte* p = start; |
744 FT_Error error = CFF_Err_Ok; | 873 FT_Error error = CFF_Err_Ok; |
745 FT_Library library = parser->library; | 874 FT_Library library = parser->library; |
746 FT_UNUSED(library); | 875 FT_UNUSED( library ); |
747 | 876 |
748 | 877 |
749 parser->top = parser->stack; | 878 parser->top = parser->stack; |
750 parser->start = start; | 879 parser->start = start; |
751 parser->limit = limit; | 880 parser->limit = limit; |
752 parser->cursor = start; | 881 parser->cursor = start; |
753 | 882 |
754 while ( p < limit ) | 883 while ( p < limit ) |
755 { | 884 { |
756 FT_UInt v = *p; | 885 FT_UInt v = *p; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 946 |
818 for ( field = FT_CFF_FIELD_HANDLERS_GET; field->kind; field++ ) | 947 for ( field = FT_CFF_FIELD_HANDLERS_GET; field->kind; field++ ) |
819 { | 948 { |
820 if ( field->code == (FT_Int)code ) | 949 if ( field->code == (FT_Int)code ) |
821 { | 950 { |
822 /* we found our field's handler; read it */ | 951 /* we found our field's handler; read it */ |
823 FT_Long val; | 952 FT_Long val; |
824 FT_Byte* q = (FT_Byte*)parser->object + field->offset; | 953 FT_Byte* q = (FT_Byte*)parser->object + field->offset; |
825 | 954 |
826 | 955 |
| 956 #ifdef FT_DEBUG_LEVEL_TRACE |
| 957 FT_TRACE4(( " %s", field->id )); |
| 958 #endif |
| 959 |
827 /* check that we have enough arguments -- except for */ | 960 /* check that we have enough arguments -- except for */ |
828 /* delta encoded arrays, which can be empty */ | 961 /* delta encoded arrays, which can be empty */ |
829 if ( field->kind != cff_kind_delta && num_args < 1 ) | 962 if ( field->kind != cff_kind_delta && num_args < 1 ) |
830 goto Stack_Underflow; | 963 goto Stack_Underflow; |
831 | 964 |
832 switch ( field->kind ) | 965 switch ( field->kind ) |
833 { | 966 { |
834 case cff_kind_bool: | 967 case cff_kind_bool: |
835 case cff_kind_string: | 968 case cff_kind_string: |
836 case cff_kind_num: | 969 case cff_kind_num: |
(...skipping 18 matching lines...) Expand all Loading... |
855 *(FT_Short*)q = (FT_Short)val; | 988 *(FT_Short*)q = (FT_Short)val; |
856 break; | 989 break; |
857 | 990 |
858 case (32 / FT_CHAR_BIT): | 991 case (32 / FT_CHAR_BIT): |
859 *(FT_Int32*)q = (FT_Int)val; | 992 *(FT_Int32*)q = (FT_Int)val; |
860 break; | 993 break; |
861 | 994 |
862 default: /* for 64-bit systems */ | 995 default: /* for 64-bit systems */ |
863 *(FT_Long*)q = val; | 996 *(FT_Long*)q = val; |
864 } | 997 } |
| 998 |
| 999 #ifdef FT_DEBUG_LEVEL_TRACE |
| 1000 switch ( field->kind ) |
| 1001 { |
| 1002 case cff_kind_bool: |
| 1003 FT_TRACE4(( " %s\n", val ? "true" : "false" )); |
| 1004 break; |
| 1005 |
| 1006 case cff_kind_string: |
| 1007 FT_TRACE4(( " %ld (SID)\n", val )); |
| 1008 break; |
| 1009 |
| 1010 case cff_kind_num: |
| 1011 FT_TRACE4(( " %ld\n", val )); |
| 1012 break; |
| 1013 |
| 1014 case cff_kind_fixed: |
| 1015 FT_TRACE4(( " %f\n", (double)val / 65536 )); |
| 1016 break; |
| 1017 |
| 1018 case cff_kind_fixed_thousand: |
| 1019 FT_TRACE4(( " %f\n", (double)val / 65536 / 1000 )); |
| 1020 |
| 1021 default: |
| 1022 ; /* never reached */ |
| 1023 } |
| 1024 #endif |
| 1025 |
865 break; | 1026 break; |
866 | 1027 |
867 case cff_kind_delta: | 1028 case cff_kind_delta: |
868 { | 1029 { |
869 FT_Byte* qcount = (FT_Byte*)parser->object + | 1030 FT_Byte* qcount = (FT_Byte*)parser->object + |
870 field->count_offset; | 1031 field->count_offset; |
871 | 1032 |
872 FT_Byte** data = parser->stack; | 1033 FT_Byte** data = parser->stack; |
873 | 1034 |
874 | 1035 |
875 if ( num_args > field->array_max ) | 1036 if ( num_args > field->array_max ) |
876 num_args = field->array_max; | 1037 num_args = field->array_max; |
877 | 1038 |
| 1039 FT_TRACE4(( " [" )); |
| 1040 |
878 /* store count */ | 1041 /* store count */ |
879 *qcount = (FT_Byte)num_args; | 1042 *qcount = (FT_Byte)num_args; |
880 | 1043 |
881 val = 0; | 1044 val = 0; |
882 while ( num_args > 0 ) | 1045 while ( num_args > 0 ) |
883 { | 1046 { |
884 val += cff_parse_num( data++ ); | 1047 val += cff_parse_num( data++ ); |
885 switch ( field->size ) | 1048 switch ( field->size ) |
886 { | 1049 { |
887 case (8 / FT_CHAR_BIT): | 1050 case (8 / FT_CHAR_BIT): |
888 *(FT_Byte*)q = (FT_Byte)val; | 1051 *(FT_Byte*)q = (FT_Byte)val; |
889 break; | 1052 break; |
890 | 1053 |
891 case (16 / FT_CHAR_BIT): | 1054 case (16 / FT_CHAR_BIT): |
892 *(FT_Short*)q = (FT_Short)val; | 1055 *(FT_Short*)q = (FT_Short)val; |
893 break; | 1056 break; |
894 | 1057 |
895 case (32 / FT_CHAR_BIT): | 1058 case (32 / FT_CHAR_BIT): |
896 *(FT_Int32*)q = (FT_Int)val; | 1059 *(FT_Int32*)q = (FT_Int)val; |
897 break; | 1060 break; |
898 | 1061 |
899 default: /* for 64-bit systems */ | 1062 default: /* for 64-bit systems */ |
900 *(FT_Long*)q = val; | 1063 *(FT_Long*)q = val; |
901 } | 1064 } |
902 | 1065 |
| 1066 FT_TRACE4(( " %ld", val )); |
| 1067 |
903 q += field->size; | 1068 q += field->size; |
904 num_args--; | 1069 num_args--; |
905 } | 1070 } |
| 1071 |
| 1072 FT_TRACE4(( "]\n" )); |
906 } | 1073 } |
907 break; | 1074 break; |
908 | 1075 |
909 default: /* callback */ | 1076 default: /* callback */ |
910 error = field->reader( parser ); | 1077 error = field->reader( parser ); |
911 if ( error ) | 1078 if ( error ) |
912 goto Exit; | 1079 goto Exit; |
913 } | 1080 } |
914 goto Found; | 1081 goto Found; |
915 } | 1082 } |
(...skipping 20 matching lines...) Expand all Loading... |
936 error = CFF_Err_Invalid_Argument; | 1103 error = CFF_Err_Invalid_Argument; |
937 goto Exit; | 1104 goto Exit; |
938 | 1105 |
939 Syntax_Error: | 1106 Syntax_Error: |
940 error = CFF_Err_Invalid_Argument; | 1107 error = CFF_Err_Invalid_Argument; |
941 goto Exit; | 1108 goto Exit; |
942 } | 1109 } |
943 | 1110 |
944 | 1111 |
945 /* END */ | 1112 /* END */ |
OLD | NEW |