1 /***************************************************************************/
5 /* CFF character mapping table (cmap) support (body). */
7 /* Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2010 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 /***************************************************************************/
25 /*************************************************************************/
26 /*************************************************************************/
28 /***** CFF STANDARD (AND EXPERT) ENCODING CMAPS *****/
30 /*************************************************************************/
31 /*************************************************************************/
33 FT_CALLBACK_DEF( FT_Error )
34 cff_cmap_encoding_init( CFF_CMapStd cmap )
36 TT_Face face = (TT_Face)FT_CMAP_FACE( cmap );
37 CFF_Font cff = (CFF_Font)face->extra.data;
38 CFF_Encoding encoding = &cff->encoding;
41 cmap->gids = encoding->codes;
47 FT_CALLBACK_DEF( void )
48 cff_cmap_encoding_done( CFF_CMapStd cmap )
54 FT_CALLBACK_DEF( FT_UInt )
55 cff_cmap_encoding_char_index( CFF_CMapStd cmap,
61 if ( char_code < 256 )
62 result = cmap->gids[char_code];
68 FT_CALLBACK_DEF( FT_UInt32 )
69 cff_cmap_encoding_char_next( CFF_CMapStd cmap,
70 FT_UInt32 *pchar_code )
73 FT_UInt32 char_code = *pchar_code;
78 if ( char_code < 255 )
80 FT_UInt code = (FT_UInt)(char_code + 1);
88 result = cmap->gids[code];
102 FT_DEFINE_CMAP_CLASS(cff_cmap_encoding_class_rec,
103 sizeof ( CFF_CMapStdRec ),
105 (FT_CMap_InitFunc) cff_cmap_encoding_init,
106 (FT_CMap_DoneFunc) cff_cmap_encoding_done,
107 (FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,
108 (FT_CMap_CharNextFunc) cff_cmap_encoding_char_next,
110 NULL, NULL, NULL, NULL, NULL
114 /*************************************************************************/
115 /*************************************************************************/
117 /***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/
119 /*************************************************************************/
120 /*************************************************************************/
122 FT_CALLBACK_DEF( const char* )
123 cff_sid_to_glyph_name( TT_Face face,
126 CFF_Font cff = (CFF_Font)face->extra.data;
127 CFF_Charset charset = &cff->charset;
128 FT_UInt sid = charset->sids[idx];
131 return cff_index_get_sid_string( cff, sid );
135 FT_CALLBACK_DEF( FT_Error )
136 cff_cmap_unicode_init( PS_Unicodes unicodes )
138 TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
139 FT_Memory memory = FT_FACE_MEMORY( face );
140 CFF_Font cff = (CFF_Font)face->extra.data;
141 CFF_Charset charset = &cff->charset;
142 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
145 /* can't build Unicode map for CID-keyed font */
146 /* because we don't know glyph names. */
147 if ( !charset->sids )
148 return CFF_Err_No_Unicode_Glyph_Name;
150 return psnames->unicodes_init( memory,
153 (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name,
154 (PS_FreeGlyphNameFunc)NULL,
159 FT_CALLBACK_DEF( void )
160 cff_cmap_unicode_done( PS_Unicodes unicodes )
162 FT_Face face = FT_CMAP_FACE( unicodes );
163 FT_Memory memory = FT_FACE_MEMORY( face );
166 FT_FREE( unicodes->maps );
167 unicodes->num_maps = 0;
171 FT_CALLBACK_DEF( FT_UInt )
172 cff_cmap_unicode_char_index( PS_Unicodes unicodes,
173 FT_UInt32 char_code )
175 TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
176 CFF_Font cff = (CFF_Font)face->extra.data;
177 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
180 return psnames->unicodes_char_index( unicodes, char_code );
184 FT_CALLBACK_DEF( FT_UInt32 )
185 cff_cmap_unicode_char_next( PS_Unicodes unicodes,
186 FT_UInt32 *pchar_code )
188 TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
189 CFF_Font cff = (CFF_Font)face->extra.data;
190 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
193 return psnames->unicodes_char_next( unicodes, pchar_code );
197 FT_DEFINE_CMAP_CLASS(cff_cmap_unicode_class_rec,
198 sizeof ( PS_UnicodesRec ),
200 (FT_CMap_InitFunc) cff_cmap_unicode_init,
201 (FT_CMap_DoneFunc) cff_cmap_unicode_done,
202 (FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,
203 (FT_CMap_CharNextFunc) cff_cmap_unicode_char_next,
205 NULL, NULL, NULL, NULL, NULL