1 /***************************************************************************/
5 /* TrueType font driver implementation (body). */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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_SERVICE_XFREE86_NAME_H
25 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
26 #include FT_MULTIPLE_MASTERS_H
27 #include FT_SERVICE_MULTIPLE_MASTERS_H
30 #include FT_SERVICE_TRUETYPE_ENGINE_H
31 #include FT_SERVICE_TRUETYPE_GLYF_H
37 #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
);
129 tt_get_advances( FT_Face ttface
,
136 TT_Face face
= (TT_Face
) ttface
;
137 FT_Bool check
= FT_BOOL(
138 !( flags
& FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
) );
141 /* XXX: TODO: check for sbits */
143 if ( flags
& FT_LOAD_VERTICAL_LAYOUT
)
145 for ( nn
= 0; nn
< count
; nn
++ )
151 TT_Get_VMetrics( face
, start
+ nn
, check
, &tsb
, &ah
);
157 for ( nn
= 0; nn
< count
; nn
++ )
163 TT_Get_HMetrics( face
, start
+ nn
, check
, &lsb
, &aw
);
171 /*************************************************************************/
172 /*************************************************************************/
173 /*************************************************************************/
176 /**** S I Z E S ****/
179 /*************************************************************************/
180 /*************************************************************************/
181 /*************************************************************************/
184 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
187 tt_size_select( FT_Size size
,
188 FT_ULong strike_index
)
190 TT_Face ttface
= (TT_Face
)size
->face
;
191 TT_Size ttsize
= (TT_Size
)size
;
192 FT_Error error
= TT_Err_Ok
;
195 ttsize
->strike_index
= strike_index
;
197 if ( FT_IS_SCALABLE( size
->face
) )
199 /* use the scaled metrics, even when tt_size_reset fails */
200 FT_Select_Metrics( size
->face
, strike_index
);
202 tt_size_reset( ttsize
);
206 SFNT_Service sfnt
= (SFNT_Service
) ttface
->sfnt
;
207 FT_Size_Metrics
* metrics
= &size
->metrics
;
210 error
= sfnt
->load_strike_metrics( ttface
, strike_index
, metrics
);
212 ttsize
->strike_index
= 0xFFFFFFFFUL
;
218 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
222 tt_size_request( FT_Size size
,
223 FT_Size_Request req
)
225 TT_Size ttsize
= (TT_Size
)size
;
226 FT_Error error
= TT_Err_Ok
;
229 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
231 if ( FT_HAS_FIXED_SIZES( size
->face
) )
233 TT_Face ttface
= (TT_Face
)size
->face
;
234 SFNT_Service sfnt
= (SFNT_Service
) ttface
->sfnt
;
235 FT_ULong strike_index
;
238 error
= sfnt
->set_sbit_strike( ttface
, req
, &strike_index
);
241 ttsize
->strike_index
= 0xFFFFFFFFUL
;
243 return tt_size_select( size
, strike_index
);
246 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
248 FT_Request_Metrics( size
->face
, req
);
250 if ( FT_IS_SCALABLE( size
->face
) )
251 error
= tt_size_reset( ttsize
);
257 /*************************************************************************/
263 /* A driver method used to load a glyph within a given glyph slot. */
266 /* slot :: A handle to the target slot object where the glyph */
267 /* will be loaded. */
269 /* size :: A handle to the source face size at which the glyph */
270 /* must be scaled, loaded, etc. */
272 /* glyph_index :: The index of the glyph in the font file. */
274 /* load_flags :: A flag indicating what to load for this glyph. The */
275 /* FT_LOAD_XXX constants can be used to control the */
276 /* glyph loading process (e.g., whether the outline */
277 /* should be scaled, whether to load bitmaps or not, */
278 /* whether to hint the outline, etc). */
281 /* FreeType error code. 0 means success. */
284 Load_Glyph( FT_GlyphSlot ttslot
, /* TT_GlyphSlot */
285 FT_Size ttsize
, /* TT_Size */
287 FT_Int32 load_flags
)
289 TT_GlyphSlot slot
= (TT_GlyphSlot
)ttslot
;
290 TT_Size size
= (TT_Size
)ttsize
;
291 FT_Face face
= ttslot
->face
;
296 return TT_Err_Invalid_Slot_Handle
;
299 return TT_Err_Invalid_Size_Handle
;
301 if ( !face
|| glyph_index
>= (FT_UInt
)face
->num_glyphs
)
302 return TT_Err_Invalid_Argument
;
304 if ( load_flags
& FT_LOAD_NO_HINTING
)
306 /* both FT_LOAD_NO_HINTING and FT_LOAD_NO_AUTOHINT */
307 /* are necessary to disable hinting for tricky fonts */
309 if ( FT_IS_TRICKY( face
) )
310 load_flags
&= ~FT_LOAD_NO_HINTING
;
312 if ( load_flags
& FT_LOAD_NO_AUTOHINT
)
313 load_flags
|= FT_LOAD_NO_HINTING
;
316 if ( load_flags
& ( FT_LOAD_NO_RECURSE
| FT_LOAD_NO_SCALE
) )
318 load_flags
|= FT_LOAD_NO_BITMAP
| FT_LOAD_NO_SCALE
;
320 if ( !FT_IS_TRICKY( face
) )
321 load_flags
|= FT_LOAD_NO_HINTING
;
324 /* now load the glyph outline if necessary */
325 error
= TT_Load_Glyph( size
, slot
, glyph_index
, load_flags
);
327 /* force drop-out mode to 2 - irrelevant now */
328 /* slot->outline.dropout_mode = 2; */
334 /*************************************************************************/
335 /*************************************************************************/
336 /*************************************************************************/
339 /**** D R I V E R I N T E R F A C E ****/
342 /*************************************************************************/
343 /*************************************************************************/
344 /*************************************************************************/
346 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
347 FT_DEFINE_SERVICE_MULTIMASTERSREC(tt_service_gx_multi_masters
,
348 (FT_Get_MM_Func
) NULL
,
349 (FT_Set_MM_Design_Func
) NULL
,
350 (FT_Set_MM_Blend_Func
) TT_Set_MM_Blend
,
351 (FT_Get_MM_Var_Func
) TT_Get_MM_Var
,
352 (FT_Set_Var_Design_Func
)TT_Set_Var_Design
356 static const FT_Service_TrueTypeEngineRec tt_service_truetype_engine
=
358 #ifdef TT_USE_BYTECODE_INTERPRETER
360 #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
361 FT_TRUETYPE_ENGINE_TYPE_UNPATENTED
363 FT_TRUETYPE_ENGINE_TYPE_PATENTED
366 #else /* !TT_USE_BYTECODE_INTERPRETER */
368 FT_TRUETYPE_ENGINE_TYPE_NONE
370 #endif /* TT_USE_BYTECODE_INTERPRETER */
373 FT_DEFINE_SERVICE_TTGLYFREC(tt_service_truetype_glyf
,
374 (TT_Glyf_GetLocationFunc
)tt_face_get_location
377 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
378 FT_DEFINE_SERVICEDESCREC4(tt_services
,
379 FT_SERVICE_ID_XF86_NAME
, FT_XF86_FORMAT_TRUETYPE
,
380 FT_SERVICE_ID_MULTI_MASTERS
, &FT_TT_SERVICE_GX_MULTI_MASTERS_GET
,
381 FT_SERVICE_ID_TRUETYPE_ENGINE
, &tt_service_truetype_engine
,
382 FT_SERVICE_ID_TT_GLYF
, &FT_TT_SERVICE_TRUETYPE_GLYF_GET
385 FT_DEFINE_SERVICEDESCREC3(tt_services
,
386 FT_SERVICE_ID_XF86_NAME
, FT_XF86_FORMAT_TRUETYPE
,
387 FT_SERVICE_ID_TRUETYPE_ENGINE
, &tt_service_truetype_engine
,
388 FT_SERVICE_ID_TT_GLYF
, &FT_TT_SERVICE_TRUETYPE_GLYF_GET
392 FT_CALLBACK_DEF( FT_Module_Interface
)
393 tt_get_interface( FT_Module driver
, /* TT_Driver */
394 const char* tt_interface
)
396 FT_Library library
= driver
->library
;
397 FT_Module_Interface result
;
402 result
= ft_service_list_lookup( FT_TT_SERVICES_GET
, tt_interface
);
403 if ( result
!= NULL
)
406 /* only return the default interface from the SFNT module */
407 sfntd
= FT_Get_Module( driver
->library
, "sfnt" );
410 sfnt
= (SFNT_Service
)( sfntd
->clazz
->module_interface
);
412 return sfnt
->get_interface( driver
, tt_interface
);
419 /* The FT_DriverInterface structure is defined in ftdriver.h. */
421 #ifdef TT_USE_BYTECODE_INTERPRETER
422 #define TT_HINTER_FLAG FT_MODULE_DRIVER_HAS_HINTER
424 #define TT_HINTER_FLAG 0
427 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
428 #define TT_SIZE_SELECT tt_size_select
430 #define TT_SIZE_SELECT 0
433 FT_DEFINE_DRIVER(tt_driver_class
,
436 FT_MODULE_FONT_DRIVER
|
437 FT_MODULE_DRIVER_SCALABLE
|
440 sizeof ( TT_DriverRec
),
442 "truetype", /* driver name */
443 0x10000L
, /* driver version == 1.0 */
444 0x20000L
, /* driver requires FreeType 2.0 or above */
446 (void*)0, /* driver specific interface */
452 sizeof ( TT_FaceRec
),
453 sizeof ( TT_SizeRec
),
454 sizeof ( FT_GlyphSlotRec
),
461 0, /* FT_Slot_DoneFunc */
463 ft_stub_set_char_sizes
, /* FT_CONFIG_OPTION_OLD_INTERNALS */
464 ft_stub_set_pixel_sizes
, /* FT_CONFIG_OPTION_OLD_INTERNALS */
469 0, /* FT_Face_AttachFunc */