Merge 25584, 25588.
[reactos.git] / reactos / dll / 3rdparty / freetype / src / autofit / afhints.h
1 /***************************************************************************/
2 /* */
3 /* afhints.h */
4 /* */
5 /* Auto-fitter hinting routines (specification). */
6 /* */
7 /* Copyright 2003, 2004, 2005, 2006 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
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. */
15 /* */
16 /***************************************************************************/
17
18
19 #ifndef __AFHINTS_H__
20 #define __AFHINTS_H__
21
22 #include "aftypes.h"
23
24
25 FT_BEGIN_HEADER
26
27 /*
28 * The definition of outline glyph hints. These are shared by all
29 * script analysis routines (until now).
30 */
31
32 typedef enum
33 {
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 */
38
39 AF_DIMENSION_MAX /* do not remove */
40
41 } AF_Dimension;
42
43
44 /* hint directions -- the values are computed so that two vectors are */
45 /* in opposite directions iff `dir1 + dir2 == 0' */
46 typedef enum
47 {
48 AF_DIR_NONE = 4,
49 AF_DIR_RIGHT = 1,
50 AF_DIR_LEFT = -1,
51 AF_DIR_UP = 2,
52 AF_DIR_DOWN = -2
53
54 } AF_Direction;
55
56
57 /* point hint flags */
58 typedef enum
59 {
60 AF_FLAG_NONE = 0,
61
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,
66
67 /* point extremum flags */
68 AF_FLAG_EXTREMA_X = 1 << 2,
69 AF_FLAG_EXTREMA_Y = 1 << 3,
70
71 /* point roundness flags */
72 AF_FLAG_ROUND_X = 1 << 4,
73 AF_FLAG_ROUND_Y = 1 << 5,
74
75 /* point touch flags */
76 AF_FLAG_TOUCH_X = 1 << 6,
77 AF_FLAG_TOUCH_Y = 1 << 7,
78
79 /* candidates for weak interpolation have this flag set */
80 AF_FLAG_WEAK_INTERPOLATION = 1 << 8,
81
82 /* all inflection points in the outline have this flag set */
83 AF_FLAG_INFLECTION = 1 << 9
84
85 } AF_Flags;
86
87
88 /* edge hint flags */
89 typedef enum
90 {
91 AF_EDGE_NORMAL = 0,
92 AF_EDGE_ROUND = 1 << 0,
93 AF_EDGE_SERIF = 1 << 1,
94 AF_EDGE_DONE = 1 << 2
95
96 } AF_Edge_Flags;
97
98
99 typedef struct AF_PointRec_* AF_Point;
100 typedef struct AF_SegmentRec_* AF_Segment;
101 typedef struct AF_EdgeRec_* AF_Edge;
102
103
104 typedef struct AF_PointRec_
105 {
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 */
109
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 */
114
115 AF_Point next; /* next point in contour */
116 AF_Point prev; /* previous point in contour */
117
118 } AF_PointRec;
119
120
121 typedef struct AF_SegmentRec_
122 {
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 */
129
130 AF_Edge edge; /* the segment's parent edge */
131 AF_Segment edge_next; /* link to next segment in parent edge */
132
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 */
138
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 */
142
143 } AF_SegmentRec;
144
145
146 typedef struct AF_EdgeRec_
147 {
148 FT_Short fpos; /* original, unscaled position (font units) */
149 FT_Pos opos; /* original, scaled position */
150 FT_Pos pos; /* current position */
151
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 */
156
157 AF_Edge link;
158 AF_Edge serif;
159 FT_Short num_linked;
160
161 FT_Int score;
162
163 AF_Segment first;
164 AF_Segment last;
165
166 } AF_EdgeRec;
167
168
169 typedef struct AF_AxisHintsRec_
170 {
171 FT_Int num_segments;
172 FT_Int max_segments;
173 AF_Segment segments;
174
175 FT_Int num_edges;
176 FT_Int max_edges;
177 AF_Edge edges;
178
179 AF_Direction major_dir;
180
181 } AF_AxisHintsRec, *AF_AxisHints;
182
183
184 typedef struct AF_GlyphHintsRec_
185 {
186 FT_Memory memory;
187
188 FT_Fixed x_scale;
189 FT_Pos x_delta;
190
191 FT_Fixed y_scale;
192 FT_Pos y_delta;
193
194 FT_Pos edge_distance_threshold;
195
196 FT_Int max_points;
197 FT_Int num_points;
198 AF_Point points;
199
200 FT_Int max_contours;
201 FT_Int num_contours;
202 AF_Point* contours;
203
204 AF_AxisHintsRec axis[AF_DIMENSION_MAX];
205
206 FT_UInt32 scaler_flags; /* copy of scaler flags */
207 FT_UInt32 other_flags; /* free for script-specific */
208 /* implementations */
209 AF_ScriptMetrics metrics;
210
211 } AF_GlyphHintsRec;
212
213
214 #define AF_HINTS_TEST_SCALER( h, f ) ( (h)->scaler_flags & (f) )
215 #define AF_HINTS_TEST_OTHER( h, f ) ( (h)->other_flags & (f) )
216
217
218 #ifdef AF_DEBUG
219
220 #define AF_HINTS_DO_HORIZONTAL( h ) \
221 ( !_af_debug_disable_horz_hints && \
222 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_HORIZONTAL ) )
223
224 #define AF_HINTS_DO_VERTICAL( h ) \
225 ( !_af_debug_disable_vert_hints && \
226 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_VERTICAL ) )
227
228 #define AF_HINTS_DO_ADVANCE( h ) \
229 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_ADVANCE )
230
231 #define AF_HINTS_DO_BLUES( h ) ( !_af_debug_disable_blue_hints )
232
233 #else /* !AF_DEBUG */
234
235 #define AF_HINTS_DO_HORIZONTAL( h ) \
236 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_HORIZONTAL )
237
238 #define AF_HINTS_DO_VERTICAL( h ) \
239 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_VERTICAL )
240
241 #define AF_HINTS_DO_ADVANCE( h ) \
242 !AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_ADVANCE )
243
244 #define AF_HINTS_DO_BLUES( h ) 1
245
246 #endif /* !AF_DEBUG */
247
248
249 FT_LOCAL( AF_Direction )
250 af_direction_compute( FT_Pos dx,
251 FT_Pos dy );
252
253
254 FT_LOCAL( FT_Error )
255 af_axis_hints_new_segment( AF_AxisHints axis,
256 FT_Memory memory,
257 AF_Segment *asegment );
258
259 FT_LOCAL( FT_Error)
260 af_axis_hints_new_edge( AF_AxisHints axis,
261 FT_Int fpos,
262 FT_Memory memory,
263 AF_Edge *edge );
264
265 FT_LOCAL( void )
266 af_glyph_hints_init( AF_GlyphHints hints,
267 FT_Memory memory );
268
269
270
271 /*
272 * recompute all AF_Point in a AF_GlyphHints from the definitions
273 * in a source outline
274 */
275 FT_LOCAL( void )
276 af_glyph_hints_rescale( AF_GlyphHints hints,
277 AF_ScriptMetrics metrics );
278
279 FT_LOCAL( FT_Error )
280 af_glyph_hints_reload( AF_GlyphHints hints,
281 FT_Outline* outline );
282
283 FT_LOCAL( void )
284 af_glyph_hints_save( AF_GlyphHints hints,
285 FT_Outline* outline );
286
287 FT_LOCAL( void )
288 af_glyph_hints_align_edge_points( AF_GlyphHints hints,
289 AF_Dimension dim );
290
291 FT_LOCAL( void )
292 af_glyph_hints_align_strong_points( AF_GlyphHints hints,
293 AF_Dimension dim );
294
295 FT_LOCAL( void )
296 af_glyph_hints_align_weak_points( AF_GlyphHints hints,
297 AF_Dimension dim );
298
299 #ifdef AF_USE_WARPER
300 FT_LOCAL( void )
301 af_glyph_hints_scale_dim( AF_GlyphHints hints,
302 AF_Dimension dim,
303 FT_Fixed scale,
304 FT_Pos delta );
305 #endif
306
307 FT_LOCAL( void )
308 af_glyph_hints_done( AF_GlyphHints hints );
309
310 /* */
311
312 #define AF_SEGMENT_LEN( seg ) ( (seg)->max_coord - (seg)->min_coord )
313
314 #define AF_SEGMENT_DIST( seg1, seg2 ) ( ( (seg1)->pos > (seg2)->pos ) \
315 ? (seg1)->pos - (seg2)->pos \
316 : (seg2)->pos - (seg1)->pos )
317
318
319 FT_END_HEADER
320
321 #endif /* __AFHINTS_H__ */
322
323
324 /* END */