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