Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / freetype2 / src / truetype / ttdriver.c
blobc2cf45298a59fb5f8e3129ba8ee292086229dab8
1 /***************************************************************************/
2 /* */
3 /* ttdriver.c */
4 /* */
5 /* TrueType font driver implementation (body). */
6 /* */
7 /* Copyright 1996-2001, 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 <ft2build.h>
20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_STREAM_H
22 #include FT_INTERNAL_SFNT_H
23 #include FT_TRUETYPE_IDS_H
24 #include FT_SERVICE_XFREE86_NAME_H
26 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
27 #include FT_MULTIPLE_MASTERS_H
28 #include FT_SERVICE_MULTIPLE_MASTERS_H
29 #endif
31 #include FT_SERVICE_TRUETYPE_ENGINE_H
32 #include FT_SERVICE_TRUETYPE_GLYF_H
34 #include "ttdriver.h"
35 #include "ttgload.h"
36 #include "ttpload.h"
38 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
39 #include "ttgxvar.h"
40 #endif
42 #include "tterrors.h"
45 /*************************************************************************/
46 /* */
47 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
48 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
49 /* messages during execution. */
50 /* */
51 #undef FT_COMPONENT
52 #define FT_COMPONENT trace_ttdriver
55 /*************************************************************************/
56 /*************************************************************************/
57 /*************************************************************************/
58 /**** ****/
59 /**** ****/
60 /**** F A C E S ****/
61 /**** ****/
62 /**** ****/
63 /*************************************************************************/
64 /*************************************************************************/
65 /*************************************************************************/
68 #undef PAIR_TAG
69 #define PAIR_TAG( left, right ) ( ( (FT_ULong)left << 16 ) | \
70 (FT_ULong)right )
73 /*************************************************************************/
74 /* */
75 /* <Function> */
76 /* tt_get_kerning */
77 /* */
78 /* <Description> */
79 /* A driver method used to return the kerning vector between two */
80 /* glyphs of the same face. */
81 /* */
82 /* <Input> */
83 /* face :: A handle to the source face object. */
84 /* */
85 /* left_glyph :: The index of the left glyph in the kern pair. */
86 /* */
87 /* right_glyph :: The index of the right glyph in the kern pair. */
88 /* */
89 /* <Output> */
90 /* kerning :: The kerning vector. This is in font units for */
91 /* scalable formats, and in pixels for fixed-sizes */
92 /* formats. */
93 /* */
94 /* <Return> */
95 /* FreeType error code. 0 means success. */
96 /* */
97 /* <Note> */
98 /* Only horizontal layouts (left-to-right & right-to-left) are */
99 /* supported by this function. Other layouts, or more sophisticated */
100 /* kernings, are out of scope of this method (the basic driver */
101 /* interface is meant to be simple). */
102 /* */
103 /* They can be implemented by format-specific interfaces. */
104 /* */
105 static FT_Error
106 tt_get_kerning( FT_Face ttface, /* TT_Face */
107 FT_UInt left_glyph,
108 FT_UInt right_glyph,
109 FT_Vector* kerning )
111 TT_Face face = (TT_Face)ttface;
112 SFNT_Service sfnt = (SFNT_Service)face->sfnt;
115 kerning->x = 0;
116 kerning->y = 0;
118 if ( sfnt )
119 kerning->x = sfnt->get_kerning( face, left_glyph, right_glyph );
121 return 0;
125 #undef PAIR_TAG
128 /*************************************************************************/
129 /*************************************************************************/
130 /*************************************************************************/
131 /**** ****/
132 /**** ****/
133 /**** S I Z E S ****/
134 /**** ****/
135 /**** ****/
136 /*************************************************************************/
137 /*************************************************************************/
138 /*************************************************************************/
141 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
143 static FT_Error
144 tt_size_select( FT_Size size,
145 FT_ULong strike_index )
147 TT_Face ttface = (TT_Face)size->face;
148 TT_Size ttsize = (TT_Size)size;
149 FT_Error error = TT_Err_Ok;
152 ttsize->strike_index = strike_index;
154 if ( FT_IS_SCALABLE( size->face ) )
156 /* use the scaled metrics, even when tt_size_reset fails */
157 FT_Select_Metrics( size->face, strike_index );
159 tt_size_reset( ttsize );
161 else
163 SFNT_Service sfnt = (SFNT_Service) ttface->sfnt;
164 FT_Size_Metrics* metrics = &size->metrics;
167 error = sfnt->load_strike_metrics( ttface, strike_index, metrics );
168 if ( error )
169 ttsize->strike_index = 0xFFFFFFFFUL;
172 return error;
175 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
178 static FT_Error
179 tt_size_request( FT_Size size,
180 FT_Size_Request req )
182 TT_Size ttsize = (TT_Size)size;
183 FT_Error error = TT_Err_Ok;
186 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
188 if ( FT_HAS_FIXED_SIZES( size->face ) )
190 TT_Face ttface = (TT_Face)size->face;
191 SFNT_Service sfnt = (SFNT_Service) ttface->sfnt;
192 FT_ULong strike_index;
195 error = sfnt->set_sbit_strike( ttface, req, &strike_index );
197 if ( error )
198 ttsize->strike_index = 0xFFFFFFFFUL;
199 else
200 return tt_size_select( size, strike_index );
203 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
205 FT_Request_Metrics( size->face, req );
207 if ( FT_IS_SCALABLE( size->face ) )
208 error = tt_size_reset( ttsize );
210 return error;
214 /*************************************************************************/
215 /* */
216 /* <Function> */
217 /* Load_Glyph */
218 /* */
219 /* <Description> */
220 /* A driver method used to load a glyph within a given glyph slot. */
221 /* */
222 /* <Input> */
223 /* slot :: A handle to the target slot object where the glyph */
224 /* will be loaded. */
225 /* */
226 /* size :: A handle to the source face size at which the glyph */
227 /* must be scaled, loaded, etc. */
228 /* */
229 /* glyph_index :: The index of the glyph in the font file. */
230 /* */
231 /* load_flags :: A flag indicating what to load for this glyph. The */
232 /* FTLOAD_??? constants can be used to control the */
233 /* glyph loading process (e.g., whether the outline */
234 /* should be scaled, whether to load bitmaps or not, */
235 /* whether to hint the outline, etc). */
236 /* */
237 /* <Return> */
238 /* FreeType error code. 0 means success. */
239 /* */
240 static FT_Error
241 Load_Glyph( FT_GlyphSlot ttslot, /* TT_GlyphSlot */
242 FT_Size ttsize, /* TT_Size */
243 FT_UInt glyph_index,
244 FT_Int32 load_flags )
246 TT_GlyphSlot slot = (TT_GlyphSlot)ttslot;
247 TT_Size size = (TT_Size)ttsize;
248 FT_Face face = ttslot->face;
249 FT_Error error;
252 if ( !slot )
253 return TT_Err_Invalid_Slot_Handle;
255 if ( !size )
256 return TT_Err_Invalid_Size_Handle;
258 if ( !face || glyph_index >= (FT_UInt)face->num_glyphs )
259 return TT_Err_Invalid_Argument;
261 if ( load_flags & ( FT_LOAD_NO_RECURSE | FT_LOAD_NO_SCALE ) )
263 load_flags |= FT_LOAD_NO_HINTING |
264 FT_LOAD_NO_BITMAP |
265 FT_LOAD_NO_SCALE;
268 /* now load the glyph outline if necessary */
269 error = TT_Load_Glyph( size, slot, glyph_index, load_flags );
271 /* force drop-out mode to 2 - irrelevant now */
272 /* slot->outline.dropout_mode = 2; */
274 return error;
278 /*************************************************************************/
279 /*************************************************************************/
280 /*************************************************************************/
281 /**** ****/
282 /**** ****/
283 /**** D R I V E R I N T E R F A C E ****/
284 /**** ****/
285 /**** ****/
286 /*************************************************************************/
287 /*************************************************************************/
288 /*************************************************************************/
290 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
291 static const FT_Service_MultiMastersRec tt_service_gx_multi_masters =
293 (FT_Get_MM_Func) NULL,
294 (FT_Set_MM_Design_Func) NULL,
295 (FT_Set_MM_Blend_Func) TT_Set_MM_Blend,
296 (FT_Get_MM_Var_Func) TT_Get_MM_Var,
297 (FT_Set_Var_Design_Func)TT_Set_Var_Design
299 #endif
301 static const FT_Service_TrueTypeEngineRec tt_service_truetype_engine =
303 #ifdef TT_USE_BYTECODE_INTERPRETER
305 #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
306 FT_TRUETYPE_ENGINE_TYPE_UNPATENTED
307 #else
308 FT_TRUETYPE_ENGINE_TYPE_PATENTED
309 #endif
311 #else /* !TT_USE_BYTECODE_INTERPRETER */
313 FT_TRUETYPE_ENGINE_TYPE_NONE
315 #endif /* TT_USE_BYTECODE_INTERPRETER */
318 static const FT_Service_TTGlyfRec tt_service_truetype_glyf =
320 (TT_Glyf_GetLocationFunc)tt_face_get_location
323 static const FT_ServiceDescRec tt_services[] =
325 { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE },
326 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
327 { FT_SERVICE_ID_MULTI_MASTERS, &tt_service_gx_multi_masters },
328 #endif
329 { FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine },
330 { FT_SERVICE_ID_TT_GLYF, &tt_service_truetype_glyf },
331 { NULL, NULL }
335 FT_CALLBACK_DEF( FT_Module_Interface )
336 tt_get_interface( FT_Module driver, /* TT_Driver */
337 const char* tt_interface )
339 FT_Module_Interface result;
340 FT_Module sfntd;
341 SFNT_Service sfnt;
344 result = ft_service_list_lookup( tt_services, tt_interface );
345 if ( result != NULL )
346 return result;
348 /* only return the default interface from the SFNT module */
349 sfntd = FT_Get_Module( driver->library, "sfnt" );
350 if ( sfntd )
352 sfnt = (SFNT_Service)( sfntd->clazz->module_interface );
353 if ( sfnt )
354 return sfnt->get_interface( driver, tt_interface );
357 return 0;
361 /* The FT_DriverInterface structure is defined in ftdriver.h. */
363 FT_CALLBACK_TABLE_DEF
364 const FT_Driver_ClassRec tt_driver_class =
367 FT_MODULE_FONT_DRIVER |
368 FT_MODULE_DRIVER_SCALABLE |
369 #ifdef TT_USE_BYTECODE_INTERPRETER
370 FT_MODULE_DRIVER_HAS_HINTER,
371 #else
373 #endif
375 sizeof ( TT_DriverRec ),
377 "truetype", /* driver name */
378 0x10000L, /* driver version == 1.0 */
379 0x20000L, /* driver requires FreeType 2.0 or above */
381 (void*)0, /* driver specific interface */
383 tt_driver_init,
384 tt_driver_done,
385 tt_get_interface,
388 sizeof ( TT_FaceRec ),
389 sizeof ( TT_SizeRec ),
390 sizeof ( FT_GlyphSlotRec ),
392 tt_face_init,
393 tt_face_done,
394 tt_size_init,
395 tt_size_done,
396 tt_slot_init,
397 0, /* FT_Slot_DoneFunc */
399 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
400 ft_stub_set_char_sizes,
401 ft_stub_set_pixel_sizes,
402 #endif
403 Load_Glyph,
405 tt_get_kerning,
406 0, /* FT_Face_AttachFunc */
407 0, /* FT_Face_GetAdvancesFunc */
409 tt_size_request,
410 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
411 tt_size_select
412 #else
413 0 /* FT_Size_SelectFunc */
414 #endif
418 /* END */