📄 ttcmap.c
字号:
/*************************************************************************/ /* */ /* <Function> */ /* TT_CharMap_Free */ /* */ /* <Description> */ /* Destroys a character mapping table. */ /* */ /* <Input> */ /* face :: A handle to the parent face object. */ /* cmap :: A handle to a cmap object. */ /* */ /* <Return> */ /* Error code. 0 means success. */ /* */ LOCAL_FUNC TT_Error TT_CharMap_Free( TT_Face face, TT_CMapTable* cmap ) { FT_Memory memory; if ( !cmap ) return TT_Err_Ok; memory = face->root.driver->memory; switch ( cmap->format ) { case 0: FREE( cmap->c.cmap0.glyphIdArray ); break; case 2: FREE( cmap->c.cmap2.subHeaderKeys ); FREE( cmap->c.cmap2.subHeaders ); FREE( cmap->c.cmap2.glyphIdArray ); break; case 4: FREE( cmap->c.cmap4.segments ); FREE( cmap->c.cmap4.glyphIdArray ); cmap->c.cmap4.segCountX2 = 0; break; case 6: FREE( cmap->c.cmap6.glyphIdArray ); cmap->c.cmap6.entryCount = 0; break; default: /* invalid table format, do nothing */ ; } cmap->loaded = FALSE; return TT_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. */ /* */ static TT_UInt code_to_index0( TT_CMapTable* cmap, TT_ULong charCode ) { TT_CMap0* cmap0 = &cmap->c.cmap0; return ( charCode <= 0xFF ? cmap0->glyphIdArray[charCode] : 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. */ /* */ static TT_UInt code_to_index2( TT_CMapTable* cmap, TT_ULong charCode ) { TT_UInt result, index1, offset; TT_UInt char_lo; TT_ULong char_hi; TT_CMap2SubHeader* sh2; TT_CMap2* cmap2; cmap2 = &cmap->c.cmap2; result = 0; char_lo = (TT_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 wether the character code is in the charmap */ if ( cmap2->subHeaderKeys[char_lo] == 0 ) { result = cmap2->glyphIdArray[char_lo]; } } else { /* a 16-bit character code */ index1 = cmap2->subHeaderKeys[ char_hi & 0xFF ]; if (index1) { sh2 = cmap2->subHeaders + index1; char_lo -= sh2->firstCode; if (char_lo < sh2->entryCount) { offset = sh2->idRangeOffset/2 + char_lo; if (offset < cmap2->numGlyphId) { result = cmap2->glyphIdArray[offset]; if (result) result = (result + sh2->idDelta) & 0xFFFF; } } } } return result; } /*************************************************************************/ /* */ /* <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. */ /* */ static TT_UInt code_to_index4( TT_CMapTable* cmap, TT_ULong charCode ) { TT_UInt result, index1, segCount; TT_CMap4* cmap4; TT_CMap4Segment *seg4, *limit; cmap4 = &cmap->c.cmap4; result = 0; segCount = cmap4->segCountX2 / 2; seg4 = cmap4->segments; limit = seg4 + segCount; for ( ; seg4 < limit; seg4++, segCount-- ) { if ( charCode <= seg4->endCount ) { /* the ranges are sorted in increasing order, if we're out of */ /* the range here, the char code isn't in the charmap, so exit */ if ( charCode < seg4->startCount ) break; /* when the idRangeOffset is 0, we can compute the glyph index */ /* directly.. */ if ( seg4->idRangeOffset == 0 ) result = (charCode + seg4->idDelta) & 0xFFFF; else /* otherwise, we must use the glyphIdArray to do it */ { index1 = seg4->idRangeOffset/2 + (charCode - seg4->startCount) - segCount; if ( index1 < cmap4->numGlyphId && cmap4->glyphIdArray[index1] != 0 ) { result = (cmap4->glyphIdArray[index1] + seg4->idDelta) & 0xFFFF; } } break; } } return result; } /*************************************************************************/ /* */ /* <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. */ /* */ static TT_UInt code_to_index6( TT_CMapTable* cmap, TT_ULong charCode ) { TT_CMap6* cmap6; TT_UInt result = 0; cmap6 = &cmap->c.cmap6; result = 0; charCode -= cmap6->firstCode; if ( charCode < cmap6->entryCount ) result = cmap6->glyphIdArray[charCode]; return result; }/* END */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -