1 /***************************************************************************/
5 /* Auto-fitter types (specification only). */
7 /* Copyright 2003, 2004, 2005, 2006, 2007, 2008 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 #define xxAF_USE_WARPER /* only define to use warp hinting */
62 #define AF_LOG( x ) do { if ( _af_debug ) printf x; } while ( 0 )
65 extern int _af_debug_disable_horz_hints
;
66 extern int _af_debug_disable_vert_hints
;
67 extern int _af_debug_disable_blue_hints
;
68 extern void* _af_debug_hints
;
72 #define AF_LOG( x ) do ; while ( 0 ) /* nothing */
74 #endif /* !AF_DEBUG */
77 /*************************************************************************/
78 /*************************************************************************/
80 /***** U T I L I T Y S T U F F *****/
82 /*************************************************************************/
83 /*************************************************************************/
85 typedef struct AF_WidthRec_
87 FT_Pos org
; /* original position/width in font units */
88 FT_Pos cur
; /* current/scaled position/width in device sub-pixels */
89 FT_Pos fit
; /* current/fitted position/width in device sub-pixels */
91 } AF_WidthRec
, *AF_Width
;
95 af_sort_pos( FT_UInt count
,
99 af_sort_widths( FT_UInt count
,
103 /*************************************************************************/
104 /*************************************************************************/
106 /***** A N G L E T Y P E S *****/
108 /*************************************************************************/
109 /*************************************************************************/
112 * The auto-fitter doesn't need a very high angular accuracy;
113 * this allows us to speed up some computations considerably with a
114 * light Cordic algorithm (see afangles.c).
117 typedef FT_Int AF_Angle
;
120 #define AF_ANGLE_PI 256
121 #define AF_ANGLE_2PI ( AF_ANGLE_PI * 2 )
122 #define AF_ANGLE_PI2 ( AF_ANGLE_PI / 2 )
123 #define AF_ANGLE_PI4 ( AF_ANGLE_PI / 4 )
128 * compute the angle of a given 2-D vector
131 af_angle_atan( FT_Pos dx
,
136 * compute `angle2 - angle1'; the result is always within
137 * the range [-AF_ANGLE_PI .. AF_ANGLE_PI - 1]
140 af_angle_diff( AF_Angle angle1
,
145 #define AF_ANGLE_DIFF( result, angle1, angle2 ) \
147 AF_Angle _delta = (angle2) - (angle1); \
150 _delta %= AF_ANGLE_2PI; \
152 _delta += AF_ANGLE_2PI; \
154 if ( _delta > AF_ANGLE_PI ) \
155 _delta -= AF_ANGLE_2PI; \
161 /*************************************************************************/
162 /*************************************************************************/
164 /***** O U T L I N E S *****/
166 /*************************************************************************/
167 /*************************************************************************/
169 /* opaque handle to glyph-specific hints -- see `afhints.h' for more
172 typedef struct AF_GlyphHintsRec_
* AF_GlyphHints
;
174 /* This structure is used to model an input glyph outline to
175 * the auto-hinter. The latter will set the `hints' field
176 * depending on the glyph's script.
178 typedef struct AF_OutlineRec_
182 FT_UInt outline_resolution
;
185 FT_UInt metrics_resolution
;
192 /*************************************************************************/
193 /*************************************************************************/
195 /***** S C A L E R S *****/
197 /*************************************************************************/
198 /*************************************************************************/
201 * A scaler models the target pixel device that will receive the
202 * auto-hinted glyph image.
205 typedef enum AF_ScalerFlags_
207 AF_SCALER_FLAG_NO_HORIZONTAL
= 1, /* disable horizontal hinting */
208 AF_SCALER_FLAG_NO_VERTICAL
= 2, /* disable vertical hinting */
209 AF_SCALER_FLAG_NO_ADVANCE
= 4 /* disable advance hinting */
214 typedef struct AF_ScalerRec_
216 FT_Face face
; /* source font face */
217 FT_Fixed x_scale
; /* from font units to 1/64th device pixels */
218 FT_Fixed y_scale
; /* from font units to 1/64th device pixels */
219 FT_Pos x_delta
; /* in 1/64th device pixels */
220 FT_Pos y_delta
; /* in 1/64th device pixels */
221 FT_Render_Mode render_mode
; /* monochrome, anti-aliased, LCD, etc. */
222 FT_UInt32 flags
; /* additional control flags, see above */
224 } AF_ScalerRec
, *AF_Scaler
;
227 #define AF_SCALER_EQUAL_SCALES( a, b ) \
228 ( (a)->x_scale == (b)->x_scale && \
229 (a)->y_scale == (b)->y_scale && \
230 (a)->x_delta == (b)->x_delta && \
231 (a)->y_delta == (b)->y_delta )
234 /*************************************************************************/
235 /*************************************************************************/
237 /***** S C R I P T S *****/
239 /*************************************************************************/
240 /*************************************************************************/
243 * The list of know scripts. Each different script corresponds to the
244 * following information:
246 * - A set of Unicode ranges to test whether the face supports the
249 * - A specific global analyzer that will compute global metrics
250 * specific to the script.
252 * - A specific glyph analyzer that will compute segments and
253 * edges for each glyph covered by the script.
255 * - A specific grid-fitting algorithm that will distort the
256 * scaled glyph outline according to the results of the glyph
259 * Note that a given analyzer and/or grid-fitting algorithm can be
260 * used by more than one script.
263 typedef enum AF_Script_
269 #ifdef FT_OPTION_AUTOFIT2
273 /* add new scripts here. Don't forget to update the list in */
276 AF_SCRIPT_MAX
/* do not remove */
281 typedef struct AF_ScriptClassRec_
const* AF_ScriptClass
;
283 typedef struct AF_ScriptMetricsRec_
285 AF_ScriptClass clazz
;
288 } AF_ScriptMetricsRec
, *AF_ScriptMetrics
;
291 /* This function parses an FT_Face to compute global metrics for
295 (*AF_Script_InitMetricsFunc
)( AF_ScriptMetrics metrics
,
299 (*AF_Script_ScaleMetricsFunc
)( AF_ScriptMetrics metrics
,
303 (*AF_Script_DoneMetricsFunc
)( AF_ScriptMetrics metrics
);
307 (*AF_Script_InitHintsFunc
)( AF_GlyphHints hints
,
308 AF_ScriptMetrics metrics
);
311 (*AF_Script_ApplyHintsFunc
)( AF_GlyphHints hints
,
313 AF_ScriptMetrics metrics
);
316 typedef struct AF_Script_UniRangeRec_
321 } AF_Script_UniRangeRec
;
323 typedef const AF_Script_UniRangeRec
*AF_Script_UniRange
;
326 typedef struct AF_ScriptClassRec_
329 AF_Script_UniRange script_uni_ranges
; /* last must be { 0, 0 } */
331 FT_UInt script_metrics_size
;
332 AF_Script_InitMetricsFunc script_metrics_init
;
333 AF_Script_ScaleMetricsFunc script_metrics_scale
;
334 AF_Script_DoneMetricsFunc script_metrics_done
;
336 AF_Script_InitHintsFunc script_hints_init
;
337 AF_Script_ApplyHintsFunc script_hints_apply
;
346 #endif /* __AFTYPES_H__ */