1 /***************************************************************************/
5 /* General types and definitions for the auto-hint module */
6 /* (specification only). */
8 /* Copyright 2000-2001, 2002 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 /***************************************************************************/
28 #include FT_INTERNAL_OBJECTS_H
31 #include <../src/autohint/ahloader.h>
43 #define AH_LOG( x ) printf ## x
47 #define AH_LOG( x ) do ; while ( 0 ) /* nothing */
55 /*************************************************************************/
56 /*************************************************************************/
57 /*************************************************************************/
59 /**** COMPILE-TIME BUILD OPTIONS ****/
61 /**** Toggle these configuration macros to experiment with `features' ****/
62 /**** of the auto-hinter. ****/
64 /*************************************************************************/
65 /*************************************************************************/
66 /*************************************************************************/
69 /*************************************************************************/
71 /* If this option is defined, only strong interpolation will be used to */
72 /* place the points between edges. Otherwise, `smooth' points are */
73 /* detected and later hinted through weak interpolation to correct some */
74 /* unpleasant artefacts. */
76 #undef AH_OPTION_NO_WEAK_INTERPOLATION
79 /*************************************************************************/
81 /* If this option is defined, only weak interpolation will be used to */
82 /* place the points between edges. Otherwise, `strong' points are */
83 /* detected and later hinted through strong interpolation to correct */
84 /* some unpleasant artefacts. */
86 #undef AH_OPTION_NO_STRONG_INTERPOLATION
89 /*************************************************************************/
91 /* Undefine this macro if you don't want to hint the metrics. There is */
92 /* no reason to do this (at least for non-CJK scripts), except for */
93 /* experimentation. */
95 #undef AH_HINT_METRICS
98 /*************************************************************************/
100 /* Define this macro if you do not want to insert extra edges at a */
101 /* glyph's x and y extremum (if there isn't one already available). */
102 /* This helps to reduce a number of artefacts and allows hinting of */
105 #undef AH_OPTION_NO_EXTREMUM_EDGES
108 /* don't touch for now */
109 #define AH_MAX_WIDTHS 12
110 #define AH_MAX_HEIGHTS 12
113 /*************************************************************************/
114 /*************************************************************************/
115 /*************************************************************************/
117 /**** TYPE DEFINITIONS ****/
119 /*************************************************************************/
120 /*************************************************************************/
121 /*************************************************************************/
125 typedef FT_Int AH_Angle;
129 #define AH_FLAG_NONE 0
131 /* bezier control points flags */
132 #define AH_FLAG_CONIC 1
133 #define AH_FLAG_CUBIC 2
134 #define AH_FLAG_CONTROL ( AH_FLAG_CONIC | AH_FLAG_CUBIC )
137 #define AH_FLAG_EXTREMA_X 4
138 #define AH_FLAG_EXTREMA_Y 8
141 #define AH_FLAG_ROUND_X 16
142 #define AH_FLAG_ROUND_Y 32
145 #define AH_FLAG_TOUCH_X 64
146 #define AH_FLAG_TOUCH_Y 128
148 /* weak interpolation */
149 #define AH_FLAG_WEAK_INTERPOLATION 256
150 #define AH_FLAG_INFLECTION 512
152 typedef FT_Int AH_Flags;
155 /* edge hint flags */
156 #define AH_EDGE_NORMAL 0
157 #define AH_EDGE_ROUND 1
158 #define AH_EDGE_SERIF 2
159 #define AH_EDGE_DONE 4
161 typedef FT_Int AH_Edge_Flags;
164 /* hint directions -- the values are computed so that two vectors are */
165 /* in opposite directions iff `dir1+dir2 == 0' */
166 #define AH_DIR_NONE 4
167 #define AH_DIR_RIGHT 1
168 #define AH_DIR_LEFT -1
170 #define AH_DIR_DOWN -2
172 typedef FT_Int AH_Direction;
175 typedef struct AH_PointRec_* AH_Point;
176 typedef struct AH_SegmentRec_* AH_Segment;
177 typedef struct AH_EdgeRec_* AH_Edge;
180 /*************************************************************************/
186 /* A structure used to model an outline point to the AH_OutlineRec */
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 hinted 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. */
212 typedef struct AH_PointRec_
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 */
232 /*************************************************************************/
238 /* A structure used to describe an edge segment to the auto-hinter. */
239 /* A segment is simply a sequence of successive points located on the */
240 /* same horizontal or vertical `position', in a given direction. */
243 /* flags :: The segment edge flags (straight, rounded, etc.). */
245 /* dir :: The segment direction. */
247 /* first :: The first point in the segment. */
249 /* last :: The last point in the segment. */
251 /* contour :: A pointer to the first point of the segment's */
254 /* pos :: The segment position in font units. */
256 /* size :: The segment size. */
258 /* edge :: The edge of the current segment. */
260 /* edge_next :: The next segment on the same edge. */
262 /* link :: The pairing segment for this edge. */
264 /* serif :: The primary segment for serifs. */
266 /* num_linked :: The number of other segments that link to this one. */
268 /* score :: Used to score the segment when selecting them. */
270 typedef struct AH_SegmentRec_
275 AH_Point first; /* first point in edge segment */
276 AH_Point last; /* last point in edge segment */
277 AH_Point* contour; /* ptr to first point of segment's contour */
279 FT_Pos pos; /* position of segment */
280 FT_Pos min_coord; /* minimum coordinate of segment */
281 FT_Pos max_coord; /* maximum coordinate of segment */
284 AH_Segment edge_next;
286 AH_Segment link; /* link segment */
287 AH_Segment serif; /* primary segment for serifs */
288 FT_Pos num_linked; /* number of linked segments */
294 /*************************************************************************/
300 /* A structure used to describe an edge, which really is a horizontal */
301 /* or vertical coordinate to be hinted depending on the segments */
305 /* flags :: The segment edge flags (straight, rounded, etc.). */
307 /* dir :: The main segment direction on this edge. */
309 /* first :: The first edge segment. */
311 /* last :: The last edge segment. */
313 /* fpos :: The original edge position in font units. */
315 /* opos :: The original scaled edge position. */
317 /* pos :: The hinted edge position. */
319 /* link :: The linked edge. */
321 /* serif :: The serif edge. */
323 /* num_paired :: The number of other edges that pair to this one. */
325 /* score :: Used to score the edge when selecting them. */
327 /* blue_edge :: Indicate the blue zone edge this edge is related to. */
328 /* Only set for some of the horizontal edges in a Latin */
331 typedef struct AH_EdgeRec_
353 /* an outline as seen by the hinter */
354 typedef struct AH_OutlineRec_
358 AH_Direction vert_major_dir; /* vertical major direction */
359 AH_Direction horz_major_dir; /* horizontal major direction */
363 FT_Pos edge_distance_threshold;
379 FT_Int num_hsegments;
380 AH_Segment horz_segments;
382 FT_Int num_vsegments;
383 AH_Segment vert_segments;
385 } AH_OutlineRec, *AH_Outline;
388 #ifdef FT_CONFIG_CHESTER_SMALL_F
390 # define AH_BLUE_CAPITAL_TOP 0 /* THEZOCQS */
391 # define AH_BLUE_CAPITAL_BOTTOM ( AH_BLUE_CAPITAL_TOP + 1 ) /* HEZLOCUS */
392 # define AH_BLUE_SMALL_F_TOP ( AH_BLUE_CAPITAL_BOTTOM + 1 ) /* fijkdbh */
393 # define AH_BLUE_SMALL_TOP ( AH_BLUE_SMALL_F_TOP + 1 ) /* xzroesc */
394 # define AH_BLUE_SMALL_BOTTOM ( AH_BLUE_SMALL_TOP + 1 ) /* xzroesc */
395 # define AH_BLUE_SMALL_MINOR ( AH_BLUE_SMALL_BOTTOM + 1 ) /* pqgjy */
396 # define AH_BLUE_MAX ( AH_BLUE_SMALL_MINOR + 1 )
398 #else /* !CHESTER_SMALL_F */
400 # define AH_BLUE_CAPITAL_TOP 0 /* THEZOCQS */
401 # define AH_BLUE_CAPITAL_BOTTOM ( AH_BLUE_CAPITAL_TOP + 1 ) /* HEZLOCUS */
402 # define AH_BLUE_SMALL_TOP ( AH_BLUE_CAPITAL_BOTTOM + 1) /* xzroesc */
403 # define AH_BLUE_SMALL_BOTTOM ( AH_BLUE_SMALL_TOP + 1 ) /* xzroesc */
404 # define AH_BLUE_SMALL_MINOR ( AH_BLUE_SMALL_BOTTOM + 1 ) /* pqgjy */
405 # define AH_BLUE_MAX ( AH_BLUE_SMALL_MINOR + 1 )
407 #endif /* !CHESTER_SMALL_F */
409 typedef FT_Int AH_Blue;
412 #define AH_HINTER_MONOCHROME 1
413 #define AH_HINTER_OPTIMIZE 2
415 typedef FT_Int AH_Hinter_Flags;
418 /*************************************************************************/
424 /* Holds the global metrics for a given font face (be it in design */
425 /* units or scaled pixel values). */
428 /* num_widths :: The number of widths. */
430 /* num_heights :: The number of heights. */
432 /* widths :: Snap widths, including standard one. */
434 /* heights :: Snap height, including standard one. */
436 /* blue_refs :: The reference positions of blue zones. */
438 /* blue_shoots :: The overshoot positions of blue zones. */
440 typedef struct AH_GlobalsRec_
447 FT_Pos widths [AH_MAX_WIDTHS];
448 FT_Pos heights[AH_MAX_HEIGHTS];
450 FT_Pos blue_refs [AH_BLUE_MAX];
451 FT_Pos blue_shoots[AH_BLUE_MAX];
453 } AH_GlobalsRec, *AH_Globals;
456 /*************************************************************************/
459 /* AH_Face_GlobalsRec */
462 /* Holds the complete global metrics for a given font face (i.e., the */
463 /* design units version + a scaled version + the current scales */
467 /* face :: A handle to the source face object */
469 /* design :: The globals in font design units. */
471 /* scaled :: Scaled globals in sub-pixel values. */
473 /* x_scale :: The current horizontal scale. */
475 /* y_scale :: The current vertical scale. */
477 typedef struct AH_Face_GlobalsRec_
480 AH_GlobalsRec design;
481 AH_GlobalsRec scaled;
484 FT_Bool control_overshoot;
486 } AH_Face_GlobalsRec, *AH_Face_Globals;
489 typedef struct AH_HinterRec
492 AH_Hinter_Flags flags;
497 AH_Face_Globals globals;
506 FT_Vector trans_delta;
507 FT_Matrix trans_matrix;
509 FT_Bool do_horz_hints; /* disable X hinting */
510 FT_Bool do_vert_hints; /* disable Y hinting */
511 FT_Bool do_horz_snapping; /* disable X stem size snapping */
512 FT_Bool do_vert_snapping; /* disable Y stem size snapping */
513 FT_Bool do_stem_adjust; /* disable light stem snapping */
515 } AH_HinterRec, *AH_Hinter;
519 extern AH_Hinter ah_debug_hinter;
520 extern FT_Bool ah_debug_disable_horz;
521 extern FT_Bool ah_debug_disable_vert;
523 #define ah_debug_disable_horz 0
524 #define ah_debug_disable_vert 0
525 #endif /* DEBUG_HINTER */
530 #endif /* __AHTYPES_H__ */