1 /***************************************************************************/
5 /* Auto-fitter module implementation (body). */
7 /* Copyright 2003-2006, 2009, 2011-2014 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 /***************************************************************************/
25 #ifdef FT_DEBUG_AUTOFIT
26 int _af_debug_disable_horz_hints;
27 int _af_debug_disable_vert_hints;
28 int _af_debug_disable_blue_hints;
29 void* _af_debug_hints;
32 #include FT_INTERNAL_OBJECTS_H
33 #include FT_INTERNAL_DEBUG_H
34 #include FT_AUTOHINTER_H
35 #include FT_SERVICE_PROPERTIES_H
38 /*************************************************************************/
40 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
41 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
42 /* messages during execution. */
45 #define FT_COMPONENT trace_afmodule
49 af_property_get_face_globals( FT_Face face,
50 AF_FaceGlobals* aglobals,
53 FT_Error error = FT_Err_Ok;
54 AF_FaceGlobals globals;
58 return FT_THROW( Invalid_Face_Handle );
60 globals = (AF_FaceGlobals)face->autohint.data;
63 /* trigger computation of the global style data */
64 /* in case it hasn't been done yet */
65 error = af_face_globals_new( face, &globals, module );
70 face->autohint.finalizer =
71 (FT_Generic_Finalizer)af_face_globals_free;
83 af_property_set( FT_Module ft_module,
84 const char* property_name,
87 FT_Error error = FT_Err_Ok;
88 AF_Module module = (AF_Module)ft_module;
91 if ( !ft_strcmp( property_name, "fallback-script" ) )
93 FT_UInt* fallback_script = (FT_UInt*)value;
98 /* We translate the fallback script to a fallback style that uses */
99 /* `fallback-script' as its script and `AF_COVERAGE_NONE' as its */
100 /* coverage value. */
101 for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
103 AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
106 if ( (FT_UInt)style_class->script == *fallback_script &&
107 style_class->coverage == AF_COVERAGE_DEFAULT )
109 module->fallback_style = ss;
114 if ( !AF_STYLE_CLASSES_GET[ss] )
116 FT_TRACE0(( "af_property_set: Invalid value %d for property `%s'\n",
117 fallback_script, property_name ));
118 return FT_THROW( Invalid_Argument );
123 else if ( !ft_strcmp( property_name, "default-script" ) )
125 FT_UInt* default_script = (FT_UInt*)value;
128 module->default_script = *default_script;
132 else if ( !ft_strcmp( property_name, "increase-x-height" ) )
134 FT_Prop_IncreaseXHeight* prop = (FT_Prop_IncreaseXHeight*)value;
135 AF_FaceGlobals globals;
138 error = af_property_get_face_globals( prop->face, &globals, module );
140 globals->increase_x_height = prop->limit;
145 FT_TRACE0(( "af_property_set: missing property `%s'\n",
147 return FT_THROW( Missing_Property );
152 af_property_get( FT_Module ft_module,
153 const char* property_name,
156 FT_Error error = FT_Err_Ok;
157 AF_Module module = (AF_Module)ft_module;
158 FT_UInt fallback_style = module->fallback_style;
159 FT_UInt default_script = module->default_script;
162 if ( !ft_strcmp( property_name, "glyph-to-script-map" ) )
164 FT_Prop_GlyphToScriptMap* prop = (FT_Prop_GlyphToScriptMap*)value;
165 AF_FaceGlobals globals;
168 error = af_property_get_face_globals( prop->face, &globals, module );
170 prop->map = globals->glyph_styles;
174 else if ( !ft_strcmp( property_name, "fallback-script" ) )
176 FT_UInt* val = (FT_UInt*)value;
178 AF_StyleClass style_class = AF_STYLE_CLASSES_GET[fallback_style];
181 *val = style_class->script;
185 else if ( !ft_strcmp( property_name, "default-script" ) )
187 FT_UInt* val = (FT_UInt*)value;
190 *val = default_script;
194 else if ( !ft_strcmp( property_name, "increase-x-height" ) )
196 FT_Prop_IncreaseXHeight* prop = (FT_Prop_IncreaseXHeight*)value;
197 AF_FaceGlobals globals;
200 error = af_property_get_face_globals( prop->face, &globals, module );
202 prop->limit = globals->increase_x_height;
208 FT_TRACE0(( "af_property_get: missing property `%s'\n",
210 return FT_THROW( Missing_Property );
214 FT_DEFINE_SERVICE_PROPERTIESREC(
215 af_service_properties,
216 (FT_Properties_SetFunc)af_property_set,
217 (FT_Properties_GetFunc)af_property_get )
220 FT_DEFINE_SERVICEDESCREC1(
222 FT_SERVICE_ID_PROPERTIES, &AF_SERVICE_PROPERTIES_GET )
225 FT_CALLBACK_DEF( FT_Module_Interface )
226 af_get_interface( FT_Module module,
227 const char* module_interface )
229 /* AF_SERVICES_GET dereferences `library' in PIC mode */
230 #ifdef FT_CONFIG_OPTION_PIC
236 library = module->library;
243 return ft_service_list_lookup( AF_SERVICES_GET, module_interface );
247 FT_CALLBACK_DEF( FT_Error )
248 af_autofitter_init( FT_Module ft_module ) /* AF_Module */
250 AF_Module module = (AF_Module)ft_module;
253 module->fallback_style = AF_STYLE_FALLBACK;
254 module->default_script = AF_SCRIPT_DEFAULT;
256 return af_loader_init( module );
260 FT_CALLBACK_DEF( void )
261 af_autofitter_done( FT_Module ft_module ) /* AF_Module */
263 AF_Module module = (AF_Module)ft_module;
266 af_loader_done( module );
270 FT_CALLBACK_DEF( FT_Error )
271 af_autofitter_load_glyph( AF_Module module,
275 FT_Int32 load_flags )
279 return af_loader_load_glyph( module, slot->face,
280 glyph_index, load_flags );
284 FT_DEFINE_AUTOHINTER_INTERFACE(
285 af_autofitter_interface,
286 NULL, /* reset_face */
287 NULL, /* get_global_hints */
288 NULL, /* done_global_hints */
289 (FT_AutoHinter_GlyphLoadFunc)af_autofitter_load_glyph ) /* load_glyph */
293 autofit_module_class,
296 sizeof ( AF_ModuleRec ),
299 0x10000L, /* version 1.0 of the autofitter */
300 0x20000L, /* requires FreeType 2.0 or above */
302 (const void*)&AF_INTERFACE_GET,
304 (FT_Module_Constructor)af_autofitter_init,
305 (FT_Module_Destructor) af_autofitter_done,
306 (FT_Module_Requester) af_get_interface )