1 /****************************************************************************
5 * Type 1 character map support (body).
7 * Copyright (C) 2002-2023 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.
21 #include <freetype/internal/ftdebug.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 = (FT_UInt)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 );
52 FT_CALLBACK_DEF( void )
53 t1_cmap_std_done( FT_CMap cmap_ ) /* T1_CMapStd */
55 T1_CMapStd cmap = (T1_CMapStd)cmap_;
59 cmap->glyph_names = NULL;
60 cmap->sid_to_string = NULL;
61 cmap->code_to_sid = NULL;
65 FT_CALLBACK_DEF( FT_UInt )
66 t1_cmap_std_char_index( FT_CMap cmap, /* T1_CMapStd */
69 T1_CMapStd t1cmap = (T1_CMapStd)cmap;
73 if ( char_code < 256 )
76 const char* glyph_name;
79 /* convert character code to Adobe SID string */
80 code = t1cmap->code_to_sid[char_code];
81 glyph_name = t1cmap->sid_to_string( code );
83 /* look for the corresponding glyph name */
84 for ( n = 0; n < t1cmap->num_glyphs; n++ )
86 const char* gname = t1cmap->glyph_names[n];
89 if ( gname && gname[0] == glyph_name[0] &&
90 ft_strcmp( gname, glyph_name ) == 0 )
102 FT_CALLBACK_DEF( FT_UInt )
103 t1_cmap_std_char_next( FT_CMap cmap,
104 FT_UInt32 *pchar_code )
107 FT_UInt32 char_code = *pchar_code + 1;
110 while ( char_code < 256 )
112 result = t1_cmap_std_char_index( cmap, char_code );
121 *pchar_code = char_code;
126 FT_CALLBACK_DEF( FT_Error )
127 t1_cmap_standard_init( FT_CMap cmap, /* T1_CMapStd */
130 T1_CMapStd t1cmap = (T1_CMapStd)cmap;
131 FT_UNUSED( pointer );
134 t1_cmap_std_init( t1cmap, 0 );
139 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
140 t1_cmap_standard_class_rec =
142 sizeof ( T1_CMapStdRec ),
144 (FT_CMap_InitFunc) t1_cmap_standard_init, /* init */
145 (FT_CMap_DoneFunc) t1_cmap_std_done, /* done */
146 (FT_CMap_CharIndexFunc)t1_cmap_std_char_index, /* char_index */
147 (FT_CMap_CharNextFunc) t1_cmap_std_char_next, /* char_next */
149 (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */
150 (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */
151 (FT_CMap_VariantListFunc) NULL, /* variant_list */
152 (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */
153 (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */
157 FT_CALLBACK_DEF( FT_Error )
158 t1_cmap_expert_init( FT_CMap cmap, /* T1_CMapStd */
161 T1_CMapStd t1cmap = (T1_CMapStd)cmap;
162 FT_UNUSED( pointer );
165 t1_cmap_std_init( t1cmap, 1 );
169 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
170 t1_cmap_expert_class_rec =
172 sizeof ( T1_CMapStdRec ),
174 (FT_CMap_InitFunc) t1_cmap_expert_init, /* init */
175 (FT_CMap_DoneFunc) t1_cmap_std_done, /* done */
176 (FT_CMap_CharIndexFunc)t1_cmap_std_char_index, /* char_index */
177 (FT_CMap_CharNextFunc) t1_cmap_std_char_next, /* char_next */
179 (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */
180 (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */
181 (FT_CMap_VariantListFunc) NULL, /* variant_list */
182 (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */
183 (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */
187 /*************************************************************************/
188 /*************************************************************************/
190 /***** TYPE1 CUSTOM ENCODING CMAP *****/
192 /*************************************************************************/
193 /*************************************************************************/
196 FT_CALLBACK_DEF( FT_Error )
197 t1_cmap_custom_init( FT_CMap cmap, /* T1_CMapCustom */
200 T1_CMapCustom t1cmap = (T1_CMapCustom)cmap;
201 T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
202 T1_Encoding encoding = &face->type1.encoding;
204 FT_UNUSED( pointer );
207 t1cmap->first = (FT_UInt)encoding->code_first;
208 t1cmap->count = (FT_UInt)encoding->code_last - t1cmap->first;
209 t1cmap->indices = encoding->char_index;
211 FT_ASSERT( t1cmap->indices );
212 FT_ASSERT( encoding->code_first <= encoding->code_last );
218 FT_CALLBACK_DEF( void )
219 t1_cmap_custom_done( FT_CMap cmap ) /* T1_CMapCustom */
221 T1_CMapCustom t1cmap = (T1_CMapCustom)cmap;
224 t1cmap->indices = NULL;
230 FT_CALLBACK_DEF( FT_UInt )
231 t1_cmap_custom_char_index( FT_CMap cmap, /* T1_CMapCustom */
232 FT_UInt32 char_code )
234 T1_CMapCustom t1cmap = (T1_CMapCustom)cmap;
238 if ( char_code >= t1cmap->first &&
239 char_code < ( t1cmap->first + t1cmap->count ) )
240 result = t1cmap->indices[char_code];
246 FT_CALLBACK_DEF( FT_UInt )
247 t1_cmap_custom_char_next( FT_CMap cmap, /* T1_CMapCustom */
248 FT_UInt32 *pchar_code )
250 T1_CMapCustom t1cmap = (T1_CMapCustom)cmap;
252 FT_UInt32 char_code = *pchar_code;
257 if ( char_code < t1cmap->first )
258 char_code = t1cmap->first;
260 for ( ; char_code < ( t1cmap->first + t1cmap->count ); char_code++ )
262 result = t1cmap->indices[char_code];
270 *pchar_code = char_code;
275 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
276 t1_cmap_custom_class_rec =
278 sizeof ( T1_CMapCustomRec ),
280 (FT_CMap_InitFunc) t1_cmap_custom_init, /* init */
281 (FT_CMap_DoneFunc) t1_cmap_custom_done, /* done */
282 (FT_CMap_CharIndexFunc)t1_cmap_custom_char_index, /* char_index */
283 (FT_CMap_CharNextFunc) t1_cmap_custom_char_next, /* char_next */
285 (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */
286 (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */
287 (FT_CMap_VariantListFunc) NULL, /* variant_list */
288 (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */
289 (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */
293 /*************************************************************************/
294 /*************************************************************************/
296 /***** TYPE1 SYNTHETIC UNICODE ENCODING CMAP *****/
298 /*************************************************************************/
299 /*************************************************************************/
301 FT_CALLBACK_DEF( const char * )
302 psaux_get_glyph_name( void* face_,
305 T1_Face face = (T1_Face)face_;
308 return face->type1.glyph_names[idx];
312 FT_CALLBACK_DEF( FT_Error )
313 t1_cmap_unicode_init( FT_CMap cmap, /* PS_Unicodes */
316 PS_Unicodes unicodes = (PS_Unicodes)cmap;
317 T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
318 FT_Memory memory = FT_FACE_MEMORY( face );
319 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
321 FT_UNUSED( pointer );
324 if ( !psnames->unicodes_init )
325 return FT_THROW( Unimplemented_Feature );
327 return psnames->unicodes_init( memory,
329 (FT_UInt)face->type1.num_glyphs,
330 &psaux_get_glyph_name,
331 (PS_FreeGlyphNameFunc)NULL,
336 FT_CALLBACK_DEF( void )
337 t1_cmap_unicode_done( FT_CMap cmap ) /* PS_Unicodes */
339 PS_Unicodes unicodes = (PS_Unicodes)cmap;
340 FT_Face face = FT_CMAP_FACE( cmap );
341 FT_Memory memory = FT_FACE_MEMORY( face );
344 FT_FREE( unicodes->maps );
345 unicodes->num_maps = 0;
349 FT_CALLBACK_DEF( FT_UInt )
350 t1_cmap_unicode_char_index( FT_CMap cmap, /* PS_Unicodes */
351 FT_UInt32 char_code )
353 PS_Unicodes unicodes = (PS_Unicodes)cmap;
354 T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
355 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
358 return psnames->unicodes_char_index( unicodes, char_code );
362 FT_CALLBACK_DEF( FT_UInt )
363 t1_cmap_unicode_char_next( FT_CMap cmap, /* PS_Unicodes */
364 FT_UInt32 *pchar_code )
366 PS_Unicodes unicodes = (PS_Unicodes)cmap;
367 T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
368 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
371 return psnames->unicodes_char_next( unicodes, pchar_code );
375 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
376 t1_cmap_unicode_class_rec =
378 sizeof ( PS_UnicodesRec ),
380 (FT_CMap_InitFunc) t1_cmap_unicode_init, /* init */
381 (FT_CMap_DoneFunc) t1_cmap_unicode_done, /* done */
382 (FT_CMap_CharIndexFunc)t1_cmap_unicode_char_index, /* char_index */
383 (FT_CMap_CharNextFunc) t1_cmap_unicode_char_next, /* char_next */
385 (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */
386 (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */
387 (FT_CMap_VariantListFunc) NULL, /* variant_list */
388 (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */
389 (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */