1 /***************************************************************************/
5 /* Type 1 character map support (body). */
7 /* Copyright 2002, 2003, 2006, 2007, 2012 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 /***************************************************************************/
21 #include FT_INTERNAL_DEBUG_H
26 /*************************************************************************/
27 /*************************************************************************/
29 /***** TYPE1 STANDARD (AND EXPERT) ENCODING CMAPS *****/
31 /*************************************************************************/
32 /*************************************************************************/
35 t1_cmap_std_init( T1_CMapStd cmap,
38 T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
39 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
42 cmap->num_glyphs = face->type1.num_glyphs;
43 cmap->glyph_names = (const char* const*)face->type1.glyph_names;
44 cmap->sid_to_string = psnames->adobe_std_strings;
45 cmap->code_to_sid = is_expert ? psnames->adobe_expert_encoding
46 : psnames->adobe_std_encoding;
48 FT_ASSERT( cmap->code_to_sid != NULL );
52 FT_CALLBACK_DEF( void )
53 t1_cmap_std_done( T1_CMapStd cmap )
56 cmap->glyph_names = NULL;
57 cmap->sid_to_string = NULL;
58 cmap->code_to_sid = NULL;
62 FT_CALLBACK_DEF( FT_UInt )
63 t1_cmap_std_char_index( T1_CMapStd cmap,
69 if ( char_code < 256 )
72 const char* glyph_name;
75 /* convert character code to Adobe SID string */
76 code = cmap->code_to_sid[char_code];
77 glyph_name = cmap->sid_to_string( code );
79 /* look for the corresponding glyph name */
80 for ( n = 0; n < cmap->num_glyphs; n++ )
82 const char* gname = cmap->glyph_names[n];
85 if ( gname && gname[0] == glyph_name[0] &&
86 ft_strcmp( gname, glyph_name ) == 0 )
98 FT_CALLBACK_DEF( FT_UInt32 )
99 t1_cmap_std_char_next( T1_CMapStd cmap,
100 FT_UInt32 *pchar_code )
103 FT_UInt32 char_code = *pchar_code + 1;
106 while ( char_code < 256 )
108 result = t1_cmap_std_char_index( cmap, char_code );
117 *pchar_code = char_code;
122 FT_CALLBACK_DEF( FT_Error )
123 t1_cmap_standard_init( T1_CMapStd cmap,
126 FT_UNUSED( pointer );
129 t1_cmap_std_init( cmap, 0 );
134 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
135 t1_cmap_standard_class_rec =
137 sizeof ( T1_CMapStdRec ),
139 (FT_CMap_InitFunc) t1_cmap_standard_init,
140 (FT_CMap_DoneFunc) t1_cmap_std_done,
141 (FT_CMap_CharIndexFunc)t1_cmap_std_char_index,
142 (FT_CMap_CharNextFunc) t1_cmap_std_char_next,
144 NULL, NULL, NULL, NULL, NULL
148 FT_CALLBACK_DEF( FT_Error )
149 t1_cmap_expert_init( T1_CMapStd cmap,
152 FT_UNUSED( pointer );
155 t1_cmap_std_init( cmap, 1 );
159 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
160 t1_cmap_expert_class_rec =
162 sizeof ( T1_CMapStdRec ),
164 (FT_CMap_InitFunc) t1_cmap_expert_init,
165 (FT_CMap_DoneFunc) t1_cmap_std_done,
166 (FT_CMap_CharIndexFunc)t1_cmap_std_char_index,
167 (FT_CMap_CharNextFunc) t1_cmap_std_char_next,
169 NULL, NULL, NULL, NULL, NULL
173 /*************************************************************************/
174 /*************************************************************************/
176 /***** TYPE1 CUSTOM ENCODING CMAP *****/
178 /*************************************************************************/
179 /*************************************************************************/
182 FT_CALLBACK_DEF( FT_Error )
183 t1_cmap_custom_init( T1_CMapCustom cmap,
186 T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
187 T1_Encoding encoding = &face->type1.encoding;
189 FT_UNUSED( pointer );
192 cmap->first = encoding->code_first;
193 cmap->count = (FT_UInt)( encoding->code_last - cmap->first );
194 cmap->indices = encoding->char_index;
196 FT_ASSERT( cmap->indices != NULL );
197 FT_ASSERT( encoding->code_first <= encoding->code_last );
203 FT_CALLBACK_DEF( void )
204 t1_cmap_custom_done( T1_CMapCustom cmap )
206 cmap->indices = NULL;
212 FT_CALLBACK_DEF( FT_UInt )
213 t1_cmap_custom_char_index( T1_CMapCustom cmap,
214 FT_UInt32 char_code )
219 if ( ( char_code >= cmap->first ) &&
220 ( char_code < ( cmap->first + cmap->count ) ) )
221 result = cmap->indices[char_code];
227 FT_CALLBACK_DEF( FT_UInt32 )
228 t1_cmap_custom_char_next( T1_CMapCustom cmap,
229 FT_UInt32 *pchar_code )
232 FT_UInt32 char_code = *pchar_code;
237 if ( char_code < cmap->first )
238 char_code = cmap->first;
240 for ( ; char_code < ( cmap->first + cmap->count ); char_code++ )
242 result = cmap->indices[char_code];
250 *pchar_code = char_code;
255 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
256 t1_cmap_custom_class_rec =
258 sizeof ( T1_CMapCustomRec ),
260 (FT_CMap_InitFunc) t1_cmap_custom_init,
261 (FT_CMap_DoneFunc) t1_cmap_custom_done,
262 (FT_CMap_CharIndexFunc)t1_cmap_custom_char_index,
263 (FT_CMap_CharNextFunc) t1_cmap_custom_char_next,
265 NULL, NULL, NULL, NULL, NULL
269 /*************************************************************************/
270 /*************************************************************************/
272 /***** TYPE1 SYNTHETIC UNICODE ENCODING CMAP *****/
274 /*************************************************************************/
275 /*************************************************************************/
277 FT_CALLBACK_DEF( const char * )
278 psaux_get_glyph_name( T1_Face face,
281 return face->type1.glyph_names[idx];
285 FT_CALLBACK_DEF( FT_Error )
286 t1_cmap_unicode_init( PS_Unicodes unicodes,
289 T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes );
290 FT_Memory memory = FT_FACE_MEMORY( face );
291 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
293 FT_UNUSED( pointer );
296 return psnames->unicodes_init( memory,
298 face->type1.num_glyphs,
299 (PS_GetGlyphNameFunc)&psaux_get_glyph_name,
300 (PS_FreeGlyphNameFunc)NULL,
305 FT_CALLBACK_DEF( void )
306 t1_cmap_unicode_done( PS_Unicodes unicodes )
308 FT_Face face = FT_CMAP_FACE( unicodes );
309 FT_Memory memory = FT_FACE_MEMORY( face );
312 FT_FREE( unicodes->maps );
313 unicodes->num_maps = 0;
317 FT_CALLBACK_DEF( FT_UInt )
318 t1_cmap_unicode_char_index( PS_Unicodes unicodes,
319 FT_UInt32 char_code )
321 T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes );
322 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
325 return psnames->unicodes_char_index( unicodes, char_code );
329 FT_CALLBACK_DEF( FT_UInt32 )
330 t1_cmap_unicode_char_next( PS_Unicodes unicodes,
331 FT_UInt32 *pchar_code )
333 T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes );
334 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
337 return psnames->unicodes_char_next( unicodes, pchar_code );
341 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
342 t1_cmap_unicode_class_rec =
344 sizeof ( PS_UnicodesRec ),
346 (FT_CMap_InitFunc) t1_cmap_unicode_init,
347 (FT_CMap_DoneFunc) t1_cmap_unicode_done,
348 (FT_CMap_CharIndexFunc)t1_cmap_unicode_char_index,
349 (FT_CMap_CharNextFunc) t1_cmap_unicode_char_next,
351 NULL, NULL, NULL, NULL, NULL