1 /***************************************************************************/
5 /* Auto-fitter types (specification only). */
7 /* Copyright 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 /***************************************************************************/
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 */
61 #include FT_CONFIG_STANDARD_LIBRARY_H
63 #define AF_LOG( x ) do { if ( _af_debug ) printf x; } while ( 0 )
66 extern int _af_debug_disable_horz_hints
;
67 extern int _af_debug_disable_vert_hints
;
68 extern int _af_debug_disable_blue_hints
;
69 extern void* _af_debug_hints
;
73 #define AF_LOG( x ) do { } while ( 0 ) /* nothing */
75 #endif /* !AF_DEBUG */
78 /*************************************************************************/
79 /*************************************************************************/
81 /***** U T I L I T Y S T U F F *****/
83 /*************************************************************************/
84 /*************************************************************************/
86 typedef struct AF_WidthRec_
88 FT_Pos org
; /* original position/width in font units */
89 FT_Pos cur
; /* current/scaled position/width in device sub-pixels */
90 FT_Pos fit
; /* current/fitted position/width in device sub-pixels */
92 } AF_WidthRec
, *AF_Width
;
96 af_sort_pos( FT_UInt count
,
100 af_sort_widths( FT_UInt count
,
104 /*************************************************************************/
105 /*************************************************************************/
107 /***** A N G L E T Y P E S *****/
109 /*************************************************************************/
110 /*************************************************************************/
113 * The auto-fitter doesn't need a very high angular accuracy;
114 * this allows us to speed up some computations considerably with a
115 * light Cordic algorithm (see afangles.c).
118 typedef FT_Int AF_Angle
;
121 #define AF_ANGLE_PI 256
122 #define AF_ANGLE_2PI ( AF_ANGLE_PI * 2 )
123 #define AF_ANGLE_PI2 ( AF_ANGLE_PI / 2 )
124 #define AF_ANGLE_PI4 ( AF_ANGLE_PI / 4 )
129 * compute the angle of a given 2-D vector
132 af_angle_atan( FT_Pos dx
,
137 * compute `angle2 - angle1'; the result is always within
138 * the range [-AF_ANGLE_PI .. AF_ANGLE_PI - 1]
141 af_angle_diff( AF_Angle angle1
,
146 #define AF_ANGLE_DIFF( result, angle1, angle2 ) \
148 AF_Angle _delta = (angle2) - (angle1); \
151 _delta %= AF_ANGLE_2PI; \
153 _delta += AF_ANGLE_2PI; \
155 if ( _delta > AF_ANGLE_PI ) \
156 _delta -= AF_ANGLE_2PI; \
162 /*************************************************************************/
163 /*************************************************************************/
165 /***** O U T L I N E S *****/
167 /*************************************************************************/
168 /*************************************************************************/
170 /* opaque handle to glyph-specific hints -- see `afhints.h' for more
173 typedef struct AF_GlyphHintsRec_
* AF_GlyphHints
;
175 /* This structure is used to model an input glyph outline to
176 * the auto-hinter. The latter will set the `hints' field
177 * depending on the glyph's script.
179 typedef struct AF_OutlineRec_
183 FT_UInt outline_resolution
;
186 FT_UInt metrics_resolution
;
193 /*************************************************************************/
194 /*************************************************************************/
196 /***** S C A L E R S *****/
198 /*************************************************************************/
199 /*************************************************************************/
202 * A scaler models the target pixel device that will receive the
203 * auto-hinted glyph image.
206 typedef enum AF_ScalerFlags_
208 AF_SCALER_FLAG_NO_HORIZONTAL
= 1, /* disable horizontal hinting */
209 AF_SCALER_FLAG_NO_VERTICAL
= 2, /* disable vertical hinting */
210 AF_SCALER_FLAG_NO_ADVANCE
= 4 /* disable advance hinting */
215 typedef struct AF_ScalerRec_
217 FT_Face face
; /* source font face */
218 FT_Fixed x_scale
; /* from font units to 1/64th device pixels */
219 FT_Fixed y_scale
; /* from font units to 1/64th device pixels */
220 FT_Pos x_delta
; /* in 1/64th device pixels */
221 FT_Pos y_delta
; /* in 1/64th device pixels */
222 FT_Render_Mode render_mode
; /* monochrome, anti-aliased, LCD, etc. */
223 FT_UInt32 flags
; /* additional control flags, see above */
225 } AF_ScalerRec
, *AF_Scaler
;
228 #define AF_SCALER_EQUAL_SCALES( a, b ) \
229 ( (a)->x_scale == (b)->x_scale && \
230 (a)->y_scale == (b)->y_scale && \
231 (a)->x_delta == (b)->x_delta && \
232 (a)->y_delta == (b)->y_delta )
235 /*************************************************************************/
236 /*************************************************************************/
238 /***** S C R I P T S *****/
240 /*************************************************************************/
241 /*************************************************************************/
244 * The list of know scripts. Each different script corresponds to the
245 * following information:
247 * - A set of Unicode ranges to test whether the face supports the
250 * - A specific global analyzer that will compute global metrics
251 * specific to the script.
253 * - A specific glyph analyzer that will compute segments and
254 * edges for each glyph covered by the script.
256 * - A specific grid-fitting algorithm that will distort the
257 * scaled glyph outline according to the results of the glyph
260 * Note that a given analyzer and/or grid-fitting algorithm can be
261 * used by more than one script.
264 typedef enum AF_Script_
270 #ifdef FT_OPTION_AUTOFIT2
274 /* add new scripts here. Don't forget to update the list in */
277 AF_SCRIPT_MAX
/* do not remove */
282 typedef struct AF_ScriptClassRec_
const* AF_ScriptClass
;
284 typedef struct AF_ScriptMetricsRec_
286 AF_ScriptClass clazz
;
288 FT_Bool digits_have_same_width
;
290 } AF_ScriptMetricsRec
, *AF_ScriptMetrics
;
293 /* This function parses an FT_Face to compute global metrics for
297 (*AF_Script_InitMetricsFunc
)( AF_ScriptMetrics metrics
,
301 (*AF_Script_ScaleMetricsFunc
)( AF_ScriptMetrics metrics
,
305 (*AF_Script_DoneMetricsFunc
)( AF_ScriptMetrics metrics
);
309 (*AF_Script_InitHintsFunc
)( AF_GlyphHints hints
,
310 AF_ScriptMetrics metrics
);
313 (*AF_Script_ApplyHintsFunc
)( AF_GlyphHints hints
,
315 AF_ScriptMetrics metrics
);
318 typedef struct AF_Script_UniRangeRec_
323 } AF_Script_UniRangeRec
;
325 #define AF_UNIRANGE_REC( a, b ) { (FT_UInt32)(a), (FT_UInt32)(b) }
327 typedef const AF_Script_UniRangeRec
*AF_Script_UniRange
;
330 typedef struct AF_ScriptClassRec_
333 AF_Script_UniRange script_uni_ranges
; /* last must be { 0, 0 } */
335 FT_Offset script_metrics_size
;
336 AF_Script_InitMetricsFunc script_metrics_init
;
337 AF_Script_ScaleMetricsFunc script_metrics_scale
;
338 AF_Script_DoneMetricsFunc script_metrics_done
;
340 AF_Script_InitHintsFunc script_hints_init
;
341 AF_Script_ApplyHintsFunc script_hints_apply
;
345 /* Declare and define vtables for classes */
346 #ifndef FT_CONFIG_OPTION_PIC
348 #define AF_DECLARE_SCRIPT_CLASS(script_class) \
349 FT_CALLBACK_TABLE const AF_ScriptClassRec \
352 #define AF_DEFINE_SCRIPT_CLASS(script_class, script_, ranges, m_size, \
353 m_init, m_scale, m_done, h_init, h_apply) \
354 FT_CALLBACK_TABLE_DEF const AF_ScriptClassRec \
372 #define AF_DECLARE_SCRIPT_CLASS(script_class) \
374 FT_Init_Class_##script_class(AF_ScriptClassRec* ac);
376 #define AF_DEFINE_SCRIPT_CLASS(script_class, script_, ranges, m_size, \
377 m_init, m_scale, m_done, h_init, h_apply) \
379 FT_Init_Class_##script_class(AF_ScriptClassRec* ac) \
381 ac->script = script_; \
382 ac->script_uni_ranges = ranges; \
384 ac->script_metrics_size = m_size; \
386 ac->script_metrics_init = m_init; \
387 ac->script_metrics_scale = m_scale; \
388 ac->script_metrics_done = m_done; \
390 ac->script_hints_init = h_init; \
391 ac->script_hints_apply = h_apply; \
400 #endif /* __AFTYPES_H__ */