Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / freetype2 / src / cff / cffcmap.c
blob578d048bedd941e325b92f61413d158816f460ee
1 /***************************************************************************/
2 /* */
3 /* cffcmap.c */
4 /* */
5 /* CFF character mapping table (cmap) support (body). */
6 /* */
7 /* Copyright 2002, 2003, 2004, 2005, 2006, 2007 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
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. */
15 /* */
16 /***************************************************************************/
19 #include "cffcmap.h"
20 #include "cffload.h"
22 #include "cfferrs.h"
25 /*************************************************************************/
26 /*************************************************************************/
27 /***** *****/
28 /***** CFF STANDARD (AND EXPERT) ENCODING CMAPS *****/
29 /***** *****/
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;
43 return 0;
47 FT_CALLBACK_DEF( void )
48 cff_cmap_encoding_done( CFF_CMapStd cmap )
50 cmap->gids = NULL;
54 FT_CALLBACK_DEF( FT_UInt )
55 cff_cmap_encoding_char_index( CFF_CMapStd cmap,
56 FT_UInt32 char_code )
58 FT_UInt result = 0;
61 if ( char_code < 256 )
62 result = cmap->gids[char_code];
64 return result;
68 FT_CALLBACK_DEF( FT_UInt )
69 cff_cmap_encoding_char_next( CFF_CMapStd cmap,
70 FT_UInt32 *pchar_code )
72 FT_UInt result = 0;
73 FT_UInt32 char_code = *pchar_code;
76 *pchar_code = 0;
78 if ( char_code < 255 )
80 FT_UInt code = (FT_UInt)(char_code + 1);
83 for (;;)
85 if ( code >= 256 )
86 break;
88 result = cmap->gids[code];
89 if ( result != 0 )
91 *pchar_code = code;
92 break;
95 code++;
98 return result;
102 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
103 cff_cmap_encoding_class_rec =
105 sizeof ( CFF_CMapStdRec ),
107 (FT_CMap_InitFunc) cff_cmap_encoding_init,
108 (FT_CMap_DoneFunc) cff_cmap_encoding_done,
109 (FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,
110 (FT_CMap_CharNextFunc) cff_cmap_encoding_char_next,
112 NULL, NULL, NULL, NULL, NULL
116 /*************************************************************************/
117 /*************************************************************************/
118 /***** *****/
119 /***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/
120 /***** *****/
121 /*************************************************************************/
122 /*************************************************************************/
124 FT_CALLBACK_DEF( const char* )
125 cff_sid_to_glyph_name( TT_Face face,
126 FT_UInt idx )
128 CFF_Font cff = (CFF_Font)face->extra.data;
129 CFF_Charset charset = &cff->charset;
130 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
131 FT_UInt sid = charset->sids[idx];
134 return cff_index_get_sid_string( &cff->string_index, sid, psnames );
138 FT_CALLBACK_DEF( void )
139 cff_sid_free_glyph_name( TT_Face face,
140 const char* gname )
142 FT_Memory memory = FT_FACE_MEMORY( face );
145 FT_FREE( gname );
149 FT_CALLBACK_DEF( FT_Error )
150 cff_cmap_unicode_init( PS_Unicodes unicodes )
152 TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
153 FT_Memory memory = FT_FACE_MEMORY( face );
154 CFF_Font cff = (CFF_Font)face->extra.data;
155 CFF_Charset charset = &cff->charset;
156 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
159 /* can't build Unicode map for CID-keyed font */
160 if ( !charset->sids )
161 return CFF_Err_Invalid_Argument;
163 return psnames->unicodes_init( memory,
164 unicodes,
165 cff->num_glyphs,
166 (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name,
167 (PS_FreeGlyphNameFunc)&cff_sid_free_glyph_name,
168 (FT_Pointer)face );
172 FT_CALLBACK_DEF( void )
173 cff_cmap_unicode_done( PS_Unicodes unicodes )
175 FT_Face face = FT_CMAP_FACE( unicodes );
176 FT_Memory memory = FT_FACE_MEMORY( face );
179 FT_FREE( unicodes->maps );
180 unicodes->num_maps = 0;
184 FT_CALLBACK_DEF( FT_UInt )
185 cff_cmap_unicode_char_index( PS_Unicodes unicodes,
186 FT_UInt32 char_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_index( unicodes, char_code );
197 FT_CALLBACK_DEF( FT_UInt )
198 cff_cmap_unicode_char_next( PS_Unicodes unicodes,
199 FT_UInt32 *pchar_code )
201 TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
202 CFF_Font cff = (CFF_Font)face->extra.data;
203 FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
206 return psnames->unicodes_char_next( unicodes, pchar_code );
210 FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
211 cff_cmap_unicode_class_rec =
213 sizeof ( PS_UnicodesRec ),
215 (FT_CMap_InitFunc) cff_cmap_unicode_init,
216 (FT_CMap_DoneFunc) cff_cmap_unicode_done,
217 (FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,
218 (FT_CMap_CharNextFunc) cff_cmap_unicode_char_next,
220 NULL, NULL, NULL, NULL, NULL
224 /* END */