ReactOS 0.4.16-dev-2357-g35d0dfe
ftccmap.c
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * ftccmap.c
4 *
5 * FreeType CharMap cache (body)
6 *
7 * Copyright (C) 2000-2020 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 */
17
18
19#include <freetype/freetype.h>
20#include <freetype/ftcache.h>
21#include "ftcmanag.h"
25
26#include "ftccback.h"
27#include "ftcerror.h"
28
29#undef FT_COMPONENT
30#define FT_COMPONENT cache
31
32
33 /**************************************************************************
34 *
35 * Each FTC_CMapNode contains a simple array to map a range of character
36 * codes to equivalent glyph indices.
37 *
38 * For now, the implementation is very basic: Each node maps a range of
39 * 128 consecutive character codes to their corresponding glyph indices.
40 *
41 * We could do more complex things, but I don't think it is really very
42 * useful.
43 *
44 */
45
46
47 /* number of glyph indices / character code per node */
48#define FTC_CMAP_INDICES_MAX 128
49
50 /* compute a query/node hash */
51#define FTC_CMAP_HASH( faceid, index, charcode ) \
52 ( FTC_FACE_ID_HASH( faceid ) + 211 * (index) + \
53 ( (charcode) / FTC_CMAP_INDICES_MAX ) )
54
55 /* the charmap query */
56 typedef struct FTC_CMapQueryRec_
57 {
60 FT_UInt32 char_code;
61
63
64#define FTC_CMAP_QUERY( x ) ((FTC_CMapQuery)(x))
65
66 /* the cmap cache node */
67 typedef struct FTC_CMapNodeRec_
68 {
72 FT_UInt32 first; /* first character in node */
73 FT_UInt16 indices[FTC_CMAP_INDICES_MAX]; /* array of glyph indices */
74
76
77#define FTC_CMAP_NODE( x ) ( (FTC_CMapNode)( x ) )
78
79 /* if (indices[n] == FTC_CMAP_UNKNOWN), we assume that the corresponding */
80 /* glyph indices haven't been queried through FT_Get_Glyph_Index() yet */
81#define FTC_CMAP_UNKNOWN (FT_UInt16)~0
82
83
84 /*************************************************************************/
85 /*************************************************************************/
86 /***** *****/
87 /***** CHARMAP NODES *****/
88 /***** *****/
89 /*************************************************************************/
90 /*************************************************************************/
91
92
93 FT_CALLBACK_DEF( void )
96 {
98 FT_Memory memory = cache->memory;
99
100
101 FT_FREE( node );
102 }
103
104
105 /* initialize a new cmap node */
108 FT_Pointer ftcquery,
110 {
111 FTC_CMapNode *anode = (FTC_CMapNode*)ftcanode;
114 FT_Memory memory = cache->memory;
116 FT_UInt nn;
117
118
119 if ( !FT_NEW( node ) )
120 {
121 node->face_id = query->face_id;
122 node->cmap_index = query->cmap_index;
123 node->first = (query->char_code / FTC_CMAP_INDICES_MAX) *
125
126 for ( nn = 0; nn < FTC_CMAP_INDICES_MAX; nn++ )
127 node->indices[nn] = FTC_CMAP_UNKNOWN;
128 }
129
130 *anode = node;
131 return error;
132 }
133
134
135 /* compute the weight of a given cmap node */
139 {
140 FT_UNUSED( cnode );
141 FT_UNUSED( cache );
142
143 return sizeof ( *cnode );
144 }
145
146
147 /* compare a cmap node to a given query */
150 FT_Pointer ftcquery,
152 FT_Bool* list_changed )
153 {
154 FTC_CMapNode node = (FTC_CMapNode)ftcnode;
156 FT_UNUSED( cache );
157
158
159 if ( list_changed )
160 *list_changed = FALSE;
161 if ( node->face_id == query->face_id &&
162 node->cmap_index == query->cmap_index )
163 {
164 FT_UInt32 offset = (FT_UInt32)( query->char_code - node->first );
165
166
168 }
169
170 return 0;
171 }
172
173
176 FT_Pointer ftcface_id,
178 FT_Bool* list_changed )
179 {
180 FTC_CMapNode node = (FTC_CMapNode)ftcnode;
181 FTC_FaceID face_id = (FTC_FaceID)ftcface_id;
182 FT_UNUSED( cache );
183
184
185 if ( list_changed )
186 *list_changed = FALSE;
187 return FT_BOOL( node->face_id == face_id );
188 }
189
190
191 /*************************************************************************/
192 /*************************************************************************/
193 /***** *****/
194 /***** GLYPH IMAGE CACHE *****/
195 /***** *****/
196 /*************************************************************************/
197 /*************************************************************************/
198
199
200 static
202 {
203 ftc_cmap_node_new, /* FTC_Node_NewFunc node_new */
204 ftc_cmap_node_weight, /* FTC_Node_WeightFunc node_weight */
205 ftc_cmap_node_compare, /* FTC_Node_CompareFunc node_compare */
206 ftc_cmap_node_remove_faceid, /* FTC_Node_CompareFunc node_remove_faceid */
207 ftc_cmap_node_free, /* FTC_Node_FreeFunc node_free */
208
209 sizeof ( FTC_CacheRec ),
210 ftc_cache_init, /* FTC_Cache_InitFunc cache_init */
211 ftc_cache_done, /* FTC_Cache_DoneFunc cache_done */
212 };
213
214
215 /* documentation is in ftcache.h */
216
219 FTC_CMapCache *acache )
220 {
221 return FTC_Manager_RegisterCache( manager,
223 FTC_CACHE_P( acache ) );
224 }
225
226
227 /* documentation is in ftcache.h */
228
231 FTC_FaceID face_id,
232 FT_Int cmap_index,
233 FT_UInt32 char_code )
234 {
235 FTC_Cache cache = FTC_CACHE( cmap_cache );
239 FT_UInt gindex = 0;
241 FT_Int no_cmap_change = 0;
242
243
244 if ( cmap_index < 0 )
245 {
246 /* Treat a negative cmap index as a special value, meaning that you */
247 /* don't want to change the FT_Face's character map through this */
248 /* call. This can be useful if the face requester callback already */
249 /* sets the face's charmap to the appropriate value. */
250
251 no_cmap_change = 1;
252 cmap_index = 0;
253 }
254
255 if ( !cache )
256 {
257 FT_TRACE0(( "FTC_CMapCache_Lookup: bad arguments, returning 0\n" ));
258 return 0;
259 }
260
261 query.face_id = face_id;
262 query.cmap_index = (FT_UInt)cmap_index;
263 query.char_code = char_code;
264
265 hash = FTC_CMAP_HASH( face_id, (FT_UInt)cmap_index, char_code );
266
267#if 1
269 node, error );
270#else
271 error = FTC_Cache_Lookup( cache, hash, &query, &node );
272#endif
273 if ( error )
274 goto Exit;
275
276 FT_ASSERT( (FT_UInt)( char_code - FTC_CMAP_NODE( node )->first ) <
278
279 /* something rotten can happen with rogue clients */
280 if ( (FT_UInt)( char_code - FTC_CMAP_NODE( node )->first >=
282 return 0; /* XXX: should return appropriate error */
283
284 gindex = FTC_CMAP_NODE( node )->indices[char_code -
285 FTC_CMAP_NODE( node )->first];
286 if ( gindex == FTC_CMAP_UNKNOWN )
287 {
289
290
291 gindex = 0;
292
294 FTC_CMAP_NODE( node )->face_id,
295 &face );
296 if ( error )
297 goto Exit;
298
299 if ( (FT_UInt)cmap_index < (FT_UInt)face->num_charmaps )
300 {
301 FT_CharMap old, cmap = NULL;
302
303
304 old = face->charmap;
305 cmap = face->charmaps[cmap_index];
306
307 if ( old != cmap && !no_cmap_change )
308 FT_Set_Charmap( face, cmap );
309
310 gindex = FT_Get_Char_Index( face, char_code );
311
312 if ( old != cmap && !no_cmap_change )
313 FT_Set_Charmap( face, old );
314 }
315
316 FTC_CMAP_NODE( node )->indices[char_code -
317 FTC_CMAP_NODE( node )->first]
318 = (FT_UShort)gindex;
319 }
320
321 Exit:
322 return gindex;
323 }
324
325
326/* END */
#define FT_CALLBACK_DEF(x)
#define FT_EXPORT_DEF(x)
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
WORD face[3]
Definition: mesh.c:4747
FT_Get_Char_Index(FT_Face face, FT_ULong charcode)
Definition: ftobjs.c:3731
FT_Set_Charmap(FT_Face face, FT_CharMap charmap)
Definition: ftobjs.c:3564
FT_BEGIN_HEADER typedef FT_Pointer FTC_FaceID
Definition: ftcache.h:171
FTC_Manager_LookupFace(FTC_Manager manager, FTC_FaceID face_id, FT_Face *aface)
Definition: ftcmanag.c:305
struct FTC_CMapCacheRec_ * FTC_CMapCache
Definition: ftcache.h:573
ftc_cache_init(FTC_Cache cache)
Definition: ftccache.c:334
ftc_cache_done(FTC_Cache cache)
Definition: ftccache.c:388
struct FTC_CacheRec_ FTC_CacheRec
#define FTC_CACHE_P(x)
Definition: ftccache.h:162
#define FTC_CACHE(x)
Definition: ftccache.h:161
#define FTC_CACHE_LOOKUP_CMP(cache, nodecmp, hash, query, node, error)
Definition: ftccache.h:210
FTC_CMapCache_Lookup(FTC_CMapCache cmap_cache, FTC_FaceID face_id, FT_Int cmap_index, FT_UInt32 char_code)
Definition: ftccmap.c:230
struct FTC_CMapQueryRec_ * FTC_CMapQuery
#define FTC_CMAP_UNKNOWN
Definition: ftccmap.c:81
static const FTC_CacheClassRec ftc_cmap_cache_class
Definition: ftccmap.c:201
struct FTC_CMapNodeRec_ * FTC_CMapNode
ftc_cmap_node_free(FTC_Node ftcnode, FTC_Cache cache)
Definition: ftccmap.c:94
ftc_cmap_node_remove_faceid(FTC_Node ftcnode, FT_Pointer ftcface_id, FTC_Cache cache, FT_Bool *list_changed)
Definition: ftccmap.c:175
ftc_cmap_node_compare(FTC_Node ftcnode, FT_Pointer ftcquery, FTC_Cache cache, FT_Bool *list_changed)
Definition: ftccmap.c:149
ftc_cmap_node_new(FTC_Node *ftcanode, FT_Pointer ftcquery, FTC_Cache cache)
Definition: ftccmap.c:107
#define FTC_CMAP_NODE(x)
Definition: ftccmap.c:77
struct FTC_CMapNodeRec_ FTC_CMapNodeRec
#define FTC_CMAP_INDICES_MAX
Definition: ftccmap.c:48
struct FTC_CMapQueryRec_ FTC_CMapQueryRec
FTC_CMapCache_New(FTC_Manager manager, FTC_CMapCache *acache)
Definition: ftccmap.c:218
#define FTC_CMAP_HASH(faceid, index, charcode)
Definition: ftccmap.c:51
ftc_cmap_node_weight(FTC_Node cnode, FTC_Cache cache)
Definition: ftccmap.c:137
FTC_Manager_RegisterCache(FTC_Manager manager, FTC_CacheClass clazz, FTC_Cache *acache)
Definition: ftcmanag.c:575
#define FT_ASSERT(condition)
Definition: ftdebug.h:241
#define FT_TRACE0(varformat)
Definition: ftdebug.h:187
#define FT_NEW(ptr)
Definition: ftmemory.h:339
#define FT_FREE(ptr)
Definition: ftmemory.h:337
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:64
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
int FT_Error
Definition: fttypes.h:299
unsigned short FT_UShort
Definition: fttypes.h:209
unsigned int FT_UInt
Definition: fttypes.h:231
#define FT_BOOL(x)
Definition: fttypes.h:591
size_t FT_Offset
Definition: fttypes.h:323
signed int FT_Int
Definition: fttypes.h:220
GLuint GLuint GLsizei GLenum const GLvoid * indices
Definition: gl.h:1545
GLintptr offset
Definition: glext.h:5920
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
const GLint * first
Definition: glext.h:5794
unsigned short FT_UInt16
Definition: integer-types.h:90
#define error(str)
Definition: mkdosfs.c:1605
static char memory[1024 *256]
Definition: process.c:122
#define FT_UNUSED(arg)
static void Exit(void)
Definition: sock.c:1330
FTC_NodeRec node
Definition: ftccmap.c:69
FT_UInt32 first
Definition: ftccmap.c:72
FT_UInt cmap_index
Definition: ftccmap.c:71
FTC_FaceID face_id
Definition: ftccmap.c:70
FT_UInt cmap_index
Definition: ftccmap.c:59
FT_UInt32 char_code
Definition: ftccmap.c:60
FTC_FaceID face_id
Definition: ftccmap.c:58
Definition: cache.c:49
Definition: _hash_fun.h:40
Definition: dlist.c:348