1 /***************************************************************************/
5 /* Auto-fitter hinting routines (specification). */
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 /***************************************************************************/
24 #define xxAF_SORT_SEGMENTS
29 * The definition of outline glyph hints. These are shared by all
30 * script analysis routines (until now).
33 typedef enum AF_Dimension_
35 AF_DIMENSION_HORZ
= 0, /* x coordinates, */
36 /* i.e., vertical segments & edges */
37 AF_DIMENSION_VERT
= 1, /* y coordinates, */
38 /* i.e., horizontal segments & edges */
40 AF_DIMENSION_MAX
/* do not remove */
45 /* hint directions -- the values are computed so that two vectors are */
46 /* in opposite directions iff `dir1 + dir2 == 0' */
47 typedef enum AF_Direction_
58 /* point hint flags */
59 typedef enum AF_Flags_
63 /* point type flags */
64 AF_FLAG_CONIC
= 1 << 0,
65 AF_FLAG_CUBIC
= 1 << 1,
66 AF_FLAG_CONTROL
= AF_FLAG_CONIC
| AF_FLAG_CUBIC
,
68 /* point extremum flags */
69 AF_FLAG_EXTREMA_X
= 1 << 2,
70 AF_FLAG_EXTREMA_Y
= 1 << 3,
72 /* point roundness flags */
73 AF_FLAG_ROUND_X
= 1 << 4,
74 AF_FLAG_ROUND_Y
= 1 << 5,
76 /* point touch flags */
77 AF_FLAG_TOUCH_X
= 1 << 6,
78 AF_FLAG_TOUCH_Y
= 1 << 7,
80 /* candidates for weak interpolation have this flag set */
81 AF_FLAG_WEAK_INTERPOLATION
= 1 << 8,
83 /* all inflection points in the outline have this flag set */
84 AF_FLAG_INFLECTION
= 1 << 9
90 typedef enum AF_Edge_Flags_
93 AF_EDGE_ROUND
= 1 << 0,
94 AF_EDGE_SERIF
= 1 << 1,
100 typedef struct AF_PointRec_
* AF_Point
;
101 typedef struct AF_SegmentRec_
* AF_Segment
;
102 typedef struct AF_EdgeRec_
* AF_Edge
;
105 typedef struct AF_PointRec_
107 FT_UShort flags
; /* point flags used by hinter */
108 FT_Char in_dir
; /* direction of inwards vector */
109 FT_Char out_dir
; /* direction of outwards vector */
111 FT_Pos ox
, oy
; /* original, scaled position */
112 FT_Short fx
, fy
; /* original, unscaled position (font units) */
113 FT_Pos x
, y
; /* current position */
114 FT_Pos u
, v
; /* current (x,y) or (y,x) depending on context */
116 AF_Point next
; /* next point in contour */
117 AF_Point prev
; /* previous point in contour */
122 typedef struct AF_SegmentRec_
124 FT_Byte flags
; /* edge/segment flags for this segment */
125 FT_Char dir
; /* segment direction */
126 FT_Short pos
; /* position of segment */
127 FT_Short min_coord
; /* minimum coordinate of segment */
128 FT_Short max_coord
; /* maximum coordinate of segment */
129 FT_Short height
; /* the hinted segment height */
131 AF_Edge edge
; /* the segment's parent edge */
132 AF_Segment edge_next
; /* link to next segment in parent edge */
134 AF_Segment link
; /* (stem) link segment */
135 AF_Segment serif
; /* primary segment for serifs */
136 FT_Pos num_linked
; /* number of linked segments */
137 FT_Pos score
; /* used during stem matching */
138 FT_Pos len
; /* used during stem matching */
140 AF_Point first
; /* first point in edge segment */
141 AF_Point last
; /* last point in edge segment */
142 AF_Point
* contour
; /* ptr to first point of segment's contour */
147 typedef struct AF_EdgeRec_
149 FT_Short fpos
; /* original, unscaled position (font units) */
150 FT_Pos opos
; /* original, scaled position */
151 FT_Pos pos
; /* current position */
153 FT_Byte flags
; /* edge flags */
154 FT_Char dir
; /* edge direction */
155 FT_Fixed scale
; /* used to speed up interpolation between edges */
156 AF_Width blue_edge
; /* non-NULL if this is a blue edge */
170 typedef struct AF_AxisHintsRec_
175 #ifdef AF_SORT_SEGMENTS
183 AF_Direction major_dir
;
185 } AF_AxisHintsRec
, *AF_AxisHints
;
188 typedef struct AF_GlyphHintsRec_
198 FT_Pos edge_distance_threshold
;
208 AF_AxisHintsRec axis
[AF_DIMENSION_MAX
];
210 FT_UInt32 scaler_flags
; /* copy of scaler flags */
211 FT_UInt32 other_flags
; /* free for script-specific */
212 /* implementations */
213 AF_ScriptMetrics metrics
;
215 FT_Pos xmin_delta
; /* used for warping */
221 #define AF_HINTS_TEST_SCALER( h, f ) ( (h)->scaler_flags & (f) )
222 #define AF_HINTS_TEST_OTHER( h, f ) ( (h)->other_flags & (f) )
227 #define AF_HINTS_DO_HORIZONTAL( h ) \
228 ( !_af_debug_disable_horz_hints && \
229 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_HORIZONTAL ) )
231 #define AF_HINTS_DO_VERTICAL( h ) \
232 ( !_af_debug_disable_vert_hints && \
233 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_VERTICAL ) )
235 #define AF_HINTS_DO_ADVANCE( h ) \
236 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_ADVANCE )
238 #define AF_HINTS_DO_BLUES( h ) ( !_af_debug_disable_blue_hints )
240 #else /* !AF_DEBUG */
242 #define AF_HINTS_DO_HORIZONTAL( h ) \
243 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_HORIZONTAL )
245 #define AF_HINTS_DO_VERTICAL( h ) \
246 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_VERTICAL )
248 #define AF_HINTS_DO_ADVANCE( h ) \
249 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_ADVANCE )
251 #define AF_HINTS_DO_BLUES( h ) 1
253 #endif /* !AF_DEBUG */
256 FT_LOCAL( AF_Direction
)
257 af_direction_compute( FT_Pos dx
,
262 af_axis_hints_new_segment( AF_AxisHints axis
,
264 AF_Segment
*asegment
);
267 af_axis_hints_new_edge( AF_AxisHints axis
,
274 af_glyph_hints_init( AF_GlyphHints hints
,
280 * recompute all AF_Point in a AF_GlyphHints from the definitions
281 * in a source outline
284 af_glyph_hints_rescale( AF_GlyphHints hints
,
285 AF_ScriptMetrics metrics
);
288 af_glyph_hints_reload( AF_GlyphHints hints
,
290 FT_Bool get_inflections
);
293 af_glyph_hints_save( AF_GlyphHints hints
,
294 FT_Outline
* outline
);
297 af_glyph_hints_align_edge_points( AF_GlyphHints hints
,
301 af_glyph_hints_align_strong_points( AF_GlyphHints hints
,
305 af_glyph_hints_align_weak_points( AF_GlyphHints hints
,
310 af_glyph_hints_scale_dim( AF_GlyphHints hints
,
317 af_glyph_hints_done( AF_GlyphHints hints
);
321 #define AF_SEGMENT_LEN( seg ) ( (seg)->max_coord - (seg)->min_coord )
323 #define AF_SEGMENT_DIST( seg1, seg2 ) ( ( (seg1)->pos > (seg2)->pos ) \
324 ? (seg1)->pos - (seg2)->pos \
325 : (seg2)->pos - (seg1)->pos )
330 #endif /* __AFHINTS_H__ */