David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* cffload.c */ |
| 4 | /* */ |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 5 | /* OpenType and CFF data/program tables loader (body). */ |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 6 | /* */ |
Werner Lemberg | be3c981 | 2006-01-27 14:16:16 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006 by */ |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
| 10 | /* This file is part of the FreeType project, and may only be used, */ |
Werner Lemberg | 521a2d7 | 2001-03-20 22:58:56 +0000 | [diff] [blame] | 11 | /* modified, and distributed under the terms of the FreeType project */ |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 13 | /* this file you indicate that you have read the license and */ |
| 14 | /* understand and accept it fully. */ |
| 15 | /* */ |
| 16 | /***************************************************************************/ |
| 17 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 18 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 19 | #include <ft2build.h> |
| 20 | #include FT_INTERNAL_DEBUG_H |
| 21 | #include FT_INTERNAL_OBJECTS_H |
| 22 | #include FT_INTERNAL_STREAM_H |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 23 | #include FT_SERVICE_POSTSCRIPT_CMAPS_H |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 24 | #include FT_TRUETYPE_TAGS_H |
| 25 | |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 26 | #include "cffload.h" |
| 27 | #include "cffparse.h" |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 28 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 29 | #include "cfferrs.h" |
| 30 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 31 | |
David Turner | c808748 | 2001-12-20 13:14:18 +0000 | [diff] [blame] | 32 | #if 1 |
| 33 | static const FT_UShort cff_isoadobe_charset[229] = |
| 34 | { |
| 35 | 0, |
| 36 | 1, |
| 37 | 2, |
| 38 | 3, |
| 39 | 4, |
| 40 | 5, |
| 41 | 6, |
| 42 | 7, |
| 43 | 8, |
| 44 | 9, |
| 45 | 10, |
| 46 | 11, |
| 47 | 12, |
| 48 | 13, |
| 49 | 14, |
| 50 | 15, |
| 51 | 16, |
| 52 | 17, |
| 53 | 18, |
| 54 | 19, |
| 55 | 20, |
| 56 | 21, |
| 57 | 22, |
| 58 | 23, |
| 59 | 24, |
| 60 | 25, |
| 61 | 26, |
| 62 | 27, |
| 63 | 28, |
| 64 | 29, |
| 65 | 30, |
| 66 | 31, |
| 67 | 32, |
| 68 | 33, |
| 69 | 34, |
| 70 | 35, |
| 71 | 36, |
| 72 | 37, |
| 73 | 38, |
| 74 | 39, |
| 75 | 40, |
| 76 | 41, |
| 77 | 42, |
| 78 | 43, |
| 79 | 44, |
| 80 | 45, |
| 81 | 46, |
| 82 | 47, |
| 83 | 48, |
| 84 | 49, |
| 85 | 50, |
| 86 | 51, |
| 87 | 52, |
| 88 | 53, |
| 89 | 54, |
| 90 | 55, |
| 91 | 56, |
| 92 | 57, |
| 93 | 58, |
| 94 | 59, |
| 95 | 60, |
| 96 | 61, |
| 97 | 62, |
| 98 | 63, |
| 99 | 64, |
| 100 | 65, |
| 101 | 66, |
| 102 | 67, |
| 103 | 68, |
| 104 | 69, |
| 105 | 70, |
| 106 | 71, |
| 107 | 72, |
| 108 | 73, |
| 109 | 74, |
| 110 | 75, |
| 111 | 76, |
| 112 | 77, |
| 113 | 78, |
| 114 | 79, |
| 115 | 80, |
| 116 | 81, |
| 117 | 82, |
| 118 | 83, |
| 119 | 84, |
| 120 | 85, |
| 121 | 86, |
| 122 | 87, |
| 123 | 88, |
| 124 | 89, |
| 125 | 90, |
| 126 | 91, |
| 127 | 92, |
| 128 | 93, |
| 129 | 94, |
| 130 | 95, |
| 131 | 96, |
| 132 | 97, |
| 133 | 98, |
| 134 | 99, |
| 135 | 100, |
| 136 | 101, |
| 137 | 102, |
| 138 | 103, |
| 139 | 104, |
| 140 | 105, |
| 141 | 106, |
| 142 | 107, |
| 143 | 108, |
| 144 | 109, |
| 145 | 110, |
| 146 | 111, |
| 147 | 112, |
| 148 | 113, |
| 149 | 114, |
| 150 | 115, |
| 151 | 116, |
| 152 | 117, |
| 153 | 118, |
| 154 | 119, |
| 155 | 120, |
| 156 | 121, |
| 157 | 122, |
| 158 | 123, |
| 159 | 124, |
| 160 | 125, |
| 161 | 126, |
| 162 | 127, |
| 163 | 128, |
| 164 | 129, |
| 165 | 130, |
| 166 | 131, |
| 167 | 132, |
| 168 | 133, |
| 169 | 134, |
| 170 | 135, |
| 171 | 136, |
| 172 | 137, |
| 173 | 138, |
| 174 | 139, |
| 175 | 140, |
| 176 | 141, |
| 177 | 142, |
| 178 | 143, |
| 179 | 144, |
| 180 | 145, |
| 181 | 146, |
| 182 | 147, |
| 183 | 148, |
| 184 | 149, |
| 185 | 150, |
| 186 | 151, |
| 187 | 152, |
| 188 | 153, |
| 189 | 154, |
| 190 | 155, |
| 191 | 156, |
| 192 | 157, |
| 193 | 158, |
| 194 | 159, |
| 195 | 160, |
| 196 | 161, |
| 197 | 162, |
| 198 | 163, |
| 199 | 164, |
| 200 | 165, |
| 201 | 166, |
| 202 | 167, |
| 203 | 168, |
| 204 | 169, |
| 205 | 170, |
| 206 | 171, |
| 207 | 172, |
| 208 | 173, |
| 209 | 174, |
| 210 | 175, |
| 211 | 176, |
| 212 | 177, |
| 213 | 178, |
| 214 | 179, |
| 215 | 180, |
| 216 | 181, |
| 217 | 182, |
| 218 | 183, |
| 219 | 184, |
| 220 | 185, |
| 221 | 186, |
| 222 | 187, |
| 223 | 188, |
| 224 | 189, |
| 225 | 190, |
| 226 | 191, |
| 227 | 192, |
| 228 | 193, |
| 229 | 194, |
| 230 | 195, |
| 231 | 196, |
| 232 | 197, |
| 233 | 198, |
| 234 | 199, |
| 235 | 200, |
| 236 | 201, |
| 237 | 202, |
| 238 | 203, |
| 239 | 204, |
| 240 | 205, |
| 241 | 206, |
| 242 | 207, |
| 243 | 208, |
| 244 | 209, |
| 245 | 210, |
| 246 | 211, |
| 247 | 212, |
| 248 | 213, |
| 249 | 214, |
| 250 | 215, |
| 251 | 216, |
| 252 | 217, |
| 253 | 218, |
| 254 | 219, |
| 255 | 220, |
| 256 | 221, |
| 257 | 222, |
| 258 | 223, |
| 259 | 224, |
| 260 | 225, |
| 261 | 226, |
| 262 | 227, |
| 263 | 228 |
| 264 | }; |
| 265 | |
| 266 | static const FT_UShort cff_expert_charset[166] = |
| 267 | { |
| 268 | 0, |
| 269 | 1, |
| 270 | 229, |
| 271 | 230, |
| 272 | 231, |
| 273 | 232, |
| 274 | 233, |
| 275 | 234, |
| 276 | 235, |
| 277 | 236, |
| 278 | 237, |
| 279 | 238, |
| 280 | 13, |
| 281 | 14, |
| 282 | 15, |
| 283 | 99, |
| 284 | 239, |
| 285 | 240, |
| 286 | 241, |
| 287 | 242, |
| 288 | 243, |
| 289 | 244, |
| 290 | 245, |
| 291 | 246, |
| 292 | 247, |
| 293 | 248, |
| 294 | 27, |
| 295 | 28, |
| 296 | 249, |
| 297 | 250, |
| 298 | 251, |
| 299 | 252, |
| 300 | 253, |
| 301 | 254, |
| 302 | 255, |
| 303 | 256, |
| 304 | 257, |
| 305 | 258, |
| 306 | 259, |
| 307 | 260, |
| 308 | 261, |
| 309 | 262, |
| 310 | 263, |
| 311 | 264, |
| 312 | 265, |
| 313 | 266, |
| 314 | 109, |
| 315 | 110, |
| 316 | 267, |
| 317 | 268, |
| 318 | 269, |
| 319 | 270, |
| 320 | 271, |
| 321 | 272, |
| 322 | 273, |
| 323 | 274, |
| 324 | 275, |
| 325 | 276, |
| 326 | 277, |
| 327 | 278, |
| 328 | 279, |
| 329 | 280, |
| 330 | 281, |
| 331 | 282, |
| 332 | 283, |
| 333 | 284, |
| 334 | 285, |
| 335 | 286, |
| 336 | 287, |
| 337 | 288, |
| 338 | 289, |
| 339 | 290, |
| 340 | 291, |
| 341 | 292, |
| 342 | 293, |
| 343 | 294, |
| 344 | 295, |
| 345 | 296, |
| 346 | 297, |
| 347 | 298, |
| 348 | 299, |
| 349 | 300, |
| 350 | 301, |
| 351 | 302, |
| 352 | 303, |
| 353 | 304, |
| 354 | 305, |
| 355 | 306, |
| 356 | 307, |
| 357 | 308, |
| 358 | 309, |
| 359 | 310, |
| 360 | 311, |
| 361 | 312, |
| 362 | 313, |
| 363 | 314, |
| 364 | 315, |
| 365 | 316, |
| 366 | 317, |
| 367 | 318, |
| 368 | 158, |
| 369 | 155, |
| 370 | 163, |
| 371 | 319, |
| 372 | 320, |
| 373 | 321, |
| 374 | 322, |
| 375 | 323, |
| 376 | 324, |
| 377 | 325, |
| 378 | 326, |
| 379 | 150, |
| 380 | 164, |
| 381 | 169, |
| 382 | 327, |
| 383 | 328, |
| 384 | 329, |
| 385 | 330, |
| 386 | 331, |
| 387 | 332, |
| 388 | 333, |
| 389 | 334, |
| 390 | 335, |
| 391 | 336, |
| 392 | 337, |
| 393 | 338, |
| 394 | 339, |
| 395 | 340, |
| 396 | 341, |
| 397 | 342, |
| 398 | 343, |
| 399 | 344, |
| 400 | 345, |
| 401 | 346, |
| 402 | 347, |
| 403 | 348, |
| 404 | 349, |
| 405 | 350, |
| 406 | 351, |
| 407 | 352, |
| 408 | 353, |
| 409 | 354, |
| 410 | 355, |
| 411 | 356, |
| 412 | 357, |
| 413 | 358, |
| 414 | 359, |
| 415 | 360, |
| 416 | 361, |
| 417 | 362, |
| 418 | 363, |
| 419 | 364, |
| 420 | 365, |
| 421 | 366, |
| 422 | 367, |
| 423 | 368, |
| 424 | 369, |
| 425 | 370, |
| 426 | 371, |
| 427 | 372, |
| 428 | 373, |
| 429 | 374, |
| 430 | 375, |
| 431 | 376, |
| 432 | 377, |
| 433 | 378 |
| 434 | }; |
| 435 | |
| 436 | static const FT_UShort cff_expertsubset_charset[87] = |
| 437 | { |
| 438 | 0, |
| 439 | 1, |
| 440 | 231, |
| 441 | 232, |
| 442 | 235, |
| 443 | 236, |
| 444 | 237, |
| 445 | 238, |
| 446 | 13, |
| 447 | 14, |
| 448 | 15, |
| 449 | 99, |
| 450 | 239, |
| 451 | 240, |
| 452 | 241, |
| 453 | 242, |
| 454 | 243, |
| 455 | 244, |
| 456 | 245, |
| 457 | 246, |
| 458 | 247, |
| 459 | 248, |
| 460 | 27, |
| 461 | 28, |
| 462 | 249, |
| 463 | 250, |
| 464 | 251, |
| 465 | 253, |
| 466 | 254, |
| 467 | 255, |
| 468 | 256, |
| 469 | 257, |
| 470 | 258, |
| 471 | 259, |
| 472 | 260, |
| 473 | 261, |
| 474 | 262, |
| 475 | 263, |
| 476 | 264, |
| 477 | 265, |
| 478 | 266, |
| 479 | 109, |
| 480 | 110, |
| 481 | 267, |
| 482 | 268, |
| 483 | 269, |
| 484 | 270, |
| 485 | 272, |
| 486 | 300, |
| 487 | 301, |
| 488 | 302, |
| 489 | 305, |
| 490 | 314, |
| 491 | 315, |
| 492 | 158, |
| 493 | 155, |
| 494 | 163, |
| 495 | 320, |
| 496 | 321, |
| 497 | 322, |
| 498 | 323, |
| 499 | 324, |
| 500 | 325, |
| 501 | 326, |
| 502 | 150, |
| 503 | 164, |
| 504 | 169, |
| 505 | 327, |
| 506 | 328, |
| 507 | 329, |
| 508 | 330, |
| 509 | 331, |
| 510 | 332, |
| 511 | 333, |
| 512 | 334, |
| 513 | 335, |
| 514 | 336, |
| 515 | 337, |
| 516 | 338, |
| 517 | 339, |
| 518 | 340, |
| 519 | 341, |
| 520 | 342, |
| 521 | 343, |
| 522 | 344, |
| 523 | 345, |
| 524 | 346 |
| 525 | }; |
| 526 | |
| 527 | static const FT_UShort cff_standard_encoding[256] = |
| 528 | { |
| 529 | 0, |
| 530 | 0, |
| 531 | 0, |
| 532 | 0, |
| 533 | 0, |
| 534 | 0, |
| 535 | 0, |
| 536 | 0, |
| 537 | 0, |
| 538 | 0, |
| 539 | 0, |
| 540 | 0, |
| 541 | 0, |
| 542 | 0, |
| 543 | 0, |
| 544 | 0, |
| 545 | 0, |
| 546 | 0, |
| 547 | 0, |
| 548 | 0, |
| 549 | 0, |
| 550 | 0, |
| 551 | 0, |
| 552 | 0, |
| 553 | 0, |
| 554 | 0, |
| 555 | 0, |
| 556 | 0, |
| 557 | 0, |
| 558 | 0, |
| 559 | 0, |
| 560 | 0, |
| 561 | 1, |
| 562 | 2, |
| 563 | 3, |
| 564 | 4, |
| 565 | 5, |
| 566 | 6, |
| 567 | 7, |
| 568 | 8, |
| 569 | 9, |
| 570 | 10, |
| 571 | 11, |
| 572 | 12, |
| 573 | 13, |
| 574 | 14, |
| 575 | 15, |
| 576 | 16, |
| 577 | 17, |
| 578 | 18, |
| 579 | 19, |
| 580 | 20, |
| 581 | 21, |
| 582 | 22, |
| 583 | 23, |
| 584 | 24, |
| 585 | 25, |
| 586 | 26, |
| 587 | 27, |
| 588 | 28, |
| 589 | 29, |
| 590 | 30, |
| 591 | 31, |
| 592 | 32, |
| 593 | 33, |
| 594 | 34, |
| 595 | 35, |
| 596 | 36, |
| 597 | 37, |
| 598 | 38, |
| 599 | 39, |
| 600 | 40, |
| 601 | 41, |
| 602 | 42, |
| 603 | 43, |
| 604 | 44, |
| 605 | 45, |
| 606 | 46, |
| 607 | 47, |
| 608 | 48, |
| 609 | 49, |
| 610 | 50, |
| 611 | 51, |
| 612 | 52, |
| 613 | 53, |
| 614 | 54, |
| 615 | 55, |
| 616 | 56, |
| 617 | 57, |
| 618 | 58, |
| 619 | 59, |
| 620 | 60, |
| 621 | 61, |
| 622 | 62, |
| 623 | 63, |
| 624 | 64, |
| 625 | 65, |
| 626 | 66, |
| 627 | 67, |
| 628 | 68, |
| 629 | 69, |
| 630 | 70, |
| 631 | 71, |
| 632 | 72, |
| 633 | 73, |
| 634 | 74, |
| 635 | 75, |
| 636 | 76, |
| 637 | 77, |
| 638 | 78, |
| 639 | 79, |
| 640 | 80, |
| 641 | 81, |
| 642 | 82, |
| 643 | 83, |
| 644 | 84, |
| 645 | 85, |
| 646 | 86, |
| 647 | 87, |
| 648 | 88, |
| 649 | 89, |
| 650 | 90, |
| 651 | 91, |
| 652 | 92, |
| 653 | 93, |
| 654 | 94, |
| 655 | 95, |
| 656 | 0, |
| 657 | 0, |
| 658 | 0, |
| 659 | 0, |
| 660 | 0, |
| 661 | 0, |
| 662 | 0, |
| 663 | 0, |
| 664 | 0, |
| 665 | 0, |
| 666 | 0, |
| 667 | 0, |
| 668 | 0, |
| 669 | 0, |
| 670 | 0, |
| 671 | 0, |
| 672 | 0, |
| 673 | 0, |
| 674 | 0, |
| 675 | 0, |
| 676 | 0, |
| 677 | 0, |
| 678 | 0, |
| 679 | 0, |
| 680 | 0, |
| 681 | 0, |
| 682 | 0, |
| 683 | 0, |
| 684 | 0, |
| 685 | 0, |
| 686 | 0, |
| 687 | 0, |
| 688 | 0, |
| 689 | 0, |
| 690 | 96, |
| 691 | 97, |
| 692 | 98, |
| 693 | 99, |
| 694 | 100, |
| 695 | 101, |
| 696 | 102, |
| 697 | 103, |
| 698 | 104, |
| 699 | 105, |
| 700 | 106, |
| 701 | 107, |
| 702 | 108, |
| 703 | 109, |
| 704 | 110, |
| 705 | 0, |
| 706 | 111, |
| 707 | 112, |
| 708 | 113, |
| 709 | 114, |
| 710 | 0, |
| 711 | 115, |
| 712 | 116, |
| 713 | 117, |
| 714 | 118, |
| 715 | 119, |
| 716 | 120, |
| 717 | 121, |
| 718 | 122, |
| 719 | 0, |
| 720 | 123, |
| 721 | 0, |
| 722 | 124, |
| 723 | 125, |
| 724 | 126, |
| 725 | 127, |
| 726 | 128, |
| 727 | 129, |
| 728 | 130, |
| 729 | 131, |
| 730 | 0, |
| 731 | 132, |
| 732 | 133, |
| 733 | 0, |
| 734 | 134, |
| 735 | 135, |
| 736 | 136, |
| 737 | 137, |
| 738 | 0, |
| 739 | 0, |
| 740 | 0, |
| 741 | 0, |
| 742 | 0, |
| 743 | 0, |
| 744 | 0, |
| 745 | 0, |
| 746 | 0, |
| 747 | 0, |
| 748 | 0, |
| 749 | 0, |
| 750 | 0, |
| 751 | 0, |
| 752 | 0, |
| 753 | 0, |
| 754 | 138, |
| 755 | 0, |
| 756 | 139, |
| 757 | 0, |
| 758 | 0, |
| 759 | 0, |
| 760 | 0, |
| 761 | 140, |
| 762 | 141, |
| 763 | 142, |
| 764 | 143, |
| 765 | 0, |
| 766 | 0, |
| 767 | 0, |
| 768 | 0, |
| 769 | 0, |
| 770 | 144, |
| 771 | 0, |
| 772 | 0, |
| 773 | 0, |
| 774 | 145, |
| 775 | 0, |
| 776 | 0, |
| 777 | 146, |
| 778 | 147, |
| 779 | 148, |
| 780 | 149, |
| 781 | 0, |
| 782 | 0, |
| 783 | 0, |
| 784 | 0 |
| 785 | }; |
| 786 | |
| 787 | static const FT_UShort cff_expert_encoding[256] = |
| 788 | { |
| 789 | 0, |
| 790 | 0, |
| 791 | 0, |
| 792 | 0, |
| 793 | 0, |
| 794 | 0, |
| 795 | 0, |
| 796 | 0, |
| 797 | 0, |
| 798 | 0, |
| 799 | 0, |
| 800 | 0, |
| 801 | 0, |
| 802 | 0, |
| 803 | 0, |
| 804 | 0, |
| 805 | 0, |
| 806 | 0, |
| 807 | 0, |
| 808 | 0, |
| 809 | 0, |
| 810 | 0, |
| 811 | 0, |
| 812 | 0, |
| 813 | 0, |
| 814 | 0, |
| 815 | 0, |
| 816 | 0, |
| 817 | 0, |
| 818 | 0, |
| 819 | 0, |
| 820 | 0, |
| 821 | 1, |
| 822 | 229, |
| 823 | 230, |
| 824 | 0, |
| 825 | 231, |
| 826 | 232, |
| 827 | 233, |
| 828 | 234, |
| 829 | 235, |
| 830 | 236, |
| 831 | 237, |
| 832 | 238, |
| 833 | 13, |
| 834 | 14, |
| 835 | 15, |
| 836 | 99, |
| 837 | 239, |
| 838 | 240, |
| 839 | 241, |
| 840 | 242, |
| 841 | 243, |
| 842 | 244, |
| 843 | 245, |
| 844 | 246, |
| 845 | 247, |
| 846 | 248, |
| 847 | 27, |
| 848 | 28, |
| 849 | 249, |
| 850 | 250, |
| 851 | 251, |
| 852 | 252, |
| 853 | 0, |
| 854 | 253, |
| 855 | 254, |
| 856 | 255, |
| 857 | 256, |
| 858 | 257, |
| 859 | 0, |
| 860 | 0, |
| 861 | 0, |
| 862 | 258, |
| 863 | 0, |
| 864 | 0, |
| 865 | 259, |
| 866 | 260, |
| 867 | 261, |
| 868 | 262, |
| 869 | 0, |
| 870 | 0, |
| 871 | 263, |
| 872 | 264, |
| 873 | 265, |
| 874 | 0, |
| 875 | 266, |
| 876 | 109, |
| 877 | 110, |
| 878 | 267, |
| 879 | 268, |
| 880 | 269, |
| 881 | 0, |
| 882 | 270, |
| 883 | 271, |
| 884 | 272, |
| 885 | 273, |
| 886 | 274, |
| 887 | 275, |
| 888 | 276, |
| 889 | 277, |
| 890 | 278, |
| 891 | 279, |
| 892 | 280, |
| 893 | 281, |
| 894 | 282, |
| 895 | 283, |
| 896 | 284, |
| 897 | 285, |
| 898 | 286, |
| 899 | 287, |
| 900 | 288, |
| 901 | 289, |
| 902 | 290, |
| 903 | 291, |
| 904 | 292, |
| 905 | 293, |
| 906 | 294, |
| 907 | 295, |
| 908 | 296, |
| 909 | 297, |
| 910 | 298, |
| 911 | 299, |
| 912 | 300, |
| 913 | 301, |
| 914 | 302, |
| 915 | 303, |
| 916 | 0, |
| 917 | 0, |
| 918 | 0, |
| 919 | 0, |
| 920 | 0, |
| 921 | 0, |
| 922 | 0, |
| 923 | 0, |
| 924 | 0, |
| 925 | 0, |
| 926 | 0, |
| 927 | 0, |
| 928 | 0, |
| 929 | 0, |
| 930 | 0, |
| 931 | 0, |
| 932 | 0, |
| 933 | 0, |
| 934 | 0, |
| 935 | 0, |
| 936 | 0, |
| 937 | 0, |
| 938 | 0, |
| 939 | 0, |
| 940 | 0, |
| 941 | 0, |
| 942 | 0, |
| 943 | 0, |
| 944 | 0, |
| 945 | 0, |
| 946 | 0, |
| 947 | 0, |
| 948 | 0, |
| 949 | 0, |
| 950 | 304, |
| 951 | 305, |
| 952 | 306, |
| 953 | 0, |
| 954 | 0, |
| 955 | 307, |
| 956 | 308, |
| 957 | 309, |
| 958 | 310, |
| 959 | 311, |
| 960 | 0, |
| 961 | 312, |
| 962 | 0, |
| 963 | 0, |
| 964 | 312, |
| 965 | 0, |
| 966 | 0, |
| 967 | 314, |
| 968 | 315, |
| 969 | 0, |
| 970 | 0, |
| 971 | 316, |
| 972 | 317, |
| 973 | 318, |
| 974 | 0, |
| 975 | 0, |
| 976 | 0, |
| 977 | 158, |
| 978 | 155, |
| 979 | 163, |
| 980 | 319, |
| 981 | 320, |
| 982 | 321, |
| 983 | 322, |
| 984 | 323, |
| 985 | 324, |
| 986 | 325, |
| 987 | 0, |
| 988 | 0, |
| 989 | 326, |
| 990 | 150, |
| 991 | 164, |
| 992 | 169, |
| 993 | 327, |
| 994 | 328, |
| 995 | 329, |
| 996 | 330, |
| 997 | 331, |
| 998 | 332, |
| 999 | 333, |
| 1000 | 334, |
| 1001 | 335, |
| 1002 | 336, |
| 1003 | 337, |
| 1004 | 338, |
| 1005 | 339, |
| 1006 | 340, |
| 1007 | 341, |
| 1008 | 342, |
| 1009 | 343, |
| 1010 | 344, |
| 1011 | 345, |
| 1012 | 346, |
| 1013 | 347, |
| 1014 | 348, |
| 1015 | 349, |
| 1016 | 350, |
| 1017 | 351, |
| 1018 | 352, |
| 1019 | 353, |
| 1020 | 354, |
| 1021 | 355, |
| 1022 | 356, |
| 1023 | 357, |
| 1024 | 358, |
| 1025 | 359, |
| 1026 | 360, |
| 1027 | 361, |
| 1028 | 362, |
| 1029 | 363, |
| 1030 | 364, |
| 1031 | 365, |
| 1032 | 366, |
| 1033 | 367, |
| 1034 | 368, |
| 1035 | 369, |
| 1036 | 370, |
| 1037 | 371, |
| 1038 | 372, |
| 1039 | 373, |
| 1040 | 374, |
| 1041 | 375, |
| 1042 | 376, |
| 1043 | 377, |
| 1044 | 378 |
| 1045 | }; |
| 1046 | #endif |
| 1047 | |
| 1048 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1049 | FT_LOCAL_DEF( FT_UShort ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1050 | cff_get_standard_encoding( FT_UInt charcode ) |
David Turner | c808748 | 2001-12-20 13:14:18 +0000 | [diff] [blame] | 1051 | { |
David Turner | f86709a | 2002-01-07 10:04:09 +0000 | [diff] [blame] | 1052 | return (FT_UShort)(charcode < 256 ? cff_standard_encoding[charcode] : 0); |
David Turner | c808748 | 2001-12-20 13:14:18 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1056 | /*************************************************************************/ |
| 1057 | /* */ |
| 1058 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 1059 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 1060 | /* messages during execution. */ |
| 1061 | /* */ |
| 1062 | #undef FT_COMPONENT |
Tom Kacvinsky | 8d1f604 | 2001-01-03 00:21:59 +0000 | [diff] [blame] | 1063 | #define FT_COMPONENT trace_cffload |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1064 | |
David Turner | 12d40da | 2001-10-21 15:41:11 +0000 | [diff] [blame] | 1065 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1066 | /* read a CFF offset from memory */ |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1067 | static FT_ULong |
| 1068 | cff_get_offset( FT_Byte* p, |
| 1069 | FT_Byte off_size ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1070 | { |
| 1071 | FT_ULong result; |
| 1072 | |
| 1073 | |
| 1074 | for ( result = 0; off_size > 0; off_size-- ) |
| 1075 | { |
| 1076 | result <<= 8; |
| 1077 | result |= *p++; |
| 1078 | } |
| 1079 | |
| 1080 | return result; |
| 1081 | } |
| 1082 | |
| 1083 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1084 | static FT_Error |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1085 | cff_new_index( CFF_Index idx, |
| 1086 | FT_Stream stream, |
| 1087 | FT_Bool load ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1088 | { |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1089 | FT_Error error; |
| 1090 | FT_Memory memory = stream->memory; |
| 1091 | FT_UShort count; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1092 | |
| 1093 | |
Werner Lemberg | b3d5e9c | 2002-07-28 05:05:24 +0000 | [diff] [blame] | 1094 | FT_MEM_ZERO( idx, sizeof ( *idx ) ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1095 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1096 | idx->stream = stream; |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1097 | if ( !FT_READ_USHORT( count ) && |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 1098 | count > 0 ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1099 | { |
| 1100 | FT_Byte* p; |
| 1101 | FT_Byte offsize; |
| 1102 | FT_ULong data_size; |
| 1103 | FT_ULong* poff; |
| 1104 | |
| 1105 | |
| 1106 | /* there is at least one element; read the offset size, */ |
| 1107 | /* then access the offset table to compute the index's total size */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1108 | if ( FT_READ_BYTE( offsize ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1109 | goto Exit; |
| 1110 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1111 | idx->stream = stream; |
| 1112 | idx->count = count; |
| 1113 | idx->off_size = offsize; |
| 1114 | data_size = (FT_ULong)( count + 1 ) * offsize; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1115 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1116 | if ( FT_NEW_ARRAY( idx->offsets, count + 1 ) || |
| 1117 | FT_FRAME_ENTER( data_size ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1118 | goto Exit; |
| 1119 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1120 | poff = idx->offsets; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1121 | p = (FT_Byte*)stream->cursor; |
| 1122 | |
| 1123 | for ( ; (FT_Short)count >= 0; count-- ) |
| 1124 | { |
| 1125 | poff[0] = cff_get_offset( p, offsize ); |
| 1126 | poff++; |
| 1127 | p += offsize; |
| 1128 | } |
| 1129 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1130 | FT_FRAME_EXIT(); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1131 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1132 | idx->data_offset = FT_STREAM_POS(); |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1133 | data_size = poff[-1] - 1; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1134 | |
| 1135 | if ( load ) |
| 1136 | { |
| 1137 | /* load the data */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1138 | if ( FT_FRAME_EXTRACT( data_size, idx->bytes ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1139 | goto Exit; |
| 1140 | } |
| 1141 | else |
| 1142 | { |
| 1143 | /* skip the data */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1144 | if ( FT_STREAM_SKIP( data_size ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1145 | goto Exit; |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | Exit: |
| 1150 | if ( error ) |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1151 | FT_FREE( idx->offsets ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1152 | |
| 1153 | return error; |
| 1154 | } |
| 1155 | |
| 1156 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1157 | static void |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1158 | cff_done_index( CFF_Index idx ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1159 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1160 | if ( idx->stream ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1161 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1162 | FT_Stream stream = idx->stream; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1163 | FT_Memory memory = stream->memory; |
| 1164 | |
| 1165 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1166 | if ( idx->bytes ) |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1167 | FT_FRAME_RELEASE( idx->bytes ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1168 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1169 | FT_FREE( idx->offsets ); |
Werner Lemberg | b3d5e9c | 2002-07-28 05:05:24 +0000 | [diff] [blame] | 1170 | FT_MEM_ZERO( idx, sizeof ( *idx ) ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 1175 | /* allocate a table containing pointers to an index's elements */ |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1176 | static FT_Error |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1177 | cff_index_get_pointers( CFF_Index idx, |
| 1178 | FT_Byte*** table ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1179 | { |
Werner Lemberg | bfb712f | 2004-03-03 08:21:12 +0000 | [diff] [blame] | 1180 | FT_Error error = CFF_Err_Ok; |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1181 | FT_Memory memory = idx->stream->memory; |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 1182 | FT_ULong n, offset, old_offset; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1183 | FT_Byte** t; |
| 1184 | |
| 1185 | |
| 1186 | *table = 0; |
| 1187 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1188 | if ( idx->count > 0 && !FT_NEW_ARRAY( t, idx->count + 1 ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1189 | { |
| 1190 | old_offset = 1; |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1191 | for ( n = 0; n <= idx->count; n++ ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1192 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1193 | offset = idx->offsets[n]; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1194 | if ( !offset ) |
| 1195 | offset = old_offset; |
| 1196 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1197 | t[n] = idx->bytes + offset - 1; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1198 | |
| 1199 | old_offset = offset; |
| 1200 | } |
| 1201 | *table = t; |
| 1202 | } |
| 1203 | |
| 1204 | return error; |
| 1205 | } |
| 1206 | |
| 1207 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1208 | FT_LOCAL_DEF( FT_Error ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1209 | cff_index_access_element( CFF_Index idx, |
| 1210 | FT_UInt element, |
| 1211 | FT_Byte** pbytes, |
| 1212 | FT_ULong* pbyte_len ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1213 | { |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 1214 | FT_Error error = CFF_Err_Ok; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1215 | |
| 1216 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1217 | if ( idx && idx->count > element ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1218 | { |
| 1219 | /* compute start and end offsets */ |
| 1220 | FT_ULong off1, off2 = 0; |
| 1221 | |
| 1222 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1223 | off1 = idx->offsets[element]; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1224 | if ( off1 ) |
| 1225 | { |
| 1226 | do |
| 1227 | { |
| 1228 | element++; |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1229 | off2 = idx->offsets[element]; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1230 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1231 | } while ( off2 == 0 && element < idx->count ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1232 | |
| 1233 | if ( !off2 ) |
| 1234 | off1 = 0; |
| 1235 | } |
| 1236 | |
| 1237 | /* access element */ |
| 1238 | if ( off1 ) |
| 1239 | { |
| 1240 | *pbyte_len = off2 - off1; |
| 1241 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1242 | if ( idx->bytes ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1243 | { |
| 1244 | /* this index was completely loaded in memory, that's easy */ |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1245 | *pbytes = idx->bytes + off1 - 1; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1246 | } |
| 1247 | else |
| 1248 | { |
| 1249 | /* this index is still on disk/file, access it through a frame */ |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1250 | FT_Stream stream = idx->stream; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1251 | |
| 1252 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1253 | if ( FT_STREAM_SEEK( idx->data_offset + off1 - 1 ) || |
| 1254 | FT_FRAME_EXTRACT( off2 - off1, *pbytes ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1255 | goto Exit; |
| 1256 | } |
| 1257 | } |
| 1258 | else |
| 1259 | { |
| 1260 | /* empty index element */ |
| 1261 | *pbytes = 0; |
| 1262 | *pbyte_len = 0; |
| 1263 | } |
| 1264 | } |
| 1265 | else |
Tom Kacvinsky | 8d1f604 | 2001-01-03 00:21:59 +0000 | [diff] [blame] | 1266 | error = CFF_Err_Invalid_Argument; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1267 | |
| 1268 | Exit: |
| 1269 | return error; |
| 1270 | } |
| 1271 | |
| 1272 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1273 | FT_LOCAL_DEF( void ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1274 | cff_index_forget_element( CFF_Index idx, |
| 1275 | FT_Byte** pbytes ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1276 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1277 | if ( idx->bytes == 0 ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1278 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1279 | FT_Stream stream = idx->stream; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1280 | |
| 1281 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1282 | FT_FRAME_RELEASE( *pbytes ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1287 | FT_LOCAL_DEF( FT_String* ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1288 | cff_index_get_name( CFF_Index idx, |
| 1289 | FT_UInt element ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1290 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1291 | FT_Memory memory = idx->stream->memory; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1292 | FT_Byte* bytes; |
| 1293 | FT_ULong byte_len; |
| 1294 | FT_Error error; |
| 1295 | FT_String* name = 0; |
| 1296 | |
| 1297 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1298 | error = cff_index_access_element( idx, element, &bytes, &byte_len ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1299 | if ( error ) |
| 1300 | goto Exit; |
| 1301 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1302 | if ( !FT_ALLOC( name, byte_len + 1 ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1303 | { |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1304 | FT_MEM_COPY( name, bytes, byte_len ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1305 | name[byte_len] = 0; |
| 1306 | } |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1307 | cff_index_forget_element( idx, &bytes ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1308 | |
| 1309 | Exit: |
| 1310 | return name; |
| 1311 | } |
| 1312 | |
| 1313 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1314 | FT_LOCAL_DEF( FT_String* ) |
David Turner | b72d8a8 | 2003-09-29 20:33:37 +0000 | [diff] [blame] | 1315 | cff_index_get_sid_string( CFF_Index idx, |
| 1316 | FT_UInt sid, |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 1317 | FT_Service_PsCMaps psnames ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1318 | { |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 1319 | /* value 0xFFFFU indicates a missing dictionary entry */ |
| 1320 | if ( sid == 0xFFFFU ) |
| 1321 | return 0; |
| 1322 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1323 | /* if it is not a standard string, return it */ |
| 1324 | if ( sid > 390 ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1325 | return cff_index_get_name( idx, sid - 391 ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1326 | |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 1327 | /* CID-keyed CFF fonts don't have glyph names */ |
| 1328 | if ( !psnames ) |
| 1329 | return 0; |
| 1330 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1331 | /* that's a standard string, fetch a copy from the PSName module */ |
| 1332 | { |
| 1333 | FT_String* name = 0; |
David Turner | b72d8a8 | 2003-09-29 20:33:37 +0000 | [diff] [blame] | 1334 | const char* adobe_name = psnames->adobe_std_strings( sid ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1335 | FT_UInt len; |
| 1336 | |
| 1337 | |
| 1338 | if ( adobe_name ) |
| 1339 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 1340 | FT_Memory memory = idx->stream->memory; |
Werner Lemberg | b5349a9 | 2002-02-19 16:30:15 +0000 | [diff] [blame] | 1341 | FT_Error error; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1342 | |
| 1343 | |
David Turner | d15bc0d | 2002-04-12 09:31:48 +0000 | [diff] [blame] | 1344 | len = (FT_UInt)ft_strlen( adobe_name ); |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1345 | if ( !FT_ALLOC( name, len + 1 ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1346 | { |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1347 | FT_MEM_COPY( name, adobe_name, len ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1348 | name[len] = 0; |
| 1349 | } |
Werner Lemberg | b5349a9 | 2002-02-19 16:30:15 +0000 | [diff] [blame] | 1350 | |
| 1351 | FT_UNUSED( error ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | return name; |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | /*************************************************************************/ |
| 1360 | /*************************************************************************/ |
| 1361 | /*** ***/ |
| 1362 | /*** FD Select table support ***/ |
| 1363 | /*** ***/ |
| 1364 | /*************************************************************************/ |
| 1365 | /*************************************************************************/ |
| 1366 | |
| 1367 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1368 | static void |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1369 | CFF_Done_FD_Select( CFF_FDSelect fdselect, |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1370 | FT_Stream stream ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1371 | { |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1372 | if ( fdselect->data ) |
| 1373 | FT_FRAME_RELEASE( fdselect->data ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1374 | |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1375 | fdselect->data_size = 0; |
| 1376 | fdselect->format = 0; |
| 1377 | fdselect->range_count = 0; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1381 | static FT_Error |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1382 | CFF_Load_FD_Select( CFF_FDSelect fdselect, |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1383 | FT_UInt num_glyphs, |
| 1384 | FT_Stream stream, |
| 1385 | FT_ULong offset ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1386 | { |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1387 | FT_Error error; |
| 1388 | FT_Byte format; |
| 1389 | FT_UInt num_ranges; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1390 | |
| 1391 | |
| 1392 | /* read format */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1393 | if ( FT_STREAM_SEEK( offset ) || FT_READ_BYTE( format ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1394 | goto Exit; |
| 1395 | |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1396 | fdselect->format = format; |
| 1397 | fdselect->cache_count = 0; /* clear cache */ |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1398 | |
| 1399 | switch ( format ) |
| 1400 | { |
| 1401 | case 0: /* format 0, that's simple */ |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1402 | fdselect->data_size = num_glyphs; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1403 | goto Load_Data; |
| 1404 | |
| 1405 | case 3: /* format 3, a tad more complex */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1406 | if ( FT_READ_USHORT( num_ranges ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1407 | goto Exit; |
| 1408 | |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1409 | fdselect->data_size = num_ranges * 3 + 2; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1410 | |
| 1411 | Load_Data: |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1412 | if ( FT_FRAME_EXTRACT( fdselect->data_size, fdselect->data ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1413 | goto Exit; |
| 1414 | break; |
| 1415 | |
| 1416 | default: /* hmm... that's wrong */ |
Tom Kacvinsky | 8d1f604 | 2001-01-03 00:21:59 +0000 | [diff] [blame] | 1417 | error = CFF_Err_Invalid_File_Format; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | Exit: |
| 1421 | return error; |
| 1422 | } |
| 1423 | |
| 1424 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1425 | FT_LOCAL_DEF( FT_Byte ) |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1426 | cff_fd_select_get( CFF_FDSelect fdselect, |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1427 | FT_UInt glyph_index ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1428 | { |
| 1429 | FT_Byte fd = 0; |
| 1430 | |
| 1431 | |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1432 | switch ( fdselect->format ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1433 | { |
| 1434 | case 0: |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1435 | fd = fdselect->data[glyph_index]; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1436 | break; |
| 1437 | |
| 1438 | case 3: |
| 1439 | /* first, compare to cache */ |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1440 | if ( (FT_UInt)( glyph_index - fdselect->cache_first ) < |
| 1441 | fdselect->cache_count ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1442 | { |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1443 | fd = fdselect->cache_fd; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1444 | break; |
| 1445 | } |
| 1446 | |
| 1447 | /* then, lookup the ranges array */ |
| 1448 | { |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1449 | FT_Byte* p = fdselect->data; |
| 1450 | FT_Byte* p_limit = p + fdselect->data_size; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1451 | FT_Byte fd2; |
| 1452 | FT_UInt first, limit; |
| 1453 | |
| 1454 | |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1455 | first = FT_NEXT_USHORT( p ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1456 | do |
| 1457 | { |
| 1458 | if ( glyph_index < first ) |
| 1459 | break; |
| 1460 | |
| 1461 | fd2 = *p++; |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1462 | limit = FT_NEXT_USHORT( p ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1463 | |
| 1464 | if ( glyph_index < limit ) |
| 1465 | { |
| 1466 | fd = fd2; |
| 1467 | |
| 1468 | /* update cache */ |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1469 | fdselect->cache_first = first; |
| 1470 | fdselect->cache_count = limit-first; |
| 1471 | fdselect->cache_fd = fd2; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1472 | break; |
| 1473 | } |
| 1474 | first = limit; |
| 1475 | |
| 1476 | } while ( p < p_limit ); |
| 1477 | } |
| 1478 | break; |
| 1479 | |
| 1480 | default: |
| 1481 | ; |
| 1482 | } |
| 1483 | |
| 1484 | return fd; |
| 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | /*************************************************************************/ |
| 1489 | /*************************************************************************/ |
| 1490 | /*** ***/ |
| 1491 | /*** CFF font support ***/ |
| 1492 | /*** ***/ |
| 1493 | /*************************************************************************/ |
| 1494 | /*************************************************************************/ |
| 1495 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1496 | static void |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1497 | cff_charset_done( CFF_Charset charset, |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1498 | FT_Stream stream ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1499 | { |
| 1500 | FT_Memory memory = stream->memory; |
| 1501 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1502 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1503 | FT_FREE( charset->sids ); |
Werner Lemberg | a9cd856 | 2003-12-18 08:18:37 +0000 | [diff] [blame] | 1504 | FT_FREE( charset->cids ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1505 | charset->format = 0; |
| 1506 | charset->offset = 0; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1509 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1510 | static FT_Error |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1511 | cff_charset_load( CFF_Charset charset, |
David Turner | 2bf2b9c | 2002-03-20 09:44:20 +0000 | [diff] [blame] | 1512 | FT_UInt num_glyphs, |
| 1513 | FT_Stream stream, |
| 1514 | FT_ULong base_offset, |
Werner Lemberg | b36d4a5 | 2003-12-12 15:38:39 +0000 | [diff] [blame] | 1515 | FT_ULong offset, |
| 1516 | FT_Bool invert ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1517 | { |
Werner Lemberg | f35ff80 | 2003-06-02 21:58:05 +0000 | [diff] [blame] | 1518 | FT_Memory memory = stream->memory; |
Werner Lemberg | bfb712f | 2004-03-03 08:21:12 +0000 | [diff] [blame] | 1519 | FT_Error error = CFF_Err_Ok; |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1520 | FT_UShort glyph_sid; |
| 1521 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1522 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1523 | /* If the the offset is greater than 2, we have to parse the */ |
| 1524 | /* charset table. */ |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1525 | if ( offset > 2 ) |
| 1526 | { |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1527 | FT_UInt j; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1528 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1529 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1530 | charset->offset = base_offset + offset; |
| 1531 | |
| 1532 | /* Get the format of the table. */ |
| 1533 | if ( FT_STREAM_SEEK( charset->offset ) || |
| 1534 | FT_READ_BYTE( charset->format ) ) |
| 1535 | goto Exit; |
| 1536 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1537 | /* Allocate memory for sids. */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1538 | if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1539 | goto Exit; |
| 1540 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1541 | /* assign the .notdef glyph */ |
| 1542 | charset->sids[0] = 0; |
| 1543 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1544 | switch ( charset->format ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1545 | { |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1546 | case 0: |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1547 | if ( num_glyphs > 0 ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1548 | { |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1549 | if ( FT_FRAME_ENTER( ( num_glyphs - 1 ) * 2 ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1550 | goto Exit; |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1551 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1552 | for ( j = 1; j < num_glyphs; j++ ) |
| 1553 | charset->sids[j] = FT_GET_USHORT(); |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1554 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1555 | FT_FRAME_EXIT(); |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1556 | } |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1557 | break; |
| 1558 | |
| 1559 | case 1: |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1560 | case 2: |
| 1561 | { |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1562 | FT_UInt nleft; |
| 1563 | FT_UInt i; |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1564 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1565 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1566 | j = 1; |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1567 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1568 | while ( j < num_glyphs ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1569 | { |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1570 | /* Read the first glyph sid of the range. */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1571 | if ( FT_READ_USHORT( glyph_sid ) ) |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1572 | goto Exit; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1573 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1574 | /* Read the number of glyphs in the range. */ |
| 1575 | if ( charset->format == 2 ) |
| 1576 | { |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1577 | if ( FT_READ_USHORT( nleft ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1578 | goto Exit; |
| 1579 | } |
| 1580 | else |
| 1581 | { |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1582 | if ( FT_READ_BYTE( nleft ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1583 | goto Exit; |
| 1584 | } |
| 1585 | |
| 1586 | /* Fill in the range of sids -- `nleft + 1' glyphs. */ |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1587 | for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1588 | charset->sids[j] = glyph_sid; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1589 | } |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1590 | } |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1591 | break; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1592 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1593 | default: |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1594 | FT_ERROR(( "cff_charset_load: invalid table format!\n" )); |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1595 | error = CFF_Err_Invalid_File_Format; |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1596 | goto Exit; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1597 | } |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1598 | } |
| 1599 | else |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1600 | { |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1601 | /* Parse default tables corresponding to offset == 0, 1, or 2. */ |
| 1602 | /* CFF specification intimates the following: */ |
| 1603 | /* */ |
| 1604 | /* In order to use a predefined charset, the following must be */ |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1605 | /* true: The charset constructed for the glyphs in the font's */ |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1606 | /* charstrings dictionary must match the predefined charset in */ |
Werner Lemberg | 2acb963 | 2003-04-23 06:47:12 +0000 | [diff] [blame] | 1607 | /* the first num_glyphs. */ |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1608 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1609 | charset->offset = offset; /* record charset type */ |
| 1610 | |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 1611 | switch ( (FT_UInt)offset ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1612 | { |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1613 | case 0: |
David Turner | c227868 | 2002-11-23 15:53:57 +0000 | [diff] [blame] | 1614 | if ( num_glyphs > 229 ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1615 | { |
Werner Lemberg | b36d4a5 | 2003-12-12 15:38:39 +0000 | [diff] [blame] | 1616 | FT_ERROR(( "cff_charset_load: implicit charset larger than\n" |
| 1617 | "predefined charset (Adobe ISO-Latin)!\n" )); |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1618 | error = CFF_Err_Invalid_File_Format; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1619 | goto Exit; |
| 1620 | } |
| 1621 | |
| 1622 | /* Allocate memory for sids. */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1623 | if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1624 | goto Exit; |
| 1625 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1626 | /* Copy the predefined charset into the allocated memory. */ |
David Turner | 4632fcc | 2004-01-15 19:07:44 +0000 | [diff] [blame] | 1627 | FT_ARRAY_COPY( charset->sids, cff_isoadobe_charset, num_glyphs ); |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1628 | |
| 1629 | break; |
| 1630 | |
| 1631 | case 1: |
David Turner | c227868 | 2002-11-23 15:53:57 +0000 | [diff] [blame] | 1632 | if ( num_glyphs > 166 ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1633 | { |
David Turner | c227868 | 2002-11-23 15:53:57 +0000 | [diff] [blame] | 1634 | FT_ERROR(( "cff_charset_load: implicit charset larger than\n" |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1635 | "predefined charset (Adobe Expert)!\n" )); |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1636 | error = CFF_Err_Invalid_File_Format; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1637 | goto Exit; |
| 1638 | } |
| 1639 | |
| 1640 | /* Allocate memory for sids. */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1641 | if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1642 | goto Exit; |
| 1643 | |
| 1644 | /* Copy the predefined charset into the allocated memory. */ |
David Turner | 4632fcc | 2004-01-15 19:07:44 +0000 | [diff] [blame] | 1645 | FT_ARRAY_COPY( charset->sids, cff_expert_charset, num_glyphs ); |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1646 | |
| 1647 | break; |
| 1648 | |
| 1649 | case 2: |
David Turner | c227868 | 2002-11-23 15:53:57 +0000 | [diff] [blame] | 1650 | if ( num_glyphs > 87 ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1651 | { |
David Turner | c227868 | 2002-11-23 15:53:57 +0000 | [diff] [blame] | 1652 | FT_ERROR(( "cff_charset_load: implicit charset larger than\n" |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1653 | "predefined charset (Adobe Expert Subset)!\n" )); |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1654 | error = CFF_Err_Invalid_File_Format; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1655 | goto Exit; |
| 1656 | } |
| 1657 | |
| 1658 | /* Allocate memory for sids. */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 1659 | if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1660 | goto Exit; |
| 1661 | |
| 1662 | /* Copy the predefined charset into the allocated memory. */ |
David Turner | 4632fcc | 2004-01-15 19:07:44 +0000 | [diff] [blame] | 1663 | FT_ARRAY_COPY( charset->sids, cff_expertsubset_charset, num_glyphs ); |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1664 | |
| 1665 | break; |
| 1666 | |
| 1667 | default: |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1668 | error = CFF_Err_Invalid_File_Format; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1669 | goto Exit; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1670 | } |
| 1671 | } |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1672 | |
Werner Lemberg | a9cd856 | 2003-12-18 08:18:37 +0000 | [diff] [blame] | 1673 | /* we have to invert the `sids' array for subsetted CID-keyed fonts */ |
Werner Lemberg | b36d4a5 | 2003-12-12 15:38:39 +0000 | [diff] [blame] | 1674 | if ( invert ) |
| 1675 | { |
| 1676 | FT_UInt i; |
| 1677 | FT_UShort max_cid = 0; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1678 | |
Werner Lemberg | b36d4a5 | 2003-12-12 15:38:39 +0000 | [diff] [blame] | 1679 | |
| 1680 | for ( i = 0; i < num_glyphs; i++ ) |
| 1681 | if ( charset->sids[i] > max_cid ) |
| 1682 | max_cid = charset->sids[i]; |
| 1683 | max_cid++; |
| 1684 | |
| 1685 | if ( FT_NEW_ARRAY( charset->cids, max_cid ) ) |
| 1686 | goto Exit; |
| 1687 | FT_MEM_ZERO( charset->cids, sizeof ( FT_UShort ) * max_cid ); |
| 1688 | |
| 1689 | for ( i = 0; i < num_glyphs; i++ ) |
David Turner | 750fa96 | 2005-05-01 10:11:32 +0000 | [diff] [blame] | 1690 | charset->cids[charset->sids[i]] = (FT_UShort)i; |
Werner Lemberg | b36d4a5 | 2003-12-12 15:38:39 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | Exit: |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1694 | /* Clean up if there was an error. */ |
| 1695 | if ( error ) |
Werner Lemberg | b36d4a5 | 2003-12-12 15:38:39 +0000 | [diff] [blame] | 1696 | { |
| 1697 | FT_FREE( charset->sids ); |
| 1698 | FT_FREE( charset->cids ); |
| 1699 | charset->format = 0; |
| 1700 | charset->offset = 0; |
| 1701 | charset->sids = 0; |
| 1702 | } |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1703 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1704 | return error; |
| 1705 | } |
| 1706 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1707 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1708 | static void |
| 1709 | cff_encoding_done( CFF_Encoding encoding ) |
| 1710 | { |
| 1711 | encoding->format = 0; |
| 1712 | encoding->offset = 0; |
| 1713 | encoding->count = 0; |
| 1714 | } |
| 1715 | |
| 1716 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1717 | static FT_Error |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1718 | cff_encoding_load( CFF_Encoding encoding, |
David Turner | ab4fc4d | 2002-03-14 08:57:10 +0000 | [diff] [blame] | 1719 | CFF_Charset charset, |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1720 | FT_UInt num_glyphs, |
| 1721 | FT_Stream stream, |
| 1722 | FT_ULong base_offset, |
| 1723 | FT_ULong offset ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1724 | { |
Werner Lemberg | bfb712f | 2004-03-03 08:21:12 +0000 | [diff] [blame] | 1725 | FT_Error error = CFF_Err_Ok; |
Werner Lemberg | f35ff80 | 2003-06-02 21:58:05 +0000 | [diff] [blame] | 1726 | FT_UInt count; |
| 1727 | FT_UInt j; |
| 1728 | FT_UShort glyph_sid; |
| 1729 | FT_UInt glyph_code; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1730 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1731 | |
| 1732 | /* Check for charset->sids. If we do not have this, we fail. */ |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1733 | if ( !charset->sids ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1734 | { |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1735 | error = CFF_Err_Invalid_File_Format; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1736 | goto Exit; |
| 1737 | } |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1738 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1739 | /* Zero out the code to gid/sid mappings. */ |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1740 | for ( j = 0; j < 256; j++ ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1741 | { |
| 1742 | encoding->sids [j] = 0; |
| 1743 | encoding->codes[j] = 0; |
| 1744 | } |
| 1745 | |
Werner Lemberg | f35ff80 | 2003-06-02 21:58:05 +0000 | [diff] [blame] | 1746 | /* Note: The encoding table in a CFF font is indexed by glyph index; */ |
| 1747 | /* the first encoded glyph index is 1. Hence, we read the character */ |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1748 | /* code (`glyph_code') at index j and make the assignment: */ |
| 1749 | /* */ |
| 1750 | /* encoding->codes[glyph_code] = j + 1 */ |
| 1751 | /* */ |
| 1752 | /* We also make the assignment: */ |
| 1753 | /* */ |
| 1754 | /* encoding->sids[glyph_code] = charset->sids[j + 1] */ |
| 1755 | /* */ |
| 1756 | /* This gives us both a code to GID and a code to SID mapping. */ |
| 1757 | |
| 1758 | if ( offset > 1 ) |
| 1759 | { |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1760 | encoding->offset = base_offset + offset; |
| 1761 | |
| 1762 | /* we need to parse the table to determine its size */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1763 | if ( FT_STREAM_SEEK( encoding->offset ) || |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1764 | FT_READ_BYTE( encoding->format ) || |
| 1765 | FT_READ_BYTE( count ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1766 | goto Exit; |
| 1767 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1768 | switch ( encoding->format & 0x7F ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1769 | { |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1770 | case 0: |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1771 | { |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1772 | FT_Byte* p; |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1773 | |
Werner Lemberg | 2acb963 | 2003-04-23 06:47:12 +0000 | [diff] [blame] | 1774 | |
| 1775 | /* By convention, GID 0 is always ".notdef" and is never */ |
| 1776 | /* coded in the font. Hence, the number of codes found */ |
| 1777 | /* in the table is `count+1'. */ |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1778 | /* */ |
| 1779 | encoding->count = count + 1; |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1780 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1781 | if ( FT_FRAME_ENTER( count ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1782 | goto Exit; |
| 1783 | |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1784 | p = (FT_Byte*)stream->cursor; |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1785 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1786 | for ( j = 1; j <= count; j++ ) |
| 1787 | { |
| 1788 | glyph_code = *p++; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1789 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1790 | /* Make sure j is not too big. */ |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1791 | if ( j < num_glyphs ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1792 | { |
| 1793 | /* Assign code to GID mapping. */ |
| 1794 | encoding->codes[glyph_code] = (FT_UShort)j; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1795 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1796 | /* Assign code to SID mapping. */ |
| 1797 | encoding->sids[glyph_code] = charset->sids[j]; |
| 1798 | } |
| 1799 | } |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1800 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1801 | FT_FRAME_EXIT(); |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1802 | } |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1803 | break; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1804 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1805 | case 1: |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1806 | { |
Werner Lemberg | deb5510 | 2003-06-20 07:50:13 +0000 | [diff] [blame] | 1807 | FT_UInt nleft; |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1808 | FT_UInt i = 1; |
| 1809 | FT_UInt k; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1810 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1811 | |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1812 | encoding->count = 0; |
| 1813 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1814 | /* Parse the Format1 ranges. */ |
| 1815 | for ( j = 0; j < count; j++, i += nleft ) |
| 1816 | { |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1817 | /* Read the first glyph code of the range. */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1818 | if ( FT_READ_BYTE( glyph_code ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1819 | goto Exit; |
| 1820 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1821 | /* Read the number of codes in the range. */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1822 | if ( FT_READ_BYTE( nleft ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1823 | goto Exit; |
| 1824 | |
| 1825 | /* Increment nleft, so we read `nleft + 1' codes/sids. */ |
| 1826 | nleft++; |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1827 | |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1828 | /* compute max number of character codes */ |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1829 | if ( (FT_UInt)nleft > encoding->count ) |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1830 | encoding->count = nleft; |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1831 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1832 | /* Fill in the range of codes/sids. */ |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1833 | for ( k = i; k < nleft + i; k++, glyph_code++ ) |
| 1834 | { |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1835 | /* Make sure k is not too big. */ |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1836 | if ( k < num_glyphs && glyph_code < 256 ) |
| 1837 | { |
| 1838 | /* Assign code to GID mapping. */ |
| 1839 | encoding->codes[glyph_code] = (FT_UShort)k; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1840 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1841 | /* Assign code to SID mapping. */ |
| 1842 | encoding->sids[glyph_code] = charset->sids[k]; |
| 1843 | } |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1844 | } |
| 1845 | } |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1846 | |
Werner Lemberg | 2acb963 | 2003-04-23 06:47:12 +0000 | [diff] [blame] | 1847 | /* simple check; one never knows what can be found in a font */ |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1848 | if ( encoding->count > 256 ) |
| 1849 | encoding->count = 256; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1850 | } |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1851 | break; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1852 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1853 | default: |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1854 | FT_ERROR(( "cff_encoding_load: invalid table format!\n" )); |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1855 | error = CFF_Err_Invalid_File_Format; |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1856 | goto Exit; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1859 | /* Parse supplemental encodings, if any. */ |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 1860 | if ( encoding->format & 0x80 ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1861 | { |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1862 | FT_UInt gindex; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1863 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1864 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1865 | /* count supplements */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1866 | if ( FT_READ_BYTE( count ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1867 | goto Exit; |
| 1868 | |
| 1869 | for ( j = 0; j < count; j++ ) |
| 1870 | { |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1871 | /* Read supplemental glyph code. */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1872 | if ( FT_READ_BYTE( glyph_code ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1873 | goto Exit; |
| 1874 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1875 | /* Read the SID associated with this glyph code. */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1876 | if ( FT_READ_USHORT( glyph_sid ) ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1877 | goto Exit; |
| 1878 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1879 | /* Assign code to SID mapping. */ |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1880 | encoding->sids[glyph_code] = glyph_sid; |
| 1881 | |
Werner Lemberg | f35ff80 | 2003-06-02 21:58:05 +0000 | [diff] [blame] | 1882 | /* First, look up GID which has been assigned to */ |
| 1883 | /* SID glyph_sid. */ |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1884 | for ( gindex = 0; gindex < num_glyphs; gindex++ ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1885 | { |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1886 | if ( charset->sids[gindex] == glyph_sid ) |
| 1887 | { |
Werner Lemberg | f35ff80 | 2003-06-02 21:58:05 +0000 | [diff] [blame] | 1888 | encoding->codes[glyph_code] = (FT_UShort)gindex; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1889 | break; |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1890 | } |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1891 | } |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1892 | } |
| 1893 | } |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1894 | } |
| 1895 | else |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1896 | { |
| 1897 | FT_UInt i; |
| 1898 | |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1899 | |
Werner Lemberg | f35ff80 | 2003-06-02 21:58:05 +0000 | [diff] [blame] | 1900 | /* We take into account the fact a CFF font can use a predefined */ |
| 1901 | /* encoding without containing all of the glyphs encoded by this */ |
| 1902 | /* encoding (see the note at the end of section 12 in the CFF */ |
| 1903 | /* specification). */ |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1904 | |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 1905 | switch ( (FT_UInt)offset ) |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1906 | { |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1907 | case 0: |
Werner Lemberg | 6b76663 | 2000-12-30 22:14:58 +0000 | [diff] [blame] | 1908 | /* First, copy the code to SID mapping. */ |
David Turner | 4632fcc | 2004-01-15 19:07:44 +0000 | [diff] [blame] | 1909 | FT_ARRAY_COPY( encoding->sids, cff_standard_encoding, 256 ); |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1910 | goto Populate; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1911 | |
| 1912 | case 1: |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1913 | /* First, copy the code to SID mapping. */ |
David Turner | 4632fcc | 2004-01-15 19:07:44 +0000 | [diff] [blame] | 1914 | FT_ARRAY_COPY( encoding->sids, cff_expert_encoding, 256 ); |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1915 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1916 | Populate: |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1917 | /* Construct code to GID mapping from code to SID mapping */ |
| 1918 | /* and charset. */ |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1919 | |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1920 | encoding->count = 0; |
| 1921 | |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1922 | for ( j = 0; j < 256; j++ ) |
| 1923 | { |
| 1924 | /* If j is encoded, find the GID for it. */ |
| 1925 | if ( encoding->sids[j] ) |
| 1926 | { |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1927 | for ( i = 1; i < num_glyphs; i++ ) |
| 1928 | /* We matched, so break. */ |
| 1929 | if ( charset->sids[i] == encoding->sids[j] ) |
| 1930 | break; |
| 1931 | |
| 1932 | /* i will be equal to num_glyphs if we exited the above */ |
| 1933 | /* loop without a match. In this case, we also have to */ |
| 1934 | /* fix the code to SID mapping. */ |
| 1935 | if ( i == num_glyphs ) |
| 1936 | { |
| 1937 | encoding->codes[j] = 0; |
| 1938 | encoding->sids [j] = 0; |
| 1939 | } |
| 1940 | else |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1941 | { |
David Turner | 8edbcab | 2001-06-19 08:28:24 +0000 | [diff] [blame] | 1942 | encoding->codes[j] = (FT_UShort)i; |
David Turner | 4bdf435 | 2003-01-30 23:24:18 +0000 | [diff] [blame] | 1943 | |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1944 | /* update encoding count */ |
Werner Lemberg | 2acb963 | 2003-04-23 06:47:12 +0000 | [diff] [blame] | 1945 | if ( encoding->count < j + 1 ) |
| 1946 | encoding->count = j + 1; |
David Turner | 9967dce | 2002-11-23 16:41:23 +0000 | [diff] [blame] | 1947 | } |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1948 | } |
| 1949 | } |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1950 | break; |
| 1951 | |
| 1952 | default: |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1953 | FT_ERROR(( "cff_encoding_load: invalid table format!\n" )); |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1954 | error = CFF_Err_Invalid_File_Format; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1955 | goto Exit; |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1956 | } |
| 1957 | } |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1958 | |
| 1959 | Exit: |
Tom Kacvinsky | 4ba1c0a | 2000-12-30 00:37:14 +0000 | [diff] [blame] | 1960 | |
| 1961 | /* Clean up if there was an error. */ |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1962 | return error; |
| 1963 | } |
| 1964 | |
| 1965 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 1966 | static FT_Error |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1967 | cff_subfont_load( CFF_SubFont font, |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1968 | CFF_Index idx, |
| 1969 | FT_UInt font_index, |
| 1970 | FT_Stream stream, |
| 1971 | FT_ULong base_offset ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1972 | { |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1973 | FT_Error error; |
| 1974 | CFF_ParserRec parser; |
Werner Lemberg | 658f263 | 2004-01-24 15:06:57 +0000 | [diff] [blame] | 1975 | FT_Byte* dict = NULL; |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1976 | FT_ULong dict_len; |
David Turner | ab4fc4d | 2002-03-14 08:57:10 +0000 | [diff] [blame] | 1977 | CFF_FontRecDict top = &font->font_dict; |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 1978 | CFF_Private priv = &font->private_dict; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1979 | |
| 1980 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 1981 | cff_parser_init( &parser, CFF_CODE_TOPDICT, &font->font_dict ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1982 | |
| 1983 | /* set defaults */ |
Werner Lemberg | b3d5e9c | 2002-07-28 05:05:24 +0000 | [diff] [blame] | 1984 | FT_MEM_ZERO( top, sizeof ( *top ) ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1985 | |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 1986 | top->underline_position = -100L << 16; |
| 1987 | top->underline_thickness = 50L << 16; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 1988 | top->charstring_type = 2; |
| 1989 | top->font_matrix.xx = 0x10000L; |
| 1990 | top->font_matrix.yy = 0x10000L; |
| 1991 | top->cid_count = 8720; |
| 1992 | |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 1993 | /* we use the implementation specific SID value 0xFFFF to indicate */ |
| 1994 | /* missing entries */ |
| 1995 | top->version = 0xFFFFU; |
| 1996 | top->notice = 0xFFFFU; |
| 1997 | top->copyright = 0xFFFFU; |
| 1998 | top->full_name = 0xFFFFU; |
| 1999 | top->family_name = 0xFFFFU; |
| 2000 | top->weight = 0xFFFFU; |
| 2001 | top->embedded_postscript = 0xFFFFU; |
| 2002 | |
| 2003 | top->cid_registry = 0xFFFFU; |
| 2004 | top->cid_ordering = 0xFFFFU; |
| 2005 | top->cid_font_name = 0xFFFFU; |
| 2006 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2007 | error = cff_index_access_element( idx, font_index, &dict, &dict_len ) || |
| 2008 | cff_parser_run( &parser, dict, dict + dict_len ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2009 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2010 | cff_index_forget_element( idx, &dict ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2011 | |
| 2012 | if ( error ) |
| 2013 | goto Exit; |
| 2014 | |
| 2015 | /* if it is a CID font, we stop there */ |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 2016 | if ( top->cid_registry != 0xFFFFU ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2017 | goto Exit; |
| 2018 | |
| 2019 | /* parse the private dictionary, if any */ |
| 2020 | if ( top->private_offset && top->private_size ) |
| 2021 | { |
| 2022 | /* set defaults */ |
Werner Lemberg | b3d5e9c | 2002-07-28 05:05:24 +0000 | [diff] [blame] | 2023 | FT_MEM_ZERO( priv, sizeof ( *priv ) ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2024 | |
| 2025 | priv->blue_shift = 7; |
| 2026 | priv->blue_fuzz = 1; |
| 2027 | priv->lenIV = -1; |
Werner Lemberg | bf7c832 | 2003-06-06 05:07:53 +0000 | [diff] [blame] | 2028 | priv->expansion_factor = (FT_Fixed)( 0.06 * 0x10000L ); |
| 2029 | priv->blue_scale = (FT_Fixed)( 0.039625 * 0x10000L * 1000 ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2030 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2031 | cff_parser_init( &parser, CFF_CODE_PRIVATE, priv ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2032 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 2033 | if ( FT_STREAM_SEEK( base_offset + font->font_dict.private_offset ) || |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 2034 | FT_FRAME_ENTER( font->font_dict.private_size ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2035 | goto Exit; |
| 2036 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2037 | error = cff_parser_run( &parser, |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 2038 | (FT_Byte*)stream->cursor, |
| 2039 | (FT_Byte*)stream->limit ); |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 2040 | FT_FRAME_EXIT(); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2041 | if ( error ) |
| 2042 | goto Exit; |
| 2043 | } |
| 2044 | |
| 2045 | /* read the local subrs, if any */ |
| 2046 | if ( priv->local_subrs_offset ) |
| 2047 | { |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 2048 | if ( FT_STREAM_SEEK( base_offset + top->private_offset + |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 2049 | priv->local_subrs_offset ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2050 | goto Exit; |
| 2051 | |
| 2052 | error = cff_new_index( &font->local_subrs_index, stream, 1 ); |
| 2053 | if ( error ) |
| 2054 | goto Exit; |
| 2055 | |
| 2056 | font->num_local_subrs = font->local_subrs_index.count; |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2057 | error = cff_index_get_pointers( &font->local_subrs_index, |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 2058 | &font->local_subrs ); |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 2059 | if ( error ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2060 | goto Exit; |
| 2061 | } |
| 2062 | |
| 2063 | Exit: |
| 2064 | return error; |
| 2065 | } |
| 2066 | |
| 2067 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 2068 | static void |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2069 | cff_subfont_done( FT_Memory memory, |
David Turner | ab4fc4d | 2002-03-14 08:57:10 +0000 | [diff] [blame] | 2070 | CFF_SubFont subfont ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2071 | { |
| 2072 | if ( subfont ) |
| 2073 | { |
| 2074 | cff_done_index( &subfont->local_subrs_index ); |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 2075 | FT_FREE( subfont->local_subrs ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 2080 | FT_LOCAL_DEF( FT_Error ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2081 | cff_font_load( FT_Stream stream, |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 2082 | FT_Int face_index, |
Graham Asher | 9eefed1 | 2002-08-23 10:08:38 +0000 | [diff] [blame] | 2083 | CFF_Font font ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2084 | { |
| 2085 | static const FT_Frame_Field cff_header_fields[] = |
| 2086 | { |
| 2087 | #undef FT_STRUCTURE |
David Turner | ab4fc4d | 2002-03-14 08:57:10 +0000 | [diff] [blame] | 2088 | #define FT_STRUCTURE CFF_FontRec |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2089 | |
| 2090 | FT_FRAME_START( 4 ), |
| 2091 | FT_FRAME_BYTE( version_major ), |
| 2092 | FT_FRAME_BYTE( version_minor ), |
| 2093 | FT_FRAME_BYTE( header_size ), |
| 2094 | FT_FRAME_BYTE( absolute_offsize ), |
| 2095 | FT_FRAME_END |
| 2096 | }; |
| 2097 | |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 2098 | FT_Error error; |
| 2099 | FT_Memory memory = stream->memory; |
| 2100 | FT_ULong base_offset; |
David Turner | ab4fc4d | 2002-03-14 08:57:10 +0000 | [diff] [blame] | 2101 | CFF_FontRecDict dict; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2102 | |
Werner Lemberg | 0f2a415 | 2004-12-28 07:31:35 +0000 | [diff] [blame] | 2103 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2104 | FT_ZERO( font ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2105 | |
| 2106 | font->stream = stream; |
| 2107 | font->memory = memory; |
| 2108 | dict = &font->top_font.font_dict; |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 2109 | base_offset = FT_STREAM_POS(); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2110 | |
| 2111 | /* read CFF font header */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 2112 | if ( FT_STREAM_READ_FIELDS( cff_header_fields, font ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2113 | goto Exit; |
| 2114 | |
| 2115 | /* check format */ |
| 2116 | if ( font->version_major != 1 || |
| 2117 | font->header_size < 4 || |
| 2118 | font->absolute_offsize > 4 ) |
| 2119 | { |
| 2120 | FT_TRACE2(( "[not a CFF font header!]\n" )); |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 2121 | error = CFF_Err_Unknown_File_Format; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2122 | goto Exit; |
| 2123 | } |
| 2124 | |
| 2125 | /* skip the rest of the header */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 2126 | if ( FT_STREAM_SKIP( font->header_size - 4 ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2127 | goto Exit; |
| 2128 | |
| 2129 | /* read the name, top dict, string and global subrs index */ |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 2130 | if ( FT_SET_ERROR( cff_new_index( &font->name_index, stream, 0 )) || |
| 2131 | FT_SET_ERROR( cff_new_index( &font->font_dict_index, stream, 0 )) || |
| 2132 | FT_SET_ERROR( cff_new_index( &font->string_index, stream, 0 )) || |
| 2133 | FT_SET_ERROR( cff_new_index( &font->global_subrs_index, stream, 1 )) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2134 | goto Exit; |
| 2135 | |
| 2136 | /* well, we don't really forget the `disabled' fonts... */ |
| 2137 | font->num_faces = font->name_index.count; |
| 2138 | if ( face_index >= (FT_Int)font->num_faces ) |
| 2139 | { |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2140 | FT_ERROR(( "cff_font_load: incorrect face index = %d\n", |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2141 | face_index )); |
Tom Kacvinsky | 8d1f604 | 2001-01-03 00:21:59 +0000 | [diff] [blame] | 2142 | error = CFF_Err_Invalid_Argument; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | /* in case of a font format check, simply exit now */ |
| 2146 | if ( face_index < 0 ) |
| 2147 | goto Exit; |
| 2148 | |
| 2149 | /* now, parse the top-level font dictionary */ |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2150 | error = cff_subfont_load( &font->top_font, |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2151 | &font->font_dict_index, |
| 2152 | face_index, |
| 2153 | stream, |
| 2154 | base_offset ); |
| 2155 | if ( error ) |
| 2156 | goto Exit; |
| 2157 | |
Werner Lemberg | edeed6b | 2004-01-15 16:12:36 +0000 | [diff] [blame] | 2158 | if ( FT_STREAM_SEEK( base_offset + dict->charstrings_offset ) ) |
| 2159 | goto Exit; |
| 2160 | |
| 2161 | error = cff_new_index( &font->charstrings_index, stream, 0 ); |
| 2162 | if ( error ) |
| 2163 | goto Exit; |
| 2164 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2165 | /* now, check for a CID font */ |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 2166 | if ( dict->cid_registry != 0xFFFFU ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2167 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 2168 | CFF_IndexRec fd_index; |
Werner Lemberg | 48c984b | 2002-03-30 16:41:09 +0000 | [diff] [blame] | 2169 | CFF_SubFont sub; |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 2170 | FT_UInt idx; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2171 | |
| 2172 | |
| 2173 | /* this is a CID-keyed font, we must now allocate a table of */ |
| 2174 | /* sub-fonts, then load each of them separately */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 2175 | if ( FT_STREAM_SEEK( base_offset + dict->cid_fd_array_offset ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2176 | goto Exit; |
| 2177 | |
| 2178 | error = cff_new_index( &fd_index, stream, 0 ); |
| 2179 | if ( error ) |
| 2180 | goto Exit; |
| 2181 | |
| 2182 | if ( fd_index.count > CFF_MAX_CID_FONTS ) |
| 2183 | { |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2184 | FT_ERROR(( "cff_font_load: FD array too large in CID font\n" )); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2185 | goto Fail_CID; |
| 2186 | } |
| 2187 | |
| 2188 | /* allocate & read each font dict independently */ |
| 2189 | font->num_subfonts = fd_index.count; |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 2190 | if ( FT_NEW_ARRAY( sub, fd_index.count ) ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2191 | goto Fail_CID; |
| 2192 | |
Werner Lemberg | a10a9f9 | 2005-12-04 12:48:57 +0000 | [diff] [blame] | 2193 | /* set up pointer table */ |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 2194 | for ( idx = 0; idx < fd_index.count; idx++ ) |
| 2195 | font->subfonts[idx] = sub + idx; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2196 | |
Werner Lemberg | a10a9f9 | 2005-12-04 12:48:57 +0000 | [diff] [blame] | 2197 | /* now load each subfont independently */ |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 2198 | for ( idx = 0; idx < fd_index.count; idx++ ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2199 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 2200 | sub = font->subfonts[idx]; |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2201 | error = cff_subfont_load( sub, &fd_index, idx, |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2202 | stream, base_offset ); |
| 2203 | if ( error ) |
| 2204 | goto Fail_CID; |
| 2205 | } |
| 2206 | |
| 2207 | /* now load the FD Select array */ |
| 2208 | error = CFF_Load_FD_Select( &font->fd_select, |
Werner Lemberg | edeed6b | 2004-01-15 16:12:36 +0000 | [diff] [blame] | 2209 | font->charstrings_index.count, |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2210 | stream, |
| 2211 | base_offset + dict->cid_fd_select_offset ); |
| 2212 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 2213 | Fail_CID: |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2214 | cff_done_index( &fd_index ); |
| 2215 | |
| 2216 | if ( error ) |
| 2217 | goto Exit; |
| 2218 | } |
| 2219 | else |
| 2220 | font->num_subfonts = 0; |
| 2221 | |
Graham Asher | 9eefed1 | 2002-08-23 10:08:38 +0000 | [diff] [blame] | 2222 | /* read the charstrings index now */ |
| 2223 | if ( dict->charstrings_offset == 0 ) |
Werner Lemberg | f25ce9d | 2002-08-15 23:07:18 +0000 | [diff] [blame] | 2224 | { |
Graham Asher | 9eefed1 | 2002-08-23 10:08:38 +0000 | [diff] [blame] | 2225 | FT_ERROR(( "cff_font_load: no charstrings offset!\n" )); |
| 2226 | error = CFF_Err_Unknown_File_Format; |
| 2227 | goto Exit; |
Werner Lemberg | f25ce9d | 2002-08-15 23:07:18 +0000 | [diff] [blame] | 2228 | } |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2229 | |
| 2230 | /* explicit the global subrs */ |
| 2231 | font->num_global_subrs = font->global_subrs_index.count; |
| 2232 | font->num_glyphs = font->charstrings_index.count; |
| 2233 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2234 | error = cff_index_get_pointers( &font->global_subrs_index, |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 2235 | &font->global_subrs ) ; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2236 | |
| 2237 | if ( error ) |
| 2238 | goto Exit; |
| 2239 | |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 2240 | /* read the Charset and Encoding tables if available */ |
Graham Asher | 3fd12f1 | 2002-08-15 12:10:48 +0000 | [diff] [blame] | 2241 | if ( font->num_glyphs > 0 ) |
| 2242 | { |
David Turner | 750fa96 | 2005-05-01 10:11:32 +0000 | [diff] [blame] | 2243 | FT_Bool invert = FT_BOOL( dict->cid_registry != 0xFFFFU ); |
Werner Lemberg | a9cd856 | 2003-12-18 08:18:37 +0000 | [diff] [blame] | 2244 | |
| 2245 | |
Graham Asher | 3fd12f1 | 2002-08-15 12:10:48 +0000 | [diff] [blame] | 2246 | error = cff_charset_load( &font->charset, font->num_glyphs, stream, |
Werner Lemberg | a9cd856 | 2003-12-18 08:18:37 +0000 | [diff] [blame] | 2247 | base_offset, dict->charset_offset, invert ); |
Graham Asher | 3fd12f1 | 2002-08-15 12:10:48 +0000 | [diff] [blame] | 2248 | if ( error ) |
| 2249 | goto Exit; |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 2250 | |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 2251 | /* CID-keyed CFFs don't have an encoding */ |
| 2252 | if ( dict->cid_registry == 0xFFFFU ) |
| 2253 | { |
| 2254 | error = cff_encoding_load( &font->encoding, |
| 2255 | &font->charset, |
| 2256 | font->num_glyphs, |
| 2257 | stream, |
| 2258 | base_offset, |
| 2259 | dict->encoding_offset ); |
| 2260 | if ( error ) |
| 2261 | goto Exit; |
| 2262 | } |
Werner Lemberg | 83da52b | 2003-12-20 07:30:05 +0000 | [diff] [blame] | 2263 | else |
| 2264 | /* CID-keyed fonts only need CIDs */ |
| 2265 | FT_FREE( font->charset.sids ); |
Graham Asher | 3fd12f1 | 2002-08-15 12:10:48 +0000 | [diff] [blame] | 2266 | } |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 2267 | |
Werner Lemberg | 9b067fa | 2003-12-11 17:55:58 +0000 | [diff] [blame] | 2268 | /* get the font name (/CIDFontName for CID-keyed fonts, */ |
| 2269 | /* /FontName otherwise) */ |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2270 | font->font_name = cff_index_get_name( &font->name_index, face_index ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2271 | |
| 2272 | Exit: |
| 2273 | return error; |
| 2274 | } |
| 2275 | |
| 2276 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 2277 | FT_LOCAL_DEF( void ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2278 | cff_font_done( CFF_Font font ) |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2279 | { |
| 2280 | FT_Memory memory = font->memory; |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 2281 | FT_UInt idx; |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2282 | |
| 2283 | |
| 2284 | cff_done_index( &font->global_subrs_index ); |
| 2285 | cff_done_index( &font->string_index ); |
| 2286 | cff_done_index( &font->font_dict_index ); |
| 2287 | cff_done_index( &font->name_index ); |
| 2288 | cff_done_index( &font->charstrings_index ); |
| 2289 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 2290 | /* release font dictionaries, but only if working with */ |
| 2291 | /* a CID keyed CFF font */ |
Tom Kacvinsky | dfa4568 | 2001-10-21 20:26:59 +0000 | [diff] [blame] | 2292 | if ( font->num_subfonts > 0 ) |
| 2293 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 2294 | for ( idx = 0; idx < font->num_subfonts; idx++ ) |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2295 | cff_subfont_done( memory, font->subfonts[idx] ); |
Tom Kacvinsky | dfa4568 | 2001-10-21 20:26:59 +0000 | [diff] [blame] | 2296 | } |
Tom Kacvinsky | 98289a2 | 2001-10-21 16:29:16 +0000 | [diff] [blame] | 2297 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2298 | cff_encoding_done( &font->encoding ); |
| 2299 | cff_charset_done( &font->charset, font->stream ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2300 | |
David Turner | b9b2cac | 2002-07-10 16:52:06 +0000 | [diff] [blame] | 2301 | cff_subfont_done( memory, &font->top_font ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2302 | |
| 2303 | CFF_Done_FD_Select( &font->fd_select, font->stream ); |
| 2304 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 2305 | FT_FREE( font->global_subrs ); |
| 2306 | FT_FREE( font->font_name ); |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | |
| 2310 | /* END */ |