1 /***************************************************************************/
5 /* Auto-fitter types (specification only). */
7 /* Copyright 2003-2009, 2011 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 /***************************************************************************/
19 /*************************************************************************
21 * The auto-fitter is a complete rewrite of the old auto-hinter.
22 * Its main feature is the ability to differentiate between different
23 * scripts in order to apply language-specific rules.
25 * The code has also been compartmentized into several entities that
26 * should make algorithmic experimentation easier than with the old
29 * Finally, we get rid of the Catharon license, since this code is
30 * released under the FreeType one.
32 *************************************************************************/
40 #include FT_FREETYPE_H
42 #include FT_INTERNAL_OBJECTS_H
43 #include FT_INTERNAL_DEBUG_H
48 /*************************************************************************/
49 /*************************************************************************/
51 /***** D E B U G G I N G *****/
53 /*************************************************************************/
54 /*************************************************************************/
56 #ifdef FT_DEBUG_AUTOFIT
58 #include FT_CONFIG_STANDARD_LIBRARY_H
60 extern int _af_debug_disable_horz_hints;
61 extern int _af_debug_disable_vert_hints;
62 extern int _af_debug_disable_blue_hints;
63 extern void* _af_debug_hints;
65 #endif /* FT_DEBUG_AUTOFIT */
68 /*************************************************************************/
69 /*************************************************************************/
71 /***** U T I L I T Y S T U F F *****/
73 /*************************************************************************/
74 /*************************************************************************/
76 typedef struct AF_WidthRec_
78 FT_Pos org; /* original position/width in font units */
79 FT_Pos cur; /* current/scaled position/width in device sub-pixels */
80 FT_Pos fit; /* current/fitted position/width in device sub-pixels */
82 } AF_WidthRec, *AF_Width;
86 af_sort_pos( FT_UInt count,
90 af_sort_widths( FT_UInt count,
94 /*************************************************************************/
95 /*************************************************************************/
97 /***** A N G L E T Y P E S *****/
99 /*************************************************************************/
100 /*************************************************************************/
103 * The auto-fitter doesn't need a very high angular accuracy;
104 * this allows us to speed up some computations considerably with a
105 * light Cordic algorithm (see afangles.c).
108 typedef FT_Int AF_Angle;
111 #define AF_ANGLE_PI 256
112 #define AF_ANGLE_2PI ( AF_ANGLE_PI * 2 )
113 #define AF_ANGLE_PI2 ( AF_ANGLE_PI / 2 )
114 #define AF_ANGLE_PI4 ( AF_ANGLE_PI / 4 )
119 * compute the angle of a given 2-D vector
122 af_angle_atan( FT_Pos dx,
127 * compute `angle2 - angle1'; the result is always within
128 * the range [-AF_ANGLE_PI .. AF_ANGLE_PI - 1]
131 af_angle_diff( AF_Angle angle1,
136 #define AF_ANGLE_DIFF( result, angle1, angle2 ) \
138 AF_Angle _delta = (angle2) - (angle1); \
141 _delta %= AF_ANGLE_2PI; \
143 _delta += AF_ANGLE_2PI; \
145 if ( _delta > AF_ANGLE_PI ) \
146 _delta -= AF_ANGLE_2PI; \
152 /* opaque handle to glyph-specific hints -- see `afhints.h' for more
155 typedef struct AF_GlyphHintsRec_* AF_GlyphHints;
158 /*************************************************************************/
159 /*************************************************************************/
161 /***** S C A L E R S *****/
163 /*************************************************************************/
164 /*************************************************************************/
167 * A scaler models the target pixel device that will receive the
168 * auto-hinted glyph image.
171 typedef enum AF_ScalerFlags_
173 AF_SCALER_FLAG_NO_HORIZONTAL = 1, /* disable horizontal hinting */
174 AF_SCALER_FLAG_NO_VERTICAL = 2, /* disable vertical hinting */
175 AF_SCALER_FLAG_NO_ADVANCE = 4 /* disable advance hinting */
180 typedef struct AF_ScalerRec_
182 FT_Face face; /* source font face */
183 FT_Fixed x_scale; /* from font units to 1/64th device pixels */
184 FT_Fixed y_scale; /* from font units to 1/64th device pixels */
185 FT_Pos x_delta; /* in 1/64th device pixels */
186 FT_Pos y_delta; /* in 1/64th device pixels */
187 FT_Render_Mode render_mode; /* monochrome, anti-aliased, LCD, etc. */
188 FT_UInt32 flags; /* additional control flags, see above */
190 } AF_ScalerRec, *AF_Scaler;
193 #define AF_SCALER_EQUAL_SCALES( a, b ) \
194 ( (a)->x_scale == (b)->x_scale && \
195 (a)->y_scale == (b)->y_scale && \
196 (a)->x_delta == (b)->x_delta && \
197 (a)->y_delta == (b)->y_delta )
200 /*************************************************************************/
201 /*************************************************************************/
203 /***** S C R I P T S *****/
205 /*************************************************************************/
206 /*************************************************************************/
209 * The list of known scripts. Each different script corresponds to the
210 * following information:
212 * - A set of Unicode ranges to test whether the face supports the
215 * - A specific global analyzer that will compute global metrics
216 * specific to the script.
218 * - A specific glyph analyzer that will compute segments and
219 * edges for each glyph covered by the script.
221 * - A specific grid-fitting algorithm that will distort the
222 * scaled glyph outline according to the results of the glyph
225 * Note that a given analyzer and/or grid-fitting algorithm can be
226 * used by more than one script.
229 typedef enum AF_Script_
235 #ifdef FT_OPTION_AUTOFIT2
239 /* add new scripts here. Don't forget to update the list in */
242 AF_SCRIPT_MAX /* do not remove */
247 typedef struct AF_ScriptClassRec_ const* AF_ScriptClass;
249 typedef struct AF_ScriptMetricsRec_
251 AF_ScriptClass clazz;
253 FT_Bool digits_have_same_width;
255 } AF_ScriptMetricsRec, *AF_ScriptMetrics;
258 /* This function parses an FT_Face to compute global metrics for
262 (*AF_Script_InitMetricsFunc)( AF_ScriptMetrics metrics,
266 (*AF_Script_ScaleMetricsFunc)( AF_ScriptMetrics metrics,
270 (*AF_Script_DoneMetricsFunc)( AF_ScriptMetrics metrics );
274 (*AF_Script_InitHintsFunc)( AF_GlyphHints hints,
275 AF_ScriptMetrics metrics );
278 (*AF_Script_ApplyHintsFunc)( AF_GlyphHints hints,
280 AF_ScriptMetrics metrics );
283 typedef struct AF_Script_UniRangeRec_
288 } AF_Script_UniRangeRec;
290 #define AF_UNIRANGE_REC( a, b ) { (FT_UInt32)(a), (FT_UInt32)(b) }
292 typedef const AF_Script_UniRangeRec *AF_Script_UniRange;
295 typedef struct AF_ScriptClassRec_
298 AF_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
300 FT_Offset script_metrics_size;
301 AF_Script_InitMetricsFunc script_metrics_init;
302 AF_Script_ScaleMetricsFunc script_metrics_scale;
303 AF_Script_DoneMetricsFunc script_metrics_done;
305 AF_Script_InitHintsFunc script_hints_init;
306 AF_Script_ApplyHintsFunc script_hints_apply;
311 /* Declare and define vtables for classes */
312 #ifndef FT_CONFIG_OPTION_PIC
314 #define AF_DECLARE_SCRIPT_CLASS( script_class ) \
315 FT_CALLBACK_TABLE const AF_ScriptClassRec \
318 #define AF_DEFINE_SCRIPT_CLASS( script_class, script_, ranges, m_size, \
319 m_init, m_scale, m_done, h_init, h_apply ) \
320 FT_CALLBACK_TABLE_DEF const AF_ScriptClassRec \
336 #else /* FT_CONFIG_OPTION_PIC */
338 #define AF_DECLARE_SCRIPT_CLASS( script_class ) \
340 FT_Init_Class_##script_class( AF_ScriptClassRec* ac );
342 #define AF_DEFINE_SCRIPT_CLASS( script_class, script_, ranges, m_size, \
343 m_init, m_scale, m_done, h_init, h_apply ) \
344 FT_LOCAL_DEF( void ) \
345 FT_Init_Class_##script_class( AF_ScriptClassRec* ac ) \
347 ac->script = script_; \
348 ac->script_uni_ranges = ranges; \
350 ac->script_metrics_size = m_size; \
352 ac->script_metrics_init = m_init; \
353 ac->script_metrics_scale = m_scale; \
354 ac->script_metrics_done = m_done; \
356 ac->script_hints_init = h_init; \
357 ac->script_hints_apply = h_apply; \
360 #endif /* FT_CONFIG_OPTION_PIC */
367 #endif /* __AFTYPES_H__ */