1 /***************************************************************************/
5 /* Auto-fitter hinting routines (specification). */
7 /* Copyright 2003, 2004, 2005, 2006 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 /***************************************************************************/
28 * The definition of outline glyph hints. These are shared by all
29 * script analysis routines (until now).
34 AF_DIMENSION_HORZ
= 0, /* x coordinates, */
35 /* i.e., vertical segments & edges */
36 AF_DIMENSION_VERT
= 1, /* y coordinates, */
37 /* i.e., horizontal segments & edges */
39 AF_DIMENSION_MAX
/* do not remove */
44 /* hint directions -- the values are computed so that two vectors are */
45 /* in opposite directions iff `dir1 + dir2 == 0' */
57 /* point hint flags */
62 /* point type flags */
63 AF_FLAG_CONIC
= 1 << 0,
64 AF_FLAG_CUBIC
= 1 << 1,
65 AF_FLAG_CONTROL
= AF_FLAG_CONIC
| AF_FLAG_CUBIC
,
67 /* point extremum flags */
68 AF_FLAG_EXTREMA_X
= 1 << 2,
69 AF_FLAG_EXTREMA_Y
= 1 << 3,
71 /* point roundness flags */
72 AF_FLAG_ROUND_X
= 1 << 4,
73 AF_FLAG_ROUND_Y
= 1 << 5,
75 /* point touch flags */
76 AF_FLAG_TOUCH_X
= 1 << 6,
77 AF_FLAG_TOUCH_Y
= 1 << 7,
79 /* candidates for weak interpolation have this flag set */
80 AF_FLAG_WEAK_INTERPOLATION
= 1 << 8,
82 /* all inflection points in the outline have this flag set */
83 AF_FLAG_INFLECTION
= 1 << 9
92 AF_EDGE_ROUND
= 1 << 0,
93 AF_EDGE_SERIF
= 1 << 1,
99 typedef struct AF_PointRec_
* AF_Point
;
100 typedef struct AF_SegmentRec_
* AF_Segment
;
101 typedef struct AF_EdgeRec_
* AF_Edge
;
104 typedef struct AF_PointRec_
106 FT_UShort flags
; /* point flags used by hinter */
107 FT_Char in_dir
; /* direction of inwards vector */
108 FT_Char out_dir
; /* direction of outwards vector */
110 FT_Pos ox
, oy
; /* original, scaled position */
111 FT_Short fx
, fy
; /* original, unscaled position (font units) */
112 FT_Pos x
, y
; /* current position */
113 FT_Pos u
, v
; /* current (x,y) or (y,x) depending on context */
115 AF_Point next
; /* next point in contour */
116 AF_Point prev
; /* previous point in contour */
121 typedef struct AF_SegmentRec_
123 FT_Byte flags
; /* edge/segment flags for this segment */
124 FT_Char dir
; /* segment direction */
125 FT_Short pos
; /* position of segment */
126 FT_Short min_coord
; /* minimum coordinate of segment */
127 FT_Short max_coord
; /* maximum coordinate of segment */
128 FT_Short height
; /* the hinted segment height */
130 AF_Edge edge
; /* the segment's parent edge */
131 AF_Segment edge_next
; /* link to next segment in parent edge */
133 AF_Segment link
; /* (stem) link segment */
134 AF_Segment serif
; /* primary segment for serifs */
135 FT_Pos num_linked
; /* number of linked segments */
136 FT_Pos score
; /* used during stem matching */
137 FT_Pos len
; /* used during stem matching */
139 AF_Point first
; /* first point in edge segment */
140 AF_Point last
; /* last point in edge segment */
141 AF_Point
* contour
; /* ptr to first point of segment's contour */
146 typedef struct AF_EdgeRec_
148 FT_Short fpos
; /* original, unscaled position (font units) */
149 FT_Pos opos
; /* original, scaled position */
150 FT_Pos pos
; /* current position */
152 FT_Byte flags
; /* edge flags */
153 FT_Char dir
; /* edge direction */
154 FT_Fixed scale
; /* used to speed up interpolation between edges */
155 AF_Width blue_edge
; /* non-NULL if this is a blue edge */
169 typedef struct AF_AxisHintsRec_
179 AF_Direction major_dir
;
181 } AF_AxisHintsRec
, *AF_AxisHints
;
184 typedef struct AF_GlyphHintsRec_
194 FT_Pos edge_distance_threshold
;
204 AF_AxisHintsRec axis
[AF_DIMENSION_MAX
];
206 FT_UInt32 scaler_flags
; /* copy of scaler flags */
207 FT_UInt32 other_flags
; /* free for script-specific */
208 /* implementations */
209 AF_ScriptMetrics metrics
;
214 #define AF_HINTS_TEST_SCALER( h, f ) ( (h)->scaler_flags & (f) )
215 #define AF_HINTS_TEST_OTHER( h, f ) ( (h)->other_flags & (f) )
220 #define AF_HINTS_DO_HORIZONTAL( h ) \
221 ( !_af_debug_disable_horz_hints && \
222 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_HORIZONTAL ) )
224 #define AF_HINTS_DO_VERTICAL( h ) \
225 ( !_af_debug_disable_vert_hints && \
226 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_VERTICAL ) )
228 #define AF_HINTS_DO_ADVANCE( h ) \
229 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_ADVANCE )
231 #define AF_HINTS_DO_BLUES( h ) ( !_af_debug_disable_blue_hints )
233 #else /* !AF_DEBUG */
235 #define AF_HINTS_DO_HORIZONTAL( h ) \
236 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_HORIZONTAL )
238 #define AF_HINTS_DO_VERTICAL( h ) \
239 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_VERTICAL )
241 #define AF_HINTS_DO_ADVANCE( h ) \
242 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_ADVANCE )
244 #define AF_HINTS_DO_BLUES( h ) 1
246 #endif /* !AF_DEBUG */
249 FT_LOCAL( AF_Direction
)
250 af_direction_compute( FT_Pos dx
,
255 af_axis_hints_new_segment( AF_AxisHints axis
,
257 AF_Segment
*asegment
);
260 af_axis_hints_new_edge( AF_AxisHints axis
,
266 af_glyph_hints_init( AF_GlyphHints hints
,
272 * recompute all AF_Point in a AF_GlyphHints from the definitions
273 * in a source outline
276 af_glyph_hints_rescale( AF_GlyphHints hints
,
277 AF_ScriptMetrics metrics
);
280 af_glyph_hints_reload( AF_GlyphHints hints
,
281 FT_Outline
* outline
);
284 af_glyph_hints_save( AF_GlyphHints hints
,
285 FT_Outline
* outline
);
288 af_glyph_hints_align_edge_points( AF_GlyphHints hints
,
292 af_glyph_hints_align_strong_points( AF_GlyphHints hints
,
296 af_glyph_hints_align_weak_points( AF_GlyphHints hints
,
301 af_glyph_hints_scale_dim( AF_GlyphHints hints
,
308 af_glyph_hints_done( AF_GlyphHints hints
);
312 #define AF_SEGMENT_LEN( seg ) ( (seg)->max_coord - (seg)->min_coord )
314 #define AF_SEGMENT_DIST( seg1, seg2 ) ( ( (seg1)->pos > (seg2)->pos ) \
315 ? (seg1)->pos - (seg2)->pos \
316 : (seg2)->pos - (seg1)->pos )
321 #endif /* __AFHINTS_H__ */