1 /***************************************************************************/
5 /* TrueType font driver implementation (body). */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 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 /***************************************************************************/
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
31 #include FT_SERVICE_TRUETYPE_ENGINE_H
32 #include FT_SERVICE_TRUETYPE_GLYF_H
38 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
45 /*************************************************************************/
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. */
52 #define FT_COMPONENT trace_ttdriver
55 /*************************************************************************/
56 /*************************************************************************/
57 /*************************************************************************/
63 /*************************************************************************/
64 /*************************************************************************/
65 /*************************************************************************/
69 #define PAIR_TAG( left, right ) ( ( (FT_ULong)left << 16 ) | \
73 /*************************************************************************/
79 /* A driver method used to return the kerning vector between two */
80 /* glyphs of the same face. */
83 /* face :: A handle to the source face object. */
85 /* left_glyph :: The index of the left glyph in the kern pair. */
87 /* right_glyph :: The index of the right glyph in the kern pair. */
90 /* kerning :: The kerning vector. This is in font units for */
91 /* scalable formats, and in pixels for fixed-sizes */
95 /* FreeType error code. 0 means success. */
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). */
103 /* They can be implemented by format-specific interfaces. */
106 tt_get_kerning( FT_Face ttface
, /* TT_Face */
111 TT_Face face
= (TT_Face
)ttface
;
112 SFNT_Service sfnt
= (SFNT_Service
)face
->sfnt
;
119 kerning
->x
= sfnt
->get_kerning( face
, left_glyph
, right_glyph
);
128 /*************************************************************************/
129 /*************************************************************************/
130 /*************************************************************************/
133 /**** S I Z E S ****/
136 /*************************************************************************/
137 /*************************************************************************/
138 /*************************************************************************/
141 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
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
);
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
);
169 ttsize
->strike_index
= 0xFFFFFFFFUL
;
175 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
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
);
198 ttsize
->strike_index
= 0xFFFFFFFFUL
;
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
);
214 /*************************************************************************/
220 /* A driver method used to load a glyph within a given glyph slot. */
223 /* slot :: A handle to the target slot object where the glyph */
224 /* will be loaded. */
226 /* size :: A handle to the source face size at which the glyph */
227 /* must be scaled, loaded, etc. */
229 /* glyph_index :: The index of the glyph in the font file. */
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). */
238 /* FreeType error code. 0 means success. */
241 Load_Glyph( FT_GlyphSlot ttslot
, /* TT_GlyphSlot */
242 FT_Size ttsize
, /* TT_Size */
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
;
253 return TT_Err_Invalid_Slot_Handle
;
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
|
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; */
278 /*************************************************************************/
279 /*************************************************************************/
280 /*************************************************************************/
283 /**** D R I V E R I N T E R F A C E ****/
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
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
308 FT_TRUETYPE_ENGINE_TYPE_PATENTED
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
},
329 { FT_SERVICE_ID_TRUETYPE_ENGINE
, &tt_service_truetype_engine
},
330 { FT_SERVICE_ID_TT_GLYF
, &tt_service_truetype_glyf
},
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
;
344 result
= ft_service_list_lookup( tt_services
, tt_interface
);
345 if ( result
!= NULL
)
348 /* only return the default interface from the SFNT module */
349 sfntd
= FT_Get_Module( driver
->library
, "sfnt" );
352 sfnt
= (SFNT_Service
)( sfntd
->clazz
->module_interface
);
354 return sfnt
->get_interface( driver
, tt_interface
);
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
,
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 */
388 sizeof ( TT_FaceRec
),
389 sizeof ( TT_SizeRec
),
390 sizeof ( FT_GlyphSlotRec
),
397 0, /* FT_Slot_DoneFunc */
399 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
400 ft_stub_set_char_sizes
,
401 ft_stub_set_pixel_sizes
,
406 0, /* FT_Face_AttachFunc */
407 0, /* FT_Face_GetAdvancesFunc */
410 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
413 0 /* FT_Size_SelectFunc */