The BIG graph update
[rrdtool.git] / libraries / freetype-2.0.5 / include / ahtypes.h
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ahtypes.h                                                              */
4 /*                                                                         */
5 /*    General types and definitions for the auto-hint module               */
6 /*    (specification only).                                                */
7 /*                                                                         */
8 /*  Copyright 2000-2001 Catharon Productions Inc.                          */
9 /*  Author: David Turner                                                   */
10 /*                                                                         */
11 /*  This file is part of the Catharon Typography Project and shall only    */
12 /*  be used, modified, and distributed under the terms of the Catharon     */
13 /*  Open Source License that should come with this file under the name     */
14 /*  `CatharonLicense.txt'.  By continuing to use, modify, or distribute    */
15 /*  this file you indicate that you have read the license and              */
16 /*  understand and accept it fully.                                        */
17 /*                                                                         */
18 /*  Note that this license is compatible with the FreeType license.        */
19 /*                                                                         */
20 /***************************************************************************/
21
22
23 #ifndef __AHTYPES_H__
24 #define __AHTYPES_H__
25
26
27 #include <ft2build.h>
28 #include FT_INTERNAL_OBJECTS_H
29 #include "ahloader.h"
30
31
32 #define xxAH_DEBUG
33
34
35 #ifdef AH_DEBUG
36
37 #include <stdio.h>
38 #define AH_LOG( x )  printf ## x
39
40 #else
41
42 #define AH_LOG( x )  do ; while ( 0 ) /* nothing */
43
44 #endif /* AH_DEBUG */
45
46
47 FT_BEGIN_HEADER
48
49
50   /*************************************************************************/
51   /*************************************************************************/
52   /*************************************************************************/
53   /****                                                                 ****/
54   /**** COMPILE-TIME BUILD OPTIONS                                      ****/
55   /****                                                                 ****/
56   /**** Toggle these configuration macros to experiment with `features' ****/
57   /**** of the auto-hinter.                                             ****/
58   /****                                                                 ****/
59   /*************************************************************************/
60   /*************************************************************************/
61   /*************************************************************************/
62
63
64   /*************************************************************************/
65   /*                                                                       */
66   /* If this option is defined, only strong interpolation will be used to  */
67   /* place the points between edges.  Otherwise, `smooth' points are       */
68   /* detected and later hinted through weak interpolation to correct some  */
69   /* unpleasant artefacts.                                                 */
70   /*                                                                       */
71 #undef AH_OPTION_NO_WEAK_INTERPOLATION
72
73
74   /*************************************************************************/
75   /*                                                                       */
76   /* If this option is defined, only weak interpolation will be used to    */
77   /* place the points between edges.  Otherwise, `strong' points are       */
78   /* detected and later hinted through strong interpolation to correct     */
79   /* some unpleasant artefacts.                                            */
80   /*                                                                       */
81 #undef AH_OPTION_NO_STRONG_INTERPOLATION
82
83
84   /*************************************************************************/
85   /*                                                                       */
86   /* Undefine this macro if you don't want to hint the metrics.  There is  */
87   /* no reason to do this (at least for non-CJK scripts), except for       */
88   /* experimentation.                                                      */
89   /*                                                                       */
90 #define AH_HINT_METRICS
91
92
93   /*************************************************************************/
94   /*                                                                       */
95   /* Define this macro if you do not want to insert extra edges at a       */
96   /* glyph's x and y extremum (if there isn't one already available).      */
97   /* This helps to reduce a number of artefacts and allows hinting of      */
98   /* metrics.                                                              */
99   /*                                                                       */
100 #undef AH_OPTION_NO_EXTREMUM_EDGES
101
102
103   /* don't touch for now */
104 #define AH_MAX_WIDTHS   12
105 #define AH_MAX_HEIGHTS  12
106
107
108   /*************************************************************************/
109   /*************************************************************************/
110   /*************************************************************************/
111   /****                                                                 ****/
112   /****   TYPE DEFINITIONS                                              ****/
113   /****                                                                 ****/
114   /*************************************************************************/
115   /*************************************************************************/
116   /*************************************************************************/
117
118
119   /* see agangles.h */
120   typedef FT_Int  AH_Angle;
121
122
123   /* hint flags */
124 #define ah_flah_none       0
125
126   /* bezier control points flags */
127 #define ah_flah_conic                 1
128 #define ah_flah_cubic                 2
129 #define ah_flah_control               ( ah_flah_conic | ah_flah_cubic )
130
131   /* extrema flags */
132 #define ah_flah_extrema_x             4
133 #define ah_flah_extrema_y             8
134
135   /* roundness */
136 #define ah_flah_round_x              16
137 #define ah_flah_round_y              32
138
139   /* touched */
140 #define ah_flah_touch_x              64
141 #define ah_flah_touch_y             128
142
143   /* weak interpolation */
144 #define ah_flah_weak_interpolation  256
145
146   typedef FT_Int AH_Flags;
147
148
149   /* edge hint flags */
150 #define ah_edge_normal  0
151 #define ah_edge_round   1
152 #define ah_edge_serif   2
153 #define ah_edge_done    4
154
155   typedef FT_Int  AH_Edge_Flags;
156
157
158   /* hint directions -- the values are computed so that two vectors are */
159   /* in opposite directions iff `dir1+dir2 == 0'                        */
160 #define ah_dir_none    4
161 #define ah_dir_right   1
162 #define ah_dir_left   -1
163 #define ah_dir_up      2
164 #define ah_dir_down   -2
165
166   typedef FT_Int  AH_Direction;
167
168
169   typedef struct AH_Point    AH_Point;
170   typedef struct AH_Segment  AH_Segment;
171   typedef struct AH_Edge     AH_Edge;
172
173
174   /*************************************************************************/
175   /*                                                                       */
176   /* <Struct>                                                              */
177   /*    AH_Point                                                           */
178   /*                                                                       */
179   /* <Description>                                                         */
180   /*    A structure used to model an outline point to the AH_Outline type. */
181   /*                                                                       */
182   /* <Fields>                                                              */
183   /*    flags     :: The current point hint flags.                         */
184   /*                                                                       */
185   /*    ox, oy    :: The current original scaled coordinates.              */
186   /*                                                                       */
187   /*    fx, fy    :: The current coordinates in font units.                */
188   /*                                                                       */
189   /*    x,  y     :: The current hinter coordinates.                       */
190   /*                                                                       */
191   /*    u, v      :: Point coordinates -- meaning varies with context.     */
192   /*                                                                       */
193   /*    in_dir    :: The direction of the inwards vector (prev->point).    */
194   /*                                                                       */
195   /*    out_dir   :: The direction of the outwards vector (point->next).   */
196   /*                                                                       */
197   /*    in_angle  :: The angle of the inwards vector.                      */
198   /*                                                                       */
199   /*    out_angle :: The angle of the outwards vector.                     */
200   /*                                                                       */
201   /*    next      :: The next point in same contour.                       */
202   /*                                                                       */
203   /*    prev      :: The previous point in same contour.                   */
204   /*                                                                       */
205   struct AH_Point
206   {
207     AH_Flags      flags;    /* point flags used by hinter */
208     FT_Pos        ox, oy;
209     FT_Pos        fx, fy;
210     FT_Pos        x,  y;
211     FT_Pos        u,  v;
212
213     AH_Direction  in_dir;   /* direction of inwards vector  */
214     AH_Direction  out_dir;  /* direction of outwards vector */
215
216     AH_Angle      in_angle;
217     AH_Angle      out_angle;
218
219     AH_Point*     next;     /* next point in contour     */
220     AH_Point*     prev;     /* previous point in contour */
221   };
222
223
224   /*************************************************************************/
225   /*                                                                       */
226   /* <Struct>                                                              */
227   /*    AH_Segment                                                         */
228   /*                                                                       */
229   /* <Description>                                                         */
230   /*    A structure used to describe an edge segment to the auto-hinter.   */
231   /*    A segment is simply a sequence of successive points located on the */
232   /*    same horizontal or vertical `position', in a given direction.      */
233   /*                                                                       */
234   /* <Fields>                                                              */
235   /*    flags      :: The segment edge flags (straight, rounded, etc.).    */
236   /*                                                                       */
237   /*    dir        :: The segment direction.                               */
238   /*                                                                       */
239   /*    first      :: The first point in the segment.                      */
240   /*                                                                       */
241   /*    last       :: The last point in the segment.                       */
242   /*                                                                       */
243   /*    contour    :: A pointer to the first point of the segment's        */
244   /*                  contour.                                             */
245   /*                                                                       */
246   /*    pos        :: The segment position in font units.                  */
247   /*                                                                       */
248   /*    size       :: The segment size.                                    */
249   /*                                                                       */
250   /*    edge       :: The edge of the current segment.                     */
251   /*                                                                       */
252   /*    edge_next  :: The next segment on the same edge.                   */
253   /*                                                                       */
254   /*    link       :: The pairing segment for this edge.                   */
255   /*                                                                       */
256   /*    serif      :: The primary segment for serifs.                      */
257   /*                                                                       */
258   /*    num_linked :: The number of other segments that link to this one.  */
259   /*                                                                       */
260   /*    score      :: Used to score the segment when selecting them.       */
261   /*                                                                       */
262   struct AH_Segment
263   {
264     AH_Edge_Flags  flags;
265     AH_Direction   dir;
266
267     AH_Point*      first;       /* first point in edge segment             */
268     AH_Point*      last;        /* last point in edge segment              */
269     AH_Point**     contour;     /* ptr to first point of segment's contour */
270
271     FT_Pos         pos;         /* position of segment           */
272     FT_Pos         min_coord;   /* minimum coordinate of segment */
273     FT_Pos         max_coord;   /* maximum coordinate of segment */
274
275     AH_Edge*       edge;
276     AH_Segment*    edge_next;
277
278     AH_Segment*    link;        /* link segment               */
279     AH_Segment*    serif;       /* primary segment for serifs */
280     FT_Pos         num_linked;  /* number of linked segments  */
281     FT_Int         score;
282   };
283
284
285   /*************************************************************************/
286   /*                                                                       */
287   /* <Struct>                                                              */
288   /*    AH_Edge                                                            */
289   /*                                                                       */
290   /* <Description>                                                         */
291   /*    A structure used to describe an edge, which really is a horizontal */
292   /*    or vertical coordinate to be hinted depending on the segments      */
293   /*    located on it.                                                     */
294   /*                                                                       */
295   /* <Fields>                                                              */
296   /*    flags      :: The segment edge flags (straight, rounded, etc.).    */
297   /*                                                                       */
298   /*    dir        :: The main segment direction on this edge.             */
299   /*                                                                       */
300   /*    first      :: The first edge segment.                              */
301   /*                                                                       */
302   /*    last       :: The last edge segment.                               */
303   /*                                                                       */
304   /*    fpos       :: The original edge position in font units.            */
305   /*                                                                       */
306   /*    opos       :: The original scaled edge position.                   */
307   /*                                                                       */
308   /*    pos        :: The hinted edge position.                            */
309   /*                                                                       */
310   /*    link       :: The linked edge.                                     */
311   /*                                                                       */
312   /*    serif      :: The serif edge.                                      */
313   /*                                                                       */
314   /*    num_paired :: The number of other edges that pair to this one.     */
315   /*                                                                       */
316   /*    score      :: Used to score the edge when selecting them.          */
317   /*                                                                       */
318   /*    blue_edge  :: Indicate the blue zone edge this edge is related to. */
319   /*                  Only set for some of the horizontal edges in a Latin */
320   /*                  font.                                                */
321   /*                                                                       */
322   struct AH_Edge
323   {
324     AH_Edge_Flags  flags;
325     AH_Direction   dir;
326
327     AH_Segment*    first;
328     AH_Segment*    last;
329
330     FT_Pos         fpos;
331     FT_Pos         opos;
332     FT_Pos         pos;
333
334     AH_Edge*       link;
335     AH_Edge*       serif;
336     FT_Int         num_linked;
337
338     FT_Int         score;
339     FT_Pos*        blue_edge;
340   };
341
342
343   /* an outline as seen by the hinter */
344   typedef struct  AH_Outline_
345   {
346     FT_Memory     memory;
347
348     AH_Direction  vert_major_dir;   /* vertical major direction   */
349     AH_Direction  horz_major_dir;   /* horizontal major direction */
350
351     FT_Fixed      x_scale;
352     FT_Fixed      y_scale;
353     FT_Pos        edge_distance_threshold;
354
355     FT_Int        max_points;
356     FT_Int        num_points;
357     AH_Point*     points;
358
359     FT_Int        max_contours;
360     FT_Int        num_contours;
361     AH_Point**    contours;
362
363     FT_Int        num_hedges;
364     AH_Edge*      horz_edges;
365
366     FT_Int        num_vedges;
367     AH_Edge*      vert_edges;
368
369     FT_Int        num_hsegments;
370     AH_Segment*   horz_segments;
371
372     FT_Int        num_vsegments;
373     AH_Segment*   vert_segments;
374
375   } AH_Outline;
376
377
378 #define ah_blue_capital_top     0                              /* THEZOCQS */
379 #define ah_blue_capital_bottom  ( ah_blue_capital_top + 1 )    /* HEZLOCUS */
380 #define ah_blue_small_top       ( ah_blue_capital_bottom + 1 ) /* xzroesc  */
381 #define ah_blue_small_bottom    ( ah_blue_small_top + 1 )      /* xzroesc  */
382 #define ah_blue_small_minor     ( ah_blue_small_bottom + 1 )   /* pqgjy    */
383 #define ah_blue_max             ( ah_blue_small_minor + 1 )
384
385   typedef FT_Int  AH_Blue;
386
387
388 #define ah_hinter_monochrome  1
389 #define ah_hinter_optimize    2
390
391   typedef FT_Int  AH_Hinter_Flags;
392
393
394   /*************************************************************************/
395   /*                                                                       */
396   /* <Struct>                                                              */
397   /*    AH_Globals                                                         */
398   /*                                                                       */
399   /* <Description>                                                         */
400   /*    Holds the global metrics for a given font face (be it in design    */
401   /*    units or scaled pixel values).                                     */
402   /*                                                                       */
403   /* <Fields>                                                              */
404   /*    num_widths  :: The number of widths.                               */
405   /*                                                                       */
406   /*    num_heights :: The number of heights.                              */
407   /*                                                                       */
408   /*    widths      :: Snap widths, including standard one.                */
409   /*                                                                       */
410   /*    heights     :: Snap height, including standard one.                */
411   /*                                                                       */
412   /*    blue_refs   :: The reference positions of blue zones.              */
413   /*                                                                       */
414   /*    blue_shoots :: The overshoot positions of blue zones.              */
415   /*                                                                       */
416   typedef struct  AH_Globals_
417   {
418     FT_Int    num_widths;
419     FT_Int    num_heights;
420
421     FT_Pos    widths [AH_MAX_WIDTHS];
422     FT_Pos    heights[AH_MAX_HEIGHTS];
423
424     FT_Pos    blue_refs  [ah_blue_max];
425     FT_Pos    blue_shoots[ah_blue_max];
426
427   } AH_Globals;
428
429
430   /*************************************************************************/
431   /*                                                                       */
432   /* <Struct>                                                              */
433   /*    AH_Face_Globals                                                    */
434   /*                                                                       */
435   /* <Description>                                                         */
436   /*    Holds the complete global metrics for a given font face (i.e., the */
437   /*    design units version + a scaled version + the current scales       */
438   /*    used).                                                             */
439   /*                                                                       */
440   /* <Fields>                                                              */
441   /*    face    :: A handle to the source face object                      */
442   /*                                                                       */
443   /*    design  :: The globals in font design units.                       */
444   /*                                                                       */
445   /*    scaled  :: Scaled globals in sub-pixel values.                     */
446   /*                                                                       */
447   /*    x_scale :: The current horizontal scale.                           */
448   /*                                                                       */
449   /*    y_scale :: The current vertical scale.                             */
450   /*                                                                       */
451   typedef struct  AH_Face_Globals_
452   {
453     FT_Face     face;
454     AH_Globals  design;
455     AH_Globals  scaled;
456     FT_Fixed    x_scale;
457     FT_Fixed    y_scale;
458     FT_Bool     control_overshoot;
459
460   } AH_Face_Globals;
461
462
463   typedef struct  AH_Hinter
464   {
465     FT_Memory         memory;
466     AH_Hinter_Flags   flags;
467
468     FT_Int            algorithm;
469     FT_Face           face;
470
471     AH_Face_Globals*  globals;
472
473     AH_Outline*       glyph;
474
475     AH_Loader*        loader;
476     FT_Vector         pp1;
477     FT_Vector         pp2;
478
479     FT_Bool           transformed;
480     FT_Vector         trans_delta;
481     FT_Matrix         trans_matrix;
482
483     FT_Bool           disable_horz_edges;
484     FT_Bool           disable_vert_edges;
485   } AH_Hinter;
486
487
488 FT_END_HEADER
489
490 #endif /* __AHTYPES_H__ */
491
492
493 /* END */