1 /***************************************************************************/
5 /* General types and definitions for the auto-hint module */
6 /* (specification only). */
8 /* Copyright 2000 Catharon Productions Inc. */
9 /* Author: David Turner */
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. */
18 /* Note that this license is compatible with the FreeType license. */
20 /***************************************************************************/
27 #include <freetype/internal/ftobjs.h> /* for freetype.h + LOCAL_DEF etc. */
30 #ifdef FT_FLAT_COMPILE
36 #include <autohint/ahloader.h>
48 #define AH_LOG( x ) printf##x
52 #define AH_LOG( x ) do ; while ( 0 ) /* nothing */
57 /*************************************************************************/
58 /*************************************************************************/
59 /*************************************************************************/
61 /**** COMPILE-TIME BUILD OPTIONS ****/
63 /**** Toggle these configuration macros to experiment with `features' ****/
64 /**** of the auto-hinter. ****/
66 /*************************************************************************/
67 /*************************************************************************/
68 /*************************************************************************/
71 /*************************************************************************/
73 /* If this option is defined, only strong interpolation will be used to */
74 /* place the points between edges. Otherwise, `smooth' points are */
75 /* detected and later hinted through weak interpolation to correct some */
76 /* unpleasant artefacts. */
78 #undef AH_OPTION_NO_WEAK_INTERPOLATION
81 /*************************************************************************/
83 /* If this option is defined, only weak interpolation will be used to */
84 /* place the points between edges. Otherwise, `strong' points are */
85 /* detected and later hinted through strong interpolation to correct */
86 /* some unpleasant artefacts. */
88 #undef AH_OPTION_NO_STRONG_INTERPOLATION
91 /*************************************************************************/
93 /* Undefine this macro if you don't want to hint the metrics. There is */
94 /* no reason to do this (at least for non-CJK scripts), except for */
95 /* experimentation. */
97 #define AH_HINT_METRICS
100 /*************************************************************************/
102 /* Define this macro if you do not want to insert extra edges at a */
103 /* glyph's x and y extremum (if there isn't one already available). */
104 /* This helps to reduce a number of artefacts and allows hinting of */
107 #undef AH_OPTION_NO_EXTREMUM_EDGES
110 /* don't touch for now */
111 #define AH_MAX_WIDTHS 12
112 #define AH_MAX_HEIGHTS 12
115 /*************************************************************************/
116 /*************************************************************************/
117 /*************************************************************************/
119 /**** TYPE DEFINITIONS ****/
121 /*************************************************************************/
122 /*************************************************************************/
123 /*************************************************************************/
127 typedef FT_Int AH_Angle
;
131 #define ah_flah_none 0
133 /* bezier control points flags */
134 #define ah_flah_conic 1
135 #define ah_flah_cubic 2
136 #define ah_flah_control ( ah_flah_conic | ah_flah_cubic )
139 #define ah_flah_extrema_x 4
140 #define ah_flah_extrema_y 8
143 #define ah_flah_round_x 16
144 #define ah_flah_round_y 32
147 #define ah_flah_touch_x 64
148 #define ah_flah_touch_y 128
150 /* weak interpolation */
151 #define ah_flah_weak_interpolation 256
153 typedef FT_Int AH_Flags
;
156 /* edge hint flags */
157 #define ah_edge_normal 0
158 #define ah_edge_round 1
159 #define ah_edge_serif 2
160 #define ah_edge_done 4
162 typedef FT_Int AH_Edge_Flags
;
165 /* hint directions -- the values are computed so that two vectors are */
166 /* in opposite directions iff `dir1+dir2 == 0' */
167 #define ah_dir_none 4
168 #define ah_dir_right 1
169 #define ah_dir_left -1
171 #define ah_dir_down -2
173 typedef FT_Int AH_Direction
;
176 typedef struct AH_Point AH_Point
;
177 typedef struct AH_Segment AH_Segment
;
178 typedef struct AH_Edge AH_Edge
;
181 /*************************************************************************/
187 /* A structure used to model an outline point to the AH_Outline type. */
190 /* flags :: The current point hint flags. */
192 /* ox, oy :: The current original scaled coordinates. */
194 /* fx, fy :: The current coordinates in font units. */
196 /* x, y :: The current hinter coordinates. */
198 /* u, v :: Point coordinates -- meaning varies with context. */
200 /* in_dir :: The direction of the inwards vector (prev->point). */
202 /* out_dir :: The direction of the outwards vector (point->next). */
204 /* in_angle :: The angle of the inwards vector. */
206 /* out_angle :: The angle of the outwards vector. */
208 /* next :: The next point in same contour. */
210 /* prev :: The previous point in same contour. */
214 AH_Flags flags
; /* point flags used by hinter */
220 AH_Direction in_dir
; /* direction of inwards vector */
221 AH_Direction out_dir
; /* direction of outwards vector */
226 AH_Point
* next
; /* next point in contour */
227 AH_Point
* prev
; /* previous point in contour */
231 /*************************************************************************/
237 /* A structure used to describe an edge segment to the auto-hinter. */
238 /* A segment is simply a sequence of successive points located on the */
239 /* same horizontal or vertical `position', in a given direction. */
242 /* flags :: The segment edge flags (straight, rounded, etc.). */
244 /* dir :: The segment direction. */
246 /* first :: The first point in the segment. */
248 /* last :: The last point in the segment. */
250 /* contour :: A pointer to the first point of the segment's */
253 /* pos :: The segment position in font units. */
255 /* size :: The segment size. */
257 /* edge :: The edge of the current segment. */
259 /* edge_next :: The next segment on the same edge. */
261 /* link :: The pairing segment for this edge. */
263 /* serif :: The primary segment for serifs. */
265 /* num_linked :: The number of other segments that link to this one. */
267 /* score :: Used to score the segment when selecting them. */
274 AH_Point
* first
; /* first point in edge segment */
275 AH_Point
* last
; /* last point in edge segment */
276 AH_Point
** contour
; /* ptr to first point of segment's contour */
278 FT_Pos pos
; /* position of segment */
279 FT_Pos min_coord
; /* minimum coordinate of segment */
280 FT_Pos max_coord
; /* maximum coordinate of segment */
283 AH_Segment
* edge_next
;
285 AH_Segment
* link
; /* link segment */
286 AH_Segment
* serif
; /* primary segment for serifs */
287 FT_Pos num_linked
; /* number of linked segments */
292 /*************************************************************************/
298 /* A structure used to describe an edge, which really is a horizontal */
299 /* or vertical coordinate to be hinted depending on the segments */
303 /* flags :: The segment edge flags (straight, rounded, etc.). */
305 /* dir :: The main segment direction on this edge. */
307 /* first :: The first edge segment. */
309 /* last :: The last edge segment. */
311 /* fpos :: The original edge position in font units. */
313 /* opos :: The original scaled edge position. */
315 /* pos :: The hinted edge position. */
317 /* link :: The linked edge. */
319 /* serif :: The serif edge. */
321 /* num_paired :: The number of other edges that pair to this one. */
323 /* score :: Used to score the edge when selecting them. */
325 /* blue_edge :: Indicate the blue zone edge this edge is related to. */
326 /* Only set for some of the horizontal edges in a Latin */
350 /* an outline as seen by the hinter */
351 typedef struct AH_Outline_
355 AH_Direction vert_major_dir
; /* vertical major direction */
356 AH_Direction horz_major_dir
; /* horizontal major direction */
360 FT_Pos edge_distance_threshold
;
376 FT_Int num_hsegments
;
377 AH_Segment
* horz_segments
;
379 FT_Int num_vsegments
;
380 AH_Segment
* vert_segments
;
385 #define ah_blue_capital_top 0 /* THEZOCQS */
386 #define ah_blue_capital_bottom ( ah_blue_capital_top + 1 ) /* HEZLOCUS */
387 #define ah_blue_small_top ( ah_blue_capital_bottom + 1 ) /* xzroesc */
388 #define ah_blue_small_bottom ( ah_blue_small_top + 1 ) /* xzroesc */
389 #define ah_blue_small_minor ( ah_blue_small_bottom + 1 ) /* pqgjy */
390 #define ah_blue_max ( ah_blue_small_minor + 1 )
392 typedef FT_Int AH_Blue
;
395 #define ah_hinter_monochrome 1
396 #define ah_hinter_optimize 2
398 typedef FT_Int AH_Hinter_Flags
;
401 /*************************************************************************/
407 /* Holds the global metrics for a given font face (be it in design */
408 /* units or scaled pixel values). */
411 /* num_widths :: The number of widths. */
413 /* num_heights :: The number of heights. */
415 /* widths :: Snap widths, including standard one. */
417 /* heights :: Snap height, including standard one. */
419 /* blue_refs :: The reference positions of blue zones. */
421 /* blue_shoots :: The overshoot positions of blue zones. */
423 typedef struct AH_Globals_
428 FT_Pos widths
[AH_MAX_WIDTHS
];
429 FT_Pos heights
[AH_MAX_HEIGHTS
];
431 FT_Pos blue_refs
[ah_blue_max
];
432 FT_Pos blue_shoots
[ah_blue_max
];
437 /*************************************************************************/
440 /* AH_Face_Globals */
443 /* Holds the complete global metrics for a given font face (i.e., the */
444 /* design units version + a scaled version + the current scales */
448 /* face :: A handle to the source face object */
450 /* design :: The globals in font design units. */
452 /* scaled :: Scaled globals in sub-pixel values. */
454 /* x_scale :: The current horizontal scale. */
456 /* y_scale :: The current vertical scale. */
458 typedef struct AH_Face_Globals_
465 FT_Bool control_overshoot
;
470 typedef struct AH_Hinter
473 AH_Hinter_Flags flags
;
478 AH_Face_Globals
* globals
;
489 #endif /* AHTYPES_H */