1
/***************************************************************************/
5
/* TrueType font driver implementation (body). */
7
/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 */
9
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
11
/* This file is part of the FreeType project, and may only be used, */
12
/* modified, and distributed under the terms of the FreeType project */
13
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14
/* this file you indicate that you have read the license and */
15
/* understand and accept it fully. */
17
/***************************************************************************/
21
#include FT_INTERNAL_DEBUG_H
22
#include FT_INTERNAL_STREAM_H
23
#include FT_INTERNAL_SFNT_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
46
/*************************************************************************/
48
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
49
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
50
/* messages during execution. */
53
#define FT_COMPONENT trace_ttdriver
56
/*************************************************************************/
57
/*************************************************************************/
58
/*************************************************************************/
64
/*************************************************************************/
65
/*************************************************************************/
66
/*************************************************************************/
70
#define PAIR_TAG( left, right ) ( ( (FT_ULong)left << 16 ) | \
74
/*************************************************************************/
80
/* A driver method used to return the kerning vector between two */
81
/* glyphs of the same face. */
84
/* face :: A handle to the source face object. */
86
/* left_glyph :: The index of the left glyph in the kern pair. */
88
/* right_glyph :: The index of the right glyph in the kern pair. */
91
/* kerning :: The kerning vector. This is in font units for */
92
/* scalable formats, and in pixels for fixed-sizes */
96
/* FreeType error code. 0 means success. */
99
/* Only horizontal layouts (left-to-right & right-to-left) are */
100
/* supported by this function. Other layouts, or more sophisticated */
101
/* kernings, are out of scope of this method (the basic driver */
102
/* interface is meant to be simple). */
104
/* They can be implemented by format-specific interfaces. */
107
tt_get_kerning( FT_Face ttface, /* TT_Face */
112
TT_Face face = (TT_Face)ttface;
113
SFNT_Service sfnt = (SFNT_Service)face->sfnt;
120
kerning->x = sfnt->get_kerning( face, left_glyph, right_glyph );
130
tt_get_advances( FT_Face ttface,
137
TT_Face face = (TT_Face) ttface;
138
FT_Bool check = FT_BOOL(
139
!( flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) );
142
/* XXX: TODO: check for sbits */
144
if ( flags & FT_LOAD_VERTICAL_LAYOUT )
146
for ( nn = 0; nn < count; nn++ )
152
TT_Get_VMetrics( face, start + nn, check, &tsb, &ah );
158
for ( nn = 0; nn < count; nn++ )
164
TT_Get_HMetrics( face, start + nn, check, &lsb, &aw );
172
/*************************************************************************/
173
/*************************************************************************/
174
/*************************************************************************/
177
/**** S I Z E S ****/
180
/*************************************************************************/
181
/*************************************************************************/
182
/*************************************************************************/
185
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
188
tt_size_select( FT_Size size,
189
FT_ULong strike_index )
191
TT_Face ttface = (TT_Face)size->face;
192
TT_Size ttsize = (TT_Size)size;
193
FT_Error error = TT_Err_Ok;
196
ttsize->strike_index = strike_index;
198
if ( FT_IS_SCALABLE( size->face ) )
200
/* use the scaled metrics, even when tt_size_reset fails */
201
FT_Select_Metrics( size->face, strike_index );
203
tt_size_reset( ttsize );
207
SFNT_Service sfnt = (SFNT_Service) ttface->sfnt;
208
FT_Size_Metrics* metrics = &size->metrics;
211
error = sfnt->load_strike_metrics( ttface, strike_index, metrics );
213
ttsize->strike_index = 0xFFFFFFFFUL;
219
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
223
tt_size_request( FT_Size size,
224
FT_Size_Request req )
226
TT_Size ttsize = (TT_Size)size;
227
FT_Error error = TT_Err_Ok;
230
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
232
if ( FT_HAS_FIXED_SIZES( size->face ) )
234
TT_Face ttface = (TT_Face)size->face;
235
SFNT_Service sfnt = (SFNT_Service) ttface->sfnt;
236
FT_ULong strike_index;
239
error = sfnt->set_sbit_strike( ttface, req, &strike_index );
242
ttsize->strike_index = 0xFFFFFFFFUL;
244
return tt_size_select( size, strike_index );
247
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
249
FT_Request_Metrics( size->face, req );
251
if ( FT_IS_SCALABLE( size->face ) )
252
error = tt_size_reset( ttsize );
258
/*************************************************************************/
264
/* A driver method used to load a glyph within a given glyph slot. */
267
/* slot :: A handle to the target slot object where the glyph */
268
/* will be loaded. */
270
/* size :: A handle to the source face size at which the glyph */
271
/* must be scaled, loaded, etc. */
273
/* glyph_index :: The index of the glyph in the font file. */
275
/* load_flags :: A flag indicating what to load for this glyph. The */
276
/* FT_LOAD_XXX constants can be used to control the */
277
/* glyph loading process (e.g., whether the outline */
278
/* should be scaled, whether to load bitmaps or not, */
279
/* whether to hint the outline, etc). */
282
/* FreeType error code. 0 means success. */
285
Load_Glyph( FT_GlyphSlot ttslot, /* TT_GlyphSlot */
286
FT_Size ttsize, /* TT_Size */
288
FT_Int32 load_flags )
290
TT_GlyphSlot slot = (TT_GlyphSlot)ttslot;
291
TT_Size size = (TT_Size)ttsize;
292
FT_Face face = ttslot->face;
297
return TT_Err_Invalid_Slot_Handle;
300
return TT_Err_Invalid_Size_Handle;
303
return TT_Err_Invalid_Argument;
305
#ifdef FT_CONFIG_OPTION_INCREMENTAL
306
if ( glyph_index >= (FT_UInt)face->num_glyphs &&
307
!face->internal->incremental_interface )
309
if ( glyph_index >= (FT_UInt)face->num_glyphs )
311
return TT_Err_Invalid_Argument;
313
if ( load_flags & FT_LOAD_NO_HINTING )
315
/* both FT_LOAD_NO_HINTING and FT_LOAD_NO_AUTOHINT */
316
/* are necessary to disable hinting for tricky fonts */
318
if ( FT_IS_TRICKY( face ) )
319
load_flags &= ~FT_LOAD_NO_HINTING;
321
if ( load_flags & FT_LOAD_NO_AUTOHINT )
322
load_flags |= FT_LOAD_NO_HINTING;
325
if ( load_flags & ( FT_LOAD_NO_RECURSE | FT_LOAD_NO_SCALE ) )
327
load_flags |= FT_LOAD_NO_BITMAP | FT_LOAD_NO_SCALE;
329
if ( !FT_IS_TRICKY( face ) )
330
load_flags |= FT_LOAD_NO_HINTING;
333
/* now load the glyph outline if necessary */
334
error = TT_Load_Glyph( size, slot, glyph_index, load_flags );
336
/* force drop-out mode to 2 - irrelevant now */
337
/* slot->outline.dropout_mode = 2; */
343
/*************************************************************************/
344
/*************************************************************************/
345
/*************************************************************************/
348
/**** D R I V E R I N T E R F A C E ****/
351
/*************************************************************************/
352
/*************************************************************************/
353
/*************************************************************************/
355
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
356
FT_DEFINE_SERVICE_MULTIMASTERSREC(tt_service_gx_multi_masters,
357
(FT_Get_MM_Func) NULL,
358
(FT_Set_MM_Design_Func) NULL,
359
(FT_Set_MM_Blend_Func) TT_Set_MM_Blend,
360
(FT_Get_MM_Var_Func) TT_Get_MM_Var,
361
(FT_Set_Var_Design_Func)TT_Set_Var_Design
365
static const FT_Service_TrueTypeEngineRec tt_service_truetype_engine =
367
#ifdef TT_USE_BYTECODE_INTERPRETER
369
#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
370
FT_TRUETYPE_ENGINE_TYPE_UNPATENTED
372
FT_TRUETYPE_ENGINE_TYPE_PATENTED
375
#else /* !TT_USE_BYTECODE_INTERPRETER */
377
FT_TRUETYPE_ENGINE_TYPE_NONE
379
#endif /* TT_USE_BYTECODE_INTERPRETER */
382
FT_DEFINE_SERVICE_TTGLYFREC(tt_service_truetype_glyf,
383
(TT_Glyf_GetLocationFunc)tt_face_get_location
386
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
387
FT_DEFINE_SERVICEDESCREC4(tt_services,
388
FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE,
389
FT_SERVICE_ID_MULTI_MASTERS, &FT_TT_SERVICE_GX_MULTI_MASTERS_GET,
390
FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine,
391
FT_SERVICE_ID_TT_GLYF, &FT_TT_SERVICE_TRUETYPE_GLYF_GET
394
FT_DEFINE_SERVICEDESCREC3(tt_services,
395
FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE,
396
FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine,
397
FT_SERVICE_ID_TT_GLYF, &FT_TT_SERVICE_TRUETYPE_GLYF_GET
401
FT_CALLBACK_DEF( FT_Module_Interface )
402
tt_get_interface( FT_Module driver, /* TT_Driver */
403
const char* tt_interface )
405
FT_Module_Interface result;
409
result = ft_service_list_lookup( FT_TT_SERVICES_GET, tt_interface );
410
if ( result != NULL )
416
/* only return the default interface from the SFNT module */
417
sfntd = FT_Get_Module( driver->library, "sfnt" );
420
sfnt = (SFNT_Service)( sfntd->clazz->module_interface );
422
return sfnt->get_interface( driver, tt_interface );
429
/* The FT_DriverInterface structure is defined in ftdriver.h. */
431
#ifdef TT_USE_BYTECODE_INTERPRETER
432
#define TT_HINTER_FLAG FT_MODULE_DRIVER_HAS_HINTER
434
#define TT_HINTER_FLAG 0
437
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
438
#define TT_SIZE_SELECT tt_size_select
440
#define TT_SIZE_SELECT 0
443
FT_DEFINE_DRIVER(tt_driver_class,
446
FT_MODULE_FONT_DRIVER |
447
FT_MODULE_DRIVER_SCALABLE |
450
sizeof ( TT_DriverRec ),
452
"truetype", /* driver name */
453
0x10000L, /* driver version == 1.0 */
454
0x20000L, /* driver requires FreeType 2.0 or above */
456
(void*)0, /* driver specific interface */
462
sizeof ( TT_FaceRec ),
463
sizeof ( TT_SizeRec ),
464
sizeof ( FT_GlyphSlotRec ),
471
0, /* FT_Slot_DoneFunc */
473
ft_stub_set_char_sizes, /* FT_CONFIG_OPTION_OLD_INTERNALS */
474
ft_stub_set_pixel_sizes, /* FT_CONFIG_OPTION_OLD_INTERNALS */
479
0, /* FT_Face_AttachFunc */