Hash :
b08fe2dc
Author :
Date :
2002-08-27T20:20:29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
/***************************************************************************/
/* */
/* ttcmap.c */
/* */
/* TrueType character mapping table (cmap) support (body). */
/* */
/* Copyright 1996-2001, 2002 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include "ttload.h"
#include "ttcmap.h"
#include "sferrors.h"
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_ttcmap
FT_CALLBACK_DEF( FT_UInt )
code_to_index0( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next0( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_UInt )
code_to_index2( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next2( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_UInt )
code_to_index4( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next4( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_UInt )
code_to_index6( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next6( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_UInt )
code_to_index8_12( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next8_12( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_UInt )
code_to_index10( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next10( TT_CMapTable charmap,
FT_ULong char_code );
/*************************************************************************/
/* */
/* <Function> */
/* tt_face_load_charmap */
/* */
/* <Description> */
/* Loads a given TrueType character map into memory. */
/* */
/* <Input> */
/* face :: A handle to the parent face object. */
/* */
/* stream :: A handle to the current stream object. */
/* */
/* <InOut> */
/* table :: A pointer to a cmap object. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* The function assumes that the stream is already in use (i.e., */
/* opened). In case of error, all partially allocated tables are */
/* released. */
/* */
FT_LOCAL_DEF( FT_Error )
tt_face_load_charmap( TT_Face face,
TT_CMapTable cmap,
FT_Stream stream )
{
FT_Error error;
FT_Memory memory;
FT_UShort num_SH, num_Seg, i;
FT_ULong j, n;
FT_UShort u, l;
TT_CMap0 cmap0;
TT_CMap2 cmap2;
TT_CMap4 cmap4;
TT_CMap6 cmap6;
TT_CMap8_12 cmap8_12;
TT_CMap10 cmap10;
TT_CMap2SubHeader cmap2sub;
TT_CMap4Segment segments;
TT_CMapGroup groups;
if ( cmap->loaded )
return SFNT_Err_Ok;
memory = stream->memory;
if ( FT_STREAM_SEEK( cmap->offset ) )
return error;
switch ( cmap->format )
{
case 0:
cmap0 = &cmap->c.cmap0;
if ( FT_READ_USHORT( cmap0->language ) ||
FT_ALLOC( cmap0->glyphIdArray, 256L ) ||
FT_STREAM_READ( cmap0->glyphIdArray, 256L ) )
goto Fail;
cmap->get_index = code_to_index0;
cmap->get_next_char = code_to_next0;
break;
case 2:
num_SH = 0;
cmap2 = &cmap->c.cmap2;
/* allocate subheader keys */
if ( FT_NEW_ARRAY( cmap2->subHeaderKeys, 256 ) ||
FT_FRAME_ENTER( 2L + 512L ) )
goto Fail;
cmap2->language = FT_GET_USHORT();
for ( i = 0; i < 256; i++ )
{
u = (FT_UShort)( FT_GET_USHORT() / 8 );
cmap2->subHeaderKeys[i] = u;
if ( num_SH < u )
num_SH = u;
}
FT_FRAME_EXIT();
/* load subheaders */
cmap2->numGlyphId = l = (FT_UShort)(
( ( cmap->length - 2L * ( 256 + 3 ) - num_SH * 8L ) & 0xFFFFU ) / 2 );
if ( FT_NEW_ARRAY( cmap2->subHeaders, num_SH + 1 ) ||
FT_FRAME_ENTER( ( num_SH + 1 ) * 8L ) )
{
FT_FREE( cmap2->subHeaderKeys );
goto Fail;
}
cmap2sub = cmap2->subHeaders;
for ( i = 0; i <= num_SH; i++ )
{
cmap2sub->firstCode = FT_GET_USHORT();
cmap2sub->entryCount = FT_GET_USHORT();
cmap2sub->idDelta = FT_GET_SHORT();
/* we apply the location offset immediately */
cmap2sub->idRangeOffset = (FT_UShort)(
FT_GET_USHORT() - ( num_SH - i ) * 8 - 2 );
cmap2sub++;
}
FT_FRAME_EXIT();
/* load glyph IDs */
if ( FT_NEW_ARRAY( cmap2->glyphIdArray, l ) ||
FT_FRAME_ENTER( l * 2L ) )
{
FT_FREE( cmap2->subHeaders );
FT_FREE( cmap2->subHeaderKeys );
goto Fail;
}
for ( i = 0; i < l; i++ )
cmap2->glyphIdArray[i] = FT_GET_USHORT();
FT_FRAME_EXIT();
cmap->get_index = code_to_index2;
cmap->get_next_char = code_to_next2;
break;
case 4:
cmap4 = &cmap->c.cmap4;
/* load header */
if ( FT_FRAME_ENTER( 10L ) )
goto Fail;
cmap4->language = FT_GET_USHORT();
cmap4->segCountX2 = FT_GET_USHORT();
cmap4->searchRange = FT_GET_USHORT();
cmap4->entrySelector = FT_GET_USHORT();
cmap4->rangeShift = FT_GET_USHORT();
num_Seg = (FT_UShort)( cmap4->segCountX2 / 2 );
FT_FRAME_EXIT();
/* load segments */
if ( FT_NEW_ARRAY( cmap4->segments, num_Seg ) ||
FT_FRAME_ENTER( ( num_Seg * 4 + 1 ) * 2L ) )
goto Fail;
segments = cmap4->segments;
for ( i = 0; i < num_Seg; i++ )
segments[i].endCount = FT_GET_USHORT();
(void)FT_GET_USHORT();
for ( i = 0; i < num_Seg; i++ )
segments[i].startCount = FT_GET_USHORT();
for ( i = 0; i < num_Seg; i++ )
segments[i].idDelta = FT_GET_SHORT();
for ( i = 0; i < num_Seg; i++ )
segments[i].idRangeOffset = FT_GET_USHORT();
FT_FRAME_EXIT();
cmap4->numGlyphId = l = (FT_UShort)(
( ( cmap->length - ( 16L + 8L * num_Seg ) ) & 0xFFFFU ) / 2 );
/* load IDs */
if ( FT_NEW_ARRAY( cmap4->glyphIdArray, l ) ||
FT_FRAME_ENTER( l * 2L ) )
{
FT_FREE( cmap4->segments );
goto Fail;
}
for ( i = 0; i < l; i++ )
cmap4->glyphIdArray[i] = FT_GET_USHORT();
FT_FRAME_EXIT();
cmap4->last_segment = cmap4->segments;
cmap->get_index = code_to_index4;
cmap->get_next_char = code_to_next4;
break;
case 6:
cmap6 = &cmap->c.cmap6;
if ( FT_FRAME_ENTER( 6L ) )
goto Fail;
cmap6->language = FT_GET_USHORT();
cmap6->firstCode = FT_GET_USHORT();
cmap6->entryCount = FT_GET_USHORT();
FT_FRAME_EXIT();
l = cmap6->entryCount;
if ( FT_NEW_ARRAY( cmap6->glyphIdArray, l ) ||
FT_FRAME_ENTER( l * 2L ) )
goto Fail;
for ( i = 0; i < l; i++ )
cmap6->glyphIdArray[i] = FT_GET_USHORT();
FT_FRAME_EXIT();
cmap->get_index = code_to_index6;
cmap->get_next_char = code_to_next6;
break;
case 8:
case 12:
cmap8_12 = &cmap->c.cmap8_12;
if ( FT_FRAME_ENTER( 8L ) )
goto Fail;
cmap->length = FT_GET_ULONG();
cmap8_12->language = FT_GET_ULONG();
FT_FRAME_EXIT();
if ( cmap->format == 8 )
if ( FT_STREAM_SKIP( 8192L ) )
goto Fail;
if ( FT_READ_ULONG( cmap8_12->nGroups ) )
goto Fail;
n = cmap8_12->nGroups;
if ( FT_NEW_ARRAY( cmap8_12->groups, n ) ||
FT_FRAME_ENTER( n * 3 * 4L ) )
goto Fail;
groups = cmap8_12->groups;
for ( j = 0; j < n; j++ )
{
groups[j].startCharCode = FT_GET_ULONG();
groups[j].endCharCode = FT_GET_ULONG();
groups[j].startGlyphID = FT_GET_ULONG();
}
FT_FRAME_EXIT();
cmap8_12->last_group = cmap8_12->groups;
cmap->get_index = code_to_index8_12;
cmap->get_next_char = code_to_next8_12;
break;
case 10:
cmap10 = &cmap->c.cmap10;
if ( FT_FRAME_ENTER( 16L ) )
goto Fail;
cmap->length = FT_GET_ULONG();
cmap10->language = FT_GET_ULONG();
cmap10->startCharCode = FT_GET_ULONG();
cmap10->numChars = FT_GET_ULONG();
FT_FRAME_EXIT();
n = cmap10->numChars;
if ( FT_NEW_ARRAY( cmap10->glyphs, n ) ||
FT_FRAME_ENTER( n * 2L ) )
goto Fail;
for ( j = 0; j < n; j++ )
cmap10->glyphs[j] = FT_GET_USHORT();
FT_FRAME_EXIT();
cmap->get_index = code_to_index10;
cmap->get_next_char = code_to_next10;
break;
default: /* corrupt character mapping table */
return SFNT_Err_Invalid_CharMap_Format;
}
return SFNT_Err_Ok;
Fail:
tt_face_free_charmap( face, cmap );
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* tt_face_free_charmap */
/* */
/* <Description> */
/* Destroys a character mapping table. */
/* */
/* <Input> */
/* face :: A handle to the parent face object. */
/* */
/* cmap :: A handle to a cmap object. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_LOCAL_DEF( FT_Error )
tt_face_free_charmap( TT_Face face,
TT_CMapTable cmap )
{
FT_Memory memory;
if ( !cmap )
return SFNT_Err_Ok;
memory = face->root.driver->root.memory;
switch ( cmap->format )
{
case 0:
FT_FREE( cmap->c.cmap0.glyphIdArray );
break;
case 2:
FT_FREE( cmap->c.cmap2.subHeaderKeys );
FT_FREE( cmap->c.cmap2.subHeaders );
FT_FREE( cmap->c.cmap2.glyphIdArray );
break;
case 4:
FT_FREE( cmap->c.cmap4.segments );
FT_FREE( cmap->c.cmap4.glyphIdArray );
cmap->c.cmap4.segCountX2 = 0;
break;
case 6:
FT_FREE( cmap->c.cmap6.glyphIdArray );
cmap->c.cmap6.entryCount = 0;
break;
case 8:
case 12:
FT_FREE( cmap->c.cmap8_12.groups );
cmap->c.cmap8_12.nGroups = 0;
break;
case 10:
FT_FREE( cmap->c.cmap10.glyphs );
cmap->c.cmap10.numChars = 0;
break;
default:
/* invalid table format, do nothing */
;
}
cmap->loaded = FALSE;
return SFNT_Err_Ok;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index0 */
/* */
/* <Description> */
/* Converts the character code into a glyph index. Uses format 0. */
/* `charCode' must be in the range 0x00-0xFF (otherwise 0 is */
/* returned). */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap0 :: A pointer to a cmap table in format 0. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
/* */
FT_CALLBACK_DEF( FT_UInt )
code_to_index0( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap0 cmap0 = &cmap->c.cmap0;
return ( charCode <= 0xFF ? cmap0->glyphIdArray[charCode] : 0 );
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next0 */
/* */
/* <Description> */
/* Finds the next encoded character after the given one. Uses */
/* format 0. `charCode' must be in the range 0x00-0xFF (otherwise 0 */
/* is returned). */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap0 :: A pointer to a cmap table in format 0. */
/* */
/* <Return> */
/* Next char code. 0 if no higher one is encoded. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next0( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap0 cmap0 = &cmap->c.cmap0;
while ( ++charCode <= 0xFF )
if ( cmap0->glyphIdArray[charCode] )
return ( charCode );
return ( 0 );
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index2 */
/* */
/* <Description> */
/* Converts the character code into a glyph index. Uses format 2. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap2 :: A pointer to a cmap table in format 2. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
/* */
FT_CALLBACK_DEF( FT_UInt )
code_to_index2( TT_CMapTable cmap,
FT_ULong charCode )
{
FT_UInt result, index1, offset;
FT_UInt char_lo;
FT_ULong char_hi;
TT_CMap2SubHeader sh2;
TT_CMap2 cmap2;
cmap2 = &cmap->c.cmap2;
result = 0;
char_lo = (FT_UInt)( charCode & 0xFF );
char_hi = charCode >> 8;
if ( char_hi == 0 )
{
/* an 8-bit character code -- we use the subHeader 0 in this case */
/* to test whether the character code is in the charmap */
index1 = cmap2->subHeaderKeys[char_lo];
if ( index1 != 0 )
return 0;
}
else
{
/* a 16-bit character code */
index1 = cmap2->subHeaderKeys[char_hi & 0xFF];
if ( index1 == 0 )
return 0;
}
sh2 = cmap2->subHeaders + index1;
char_lo -= sh2->firstCode;
if ( char_lo < (FT_UInt)sh2->entryCount )
{
offset = sh2->idRangeOffset / 2 + char_lo;
if ( offset < (FT_UInt)cmap2->numGlyphId )
{
result = cmap2->glyphIdArray[offset];
if ( result )
result = ( result + sh2->idDelta ) & 0xFFFFU;
}
}
return result;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next2 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 2. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap2 :: A pointer to a cmap table in format 2. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next2( TT_CMapTable cmap,
FT_ULong charCode )
{
FT_UInt index1, offset;
FT_UInt char_lo;
FT_ULong char_hi;
TT_CMap2SubHeader sh2;
TT_CMap2 cmap2;
cmap2 = &cmap->c.cmap2;
charCode++;
/*
* This is relatively simplistic -- look for a subHeader containing
* glyphs and then walk to the first glyph in that subHeader.
*/
while ( charCode < 0x10000 )
{
char_lo = (FT_UInt)( charCode & 0xFF );
char_hi = charCode >> 8;
if ( char_hi == 0 )
{
/* an 8-bit character code -- we use the subHeader 0 in this case */
/* to test whether the character code is in the charmap */
index1 = cmap2->subHeaderKeys[char_lo];
if ( index1 != 0 )
{
charCode++;
continue;
}
}
else
{
/* a 16-bit character code */
index1 = cmap2->subHeaderKeys[char_hi & 0xFF];
if ( index1 == 0 )
{
charCode = ( char_hi + 1 ) << 8;
continue;
}
}
sh2 = cmap2->subHeaders + index1;
char_lo -= sh2->firstCode;
if ( char_lo > (FT_UInt)sh2->entryCount )
{
charCode = ( char_hi + 1 ) << 8;
continue;
}
offset = sh2->idRangeOffset / 2 + char_lo;
if ( offset >= (FT_UInt)cmap2->numGlyphId ||
cmap2->glyphIdArray[offset] == 0 )
{
charCode++;
continue;
}
return charCode;
}
return 0;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index4 */
/* */
/* <Description> */
/* Converts the character code into a glyph index. Uses format 4. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap4 :: A pointer to a cmap table in format 4. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
/* */
FT_CALLBACK_DEF( FT_UInt )
code_to_index4( TT_CMapTable cmap,
FT_ULong charCode )
{
FT_UInt result, index1, segCount;
TT_CMap4 cmap4;
TT_CMap4SegmentRec *seg4, *limit;
cmap4 = &cmap->c.cmap4;
result = 0;
segCount = cmap4->segCountX2 / 2;
limit = cmap4->segments + segCount;
/* first, check against the last used segment */
seg4 = cmap4->last_segment;
/* the following is equivalent to performing two tests, as in */
/* */
/* if ( charCode >= seg4->startCount && charCode <= seg4->endCount ) */
/* */
/* This is a bit strange, but it is faster, and the idea behind the */
/* cache is to significantly speed up charcode to glyph index */
/* conversion. */
if ( (FT_ULong)( charCode - seg4->startCount ) <
(FT_ULong)( seg4->endCount - seg4->startCount ) )
goto Found1;
for ( seg4 = cmap4->segments; seg4 < limit; seg4++ )
{
/* the ranges are sorted in increasing order. If we are out of */
/* the range here, the char code isn't in the charmap, so exit. */
if ( charCode > (FT_UInt)seg4->endCount )
continue;
if ( charCode >= (FT_UInt)seg4->startCount )
goto Found;
}
return 0;
Found:
cmap4->last_segment = seg4;
Found1:
/* if the idRangeOffset is 0, we can compute the glyph index */
/* directly */
if ( seg4->idRangeOffset == 0 )
result = ( charCode + seg4->idDelta ) & 0xFFFFU;
else
{
/* otherwise, we must use the glyphIdArray to do it */
index1 = (FT_UInt)( seg4->idRangeOffset / 2
+ ( charCode - seg4->startCount )
+ ( seg4 - cmap4->segments )
- segCount );
if ( index1 < (FT_UInt)cmap4->numGlyphId &&
cmap4->glyphIdArray[index1] != 0 )
result = ( cmap4->glyphIdArray[index1] + seg4->idDelta ) & 0xFFFFU;
}
return result;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next4 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 4. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap :: A pointer to a cmap table in format 4. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next4( TT_CMapTable cmap,
FT_ULong charCode )
{
FT_UInt index1, segCount;
TT_CMap4 cmap4;
TT_CMap4SegmentRec *seg4, *limit;
cmap4 = &cmap->c.cmap4;
segCount = cmap4->segCountX2 / 2;
limit = cmap4->segments + segCount;
charCode++;
for ( seg4 = cmap4->segments; seg4 < limit; seg4++ )
{
/* The ranges are sorted in increasing order. If we are out of */
/* the range here, the char code isn't in the charmap, so exit. */
if ( charCode <= (FT_UInt)seg4->endCount )
goto Found;
}
return 0;
Found:
if ( charCode < (FT_ULong) seg4->startCount )
charCode = seg4->startCount;
/* if the idRangeOffset is 0, all chars in the map exist */
if ( seg4->idRangeOffset == 0 )
return ( charCode );
while ( charCode <= (FT_UInt) seg4->endCount )
{
/* otherwise, we must use the glyphIdArray to do it */
index1 = (FT_UInt)( seg4->idRangeOffset / 2
+ ( charCode - seg4->startCount )
+ ( seg4 - cmap4->segments )
- segCount );
if ( index1 < (FT_UInt)cmap4->numGlyphId &&
cmap4->glyphIdArray[index1] != 0 )
return ( charCode );
charCode++;
}
return 0;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index6 */
/* */
/* <Description> */
/* Converts the character code into a glyph index. Uses format 6. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap6 :: A pointer to a cmap table in format 6. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
/* */
FT_CALLBACK_DEF( FT_UInt )
code_to_index6( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap6 cmap6;
FT_UInt result = 0;
cmap6 = &cmap->c.cmap6;
charCode -= cmap6->firstCode;
if ( charCode < (FT_UInt)cmap6->entryCount )
result = cmap6->glyphIdArray[charCode];
return result;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next6 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 6. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap :: A pointer to a cmap table in format 6. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next6( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap6 cmap6;
charCode++;
cmap6 = &cmap->c.cmap6;
if ( charCode < (FT_ULong) cmap6->firstCode )
charCode = cmap6->firstCode;
charCode -= cmap6->firstCode;
while ( charCode < (FT_UInt)cmap6->entryCount )
{
if ( cmap6->glyphIdArray[charCode] != 0 )
return charCode + cmap6->firstCode;
charCode++;
}
return 0;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index8_12 */
/* */
/* <Description> */
/* Converts the (possibly 32bit) character code into a glyph index. */
/* Uses format 8 or 12. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap8_12 :: A pointer to a cmap table in format 8 or 12. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
/* */
FT_CALLBACK_DEF( FT_UInt )
code_to_index8_12( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap8_12 cmap8_12;
TT_CMapGroupRec *group, *limit;
cmap8_12 = &cmap->c.cmap8_12;
limit = cmap8_12->groups + cmap8_12->nGroups;
/* first, check against the last used group */
group = cmap8_12->last_group;
/* the following is equivalent to performing two tests, as in */
/* */
/* if ( charCode >= group->startCharCode && */
/* charCode <= group->endCharCode ) */
/* */
/* This is a bit strange, but it is faster, and the idea behind the */
/* cache is to significantly speed up charcode to glyph index */
/* conversion. */
if ( (FT_ULong)( charCode - group->startCharCode ) <
(FT_ULong)( group->endCharCode - group->startCharCode ) )
goto Found1;
for ( group = cmap8_12->groups; group < limit; group++ )
{
/* the ranges are sorted in increasing order. If we are out of */
/* the range here, the char code isn't in the charmap, so exit. */
if ( charCode > group->endCharCode )
continue;
if ( charCode >= group->startCharCode )
goto Found;
}
return 0;
Found:
cmap8_12->last_group = group;
Found1:
return group->startGlyphID + (FT_UInt)( charCode - group->startCharCode );
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next8_12 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 8 or 12. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap :: A pointer to a cmap table in format 8 or 12. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next8_12( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap8_12 cmap8_12;
TT_CMapGroupRec *group, *limit;
charCode++;
cmap8_12 = &cmap->c.cmap8_12;
limit = cmap8_12->groups + cmap8_12->nGroups;
for ( group = cmap8_12->groups; group < limit; group++ )
{
/* the ranges are sorted in increasing order. If we are out of */
/* the range here, the char code isn't in the charmap, so exit. */
if ( charCode <= group->endCharCode )
goto Found;
}
return 0;
Found:
if ( charCode < group->startCharCode )
charCode = group->startCharCode;
return charCode;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index10 */
/* */
/* <Description> */
/* Converts the (possibly 32bit) character code into a glyph index. */
/* Uses format 10. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap10 :: A pointer to a cmap table in format 10. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
/* */
FT_CALLBACK_DEF( FT_UInt )
code_to_index10( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap10 cmap10;
FT_UInt result = 0;
cmap10 = &cmap->c.cmap10;
charCode -= cmap10->startCharCode;
/* the overflow trick for comparison works here also since the number */
/* of glyphs (even if numChars is specified as ULong in the specs) in */
/* an OpenType font is limited to 64k */
if ( charCode < cmap10->numChars )
result = cmap10->glyphs[charCode];
return result;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next10 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 10. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* */
/* cmap :: A pointer to a cmap table in format 10. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next10( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap10 cmap10;
charCode++;
cmap10 = &cmap->c.cmap10;
if ( charCode < cmap10->startCharCode )
charCode = cmap10->startCharCode;
charCode -= cmap10->startCharCode;
/* the overflow trick for comparison works here also since the number */
/* of glyphs (even if numChars is specified as ULong in the specs) in */
/* an OpenType font is limited to 64k */
while ( charCode < cmap10->numChars )
{
if ( cmap10->glyphs[charCode] )
return ( charCode + cmap10->startCharCode );
charCode++;
}
return 0;
}
/* END */