📄 ttcmap.c
字号:
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 < 0x10000L ) { 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -