1 /***************************************************************************/
5 /* CFF character mapping table (cmap) support (body). */
7 /* Copyright 2002-2007, 2010, 2013 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
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. */
16 /***************************************************************************/
20 #include FT_INTERNAL_DEBUG_H
27 /*************************************************************************/
28 /*************************************************************************/
30 /***** CFF STANDARD (AND EXPERT) ENCODING CMAPS *****/
32 /*************************************************************************/
33 /*************************************************************************/
35 FT_CALLBACK_DEF( FT_Error )
36 cff_cmap_encoding_init( CFF_CMapStd cmap,
39 TT_Face face = (TT_Face)FT_CMAP_FACE( cmap );
40 CFF_Font cff = (CFF_Font)face->extra.data;
41 CFF_Encoding encoding = &cff->encoding;
46 cmap->gids = encoding->codes;
52 FT_CALLBACK_DEF( void )
53 cff_cmap_encoding_done( CFF_CMapStd cmap )
59 FT_CALLBACK_DEF( FT_UInt )
60 cff_cmap_encoding_char_index( CFF_CMapStd cmap,
66 if ( char_code < 256 )
67 result = cmap->gids[char_code];
73 FT_CALLBACK_DEF( FT_UInt32 )
74 cff_cmap_encoding_char_next( CFF_CMapStd cmap,
75 FT_UInt32 *pchar_code )
78 FT_UInt32 char_code = *pchar_code;
83 if ( char_code < 255 )
85 FT_UInt code = (FT_UInt)(char_code + 1);
93 result = cmap->gids[code];
107 FT_DEFINE_CMAP_CLASS(cff_cmap_encoding_class_rec,
108 sizeof ( CFF_CMapStdRec ),
110 (FT_CMap_InitFunc) cff_cmap_encoding_init,
111 (FT_CMap_DoneFunc) cff_cmap_encoding_done,
112 (FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,
113 (FT_CMap_CharNextFunc) cff_cmap_encoding_char_next,
115 NULL, NULL, NULL, NULL, NULL
119 /*************************************************************************/
120 /*************************************************************************/
122 /***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/
124 /*************************************************************************/
125 /*************************************************************************/
127 FT_CALLBACK_DEF( const char* )
128 cff_sid_to_glyph_name( TT_Face face,
131 CFF_Font cff = (CFF_Font)face->extra.data;
132 CFF_Charset charset = &cff->charset;
133 FT_UInt sid = charset->sids[idx];
136 return cff_index_get_sid_string( cff, sid );
140 FT_CALLBACK_DEF( FT_Error )
141 cff_cmap_unicode_init( PS_Unicodes unicodes,
144 TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
145 FT_Memory memory = FT_FACE_MEMORY( face );
146 CFF_Font cff = (CFF_Font)face->extra.data;
147 CFF_Charset charset = &cff->charset;
148 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
150 FT_UNUSED( pointer );
153 /* can't build Unicode map for CID-keyed font */
154 /* because we don't know glyph names. */
155 if ( !charset->sids )
156 return FT_THROW( No_Unicode_Glyph_Name );
158 return psnames->unicodes_init( memory,
161 (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name,
162 (PS_FreeGlyphNameFunc)NULL,
167 FT_CALLBACK_DEF( void )
168 cff_cmap_unicode_done( PS_Unicodes unicodes )
170 FT_Face face = FT_CMAP_FACE( unicodes );
171 FT_Memory memory = FT_FACE_MEMORY( face );
174 FT_FREE( unicodes->maps );
175 unicodes->num_maps = 0;
179 FT_CALLBACK_DEF( FT_UInt )
180 cff_cmap_unicode_char_index( PS_Unicodes unicodes,
181 FT_UInt32 char_code )
183 TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
184 CFF_Font cff = (CFF_Font)face->extra.data;
185 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
188 return psnames->unicodes_char_index( unicodes, char_code );
192 FT_CALLBACK_DEF( FT_UInt32 )
193 cff_cmap_unicode_char_next( PS_Unicodes unicodes,
194 FT_UInt32 *pchar_code )
196 TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
197 CFF_Font cff = (CFF_Font)face->extra.data;
198 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
201 return psnames->unicodes_char_next( unicodes, pchar_code );
205 FT_DEFINE_CMAP_CLASS(cff_cmap_unicode_class_rec,
206 sizeof ( PS_UnicodesRec ),
208 (FT_CMap_InitFunc) cff_cmap_unicode_init,
209 (FT_CMap_DoneFunc) cff_cmap_unicode_done,
210 (FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,
211 (FT_CMap_CharNextFunc) cff_cmap_unicode_char_next,
213 NULL, NULL, NULL, NULL, NULL