blob: 65976658c7e60a4391eabe381030091577809b51 [file] [log] [blame]
David Turner3469d0d2000-07-19 20:02:14 +00001/***************************************************************************/
2/* */
3/* ahtypes.h */
4/* */
Werner Lembergc3dd1512000-07-26 14:11:15 +00005/* General types and definitions for the auto-hint module */
6/* (specification only). */
David Turner3469d0d2000-07-19 20:02:14 +00007/* */
Werner Lembergc3dd1512000-07-26 14:11:15 +00008/* Copyright 2000 Catharon Productions Inc. */
David Turner3469d0d2000-07-19 20:02:14 +00009/* 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 */
Werner Lembergc3dd1512000-07-26 14:11:15 +000014/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */
David Turner3469d0d2000-07-19 20:02:14 +000015/* this file you indicate that you have read the license and */
16/* understand and accept it fully. */
17/* */
Werner Lembergc3dd1512000-07-26 14:11:15 +000018/* Note that this license is compatible with the FreeType license. */
David Turner3469d0d2000-07-19 20:02:14 +000019/* */
20/***************************************************************************/
21
David Turner3469d0d2000-07-19 20:02:14 +000022
Werner Lemberg90d99642000-12-09 00:45:38 +000023#ifndef __AHTYPES_H__
24#define __AHTYPES_H__
Werner Lembergc3dd1512000-07-26 14:11:15 +000025
Werner Lembergcc069be2000-12-08 16:17:16 +000026
27#include <ft2build.h>
28#include FT_INTERNAL_OBJECTS_H
29#include FT_SOURCE_FILE(autohint,ahloader.h)
David Turner3469d0d2000-07-19 20:02:14 +000030
David Turner3469d0d2000-07-19 20:02:14 +000031
Werner Lembergc3dd1512000-07-26 14:11:15 +000032#define xxAH_DEBUG
33
34
35#ifdef AH_DEBUG
Werner Lembergcc069be2000-12-08 16:17:16 +000036
37#include <stdio.h>
38#define AH_LOG( x ) printf##x
39
David Turner3469d0d2000-07-19 20:02:14 +000040#else
Werner Lembergcc069be2000-12-08 16:17:16 +000041
42#define AH_LOG( x ) do ; while ( 0 ) /* nothing */
43
44#endif /* AH_DEBUG */
45
David Turner3469d0d2000-07-19 20:02:14 +000046
David Turner19ed8af2000-12-08 02:42:29 +000047FT_BEGIN_HEADER
Werner Lembergc713d922000-08-01 13:17:04 +000048
Werner Lemberg90d99642000-12-09 00:45:38 +000049
Werner Lembergc3dd1512000-07-26 14:11:15 +000050 /*************************************************************************/
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 /*************************************************************************/
David Turner3469d0d2000-07-19 20:02:14 +000062
David Turner3469d0d2000-07-19 20:02:14 +000063
Werner Lembergc3dd1512000-07-26 14:11:15 +000064 /*************************************************************************/
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 /* */
David Turner3469d0d2000-07-19 20:02:14 +000090#define AH_HINT_METRICS
91
David Turner3469d0d2000-07-19 20:02:14 +000092
Werner Lembergc3dd1512000-07-26 14:11:15 +000093 /*************************************************************************/
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 */
David Turner3469d0d2000-07-19 20:02:14 +0000104#define AH_MAX_WIDTHS 12
105#define AH_MAX_HEIGHTS 12
106
David Turner3469d0d2000-07-19 20:02:14 +0000107
Werner Lembergc3dd1512000-07-26 14:11:15 +0000108 /*************************************************************************/
109 /*************************************************************************/
110 /*************************************************************************/
111 /**** ****/
112 /**** TYPE DEFINITIONS ****/
113 /**** ****/
114 /*************************************************************************/
115 /*************************************************************************/
116 /*************************************************************************/
David Turner3469d0d2000-07-19 20:02:14 +0000117
118
Werner Lembergc3dd1512000-07-26 14:11:15 +0000119 /* see agangles.h */
120 typedef FT_Int AH_Angle;
David Turner3469d0d2000-07-19 20:02:14 +0000121
122
Werner Lembergc3dd1512000-07-26 14:11:15 +0000123 /* hint flags */
124#define ah_flah_none 0
David Turner3469d0d2000-07-19 20:02:14 +0000125
Werner Lembergc3dd1512000-07-26 14:11:15 +0000126 /* 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;
David Turner3469d0d2000-07-19 20:02:14 +0000147
148
Werner Lembergc3dd1512000-07-26 14:11:15 +0000149 /* 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
David Turner3469d0d2000-07-19 20:02:14 +0000154
Werner Lembergc3dd1512000-07-26 14:11:15 +0000155 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;
David Turner3469d0d2000-07-19 20:02:14 +0000167
168
169 typedef struct AH_Point AH_Point;
170 typedef struct AH_Segment AH_Segment;
171 typedef struct AH_Edge AH_Edge;
172
Werner Lembergc3dd1512000-07-26 14:11:15 +0000173
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 /* */
David Turner3469d0d2000-07-19 20:02:14 +0000205 struct AH_Point
206 {
Werner Lembergc3dd1512000-07-26 14:11:15 +0000207 AH_Flags flags; /* point flags used by hinter */
David Turner3469d0d2000-07-19 20:02:14 +0000208 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
Werner Lembergc3dd1512000-07-26 14:11:15 +0000219 AH_Point* next; /* next point in contour */
220 AH_Point* prev; /* previous point in contour */
David Turner3469d0d2000-07-19 20:02:14 +0000221 };
222
223
Werner Lembergc3dd1512000-07-26 14:11:15 +0000224 /*************************************************************************/
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 /* */
David Turner3469d0d2000-07-19 20:02:14 +0000262 struct AH_Segment
263 {
264 AH_Edge_Flags flags;
265 AH_Direction dir;
266
Werner Lembergc3dd1512000-07-26 14:11:15 +0000267 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 */
David Turner3469d0d2000-07-19 20:02:14 +0000270
Werner Lembergc3dd1512000-07-26 14:11:15 +0000271 FT_Pos pos; /* position of segment */
272 FT_Pos min_coord; /* minimum coordinate of segment */
273 FT_Pos max_coord; /* maximum coordinate of segment */
David Turner3469d0d2000-07-19 20:02:14 +0000274
275 AH_Edge* edge;
276 AH_Segment* edge_next;
277
Werner Lembergc3dd1512000-07-26 14:11:15 +0000278 AH_Segment* link; /* link segment */
279 AH_Segment* serif; /* primary segment for serifs */
280 FT_Pos num_linked; /* number of linked segments */
David Turner3469d0d2000-07-19 20:02:14 +0000281 FT_Int score;
282 };
283
284
Werner Lembergc3dd1512000-07-26 14:11:15 +0000285 /*************************************************************************/
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 /* */
David Turner3469d0d2000-07-19 20:02:14 +0000322 struct AH_Edge
323 {
Werner Lembergc3dd1512000-07-26 14:11:15 +0000324 AH_Edge_Flags flags;
325 AH_Direction dir;
David Turner3469d0d2000-07-19 20:02:14 +0000326
Werner Lembergc3dd1512000-07-26 14:11:15 +0000327 AH_Segment* first;
328 AH_Segment* last;
David Turner3469d0d2000-07-19 20:02:14 +0000329
Werner Lembergc3dd1512000-07-26 14:11:15 +0000330 FT_Pos fpos;
331 FT_Pos opos;
332 FT_Pos pos;
David Turner3469d0d2000-07-19 20:02:14 +0000333
Werner Lembergc3dd1512000-07-26 14:11:15 +0000334 AH_Edge* link;
335 AH_Edge* serif;
336 FT_Int num_linked;
David Turner3469d0d2000-07-19 20:02:14 +0000337
Werner Lembergc3dd1512000-07-26 14:11:15 +0000338 FT_Int score;
339 FT_Pos* blue_edge;
David Turner3469d0d2000-07-19 20:02:14 +0000340 };
341
342
Werner Lembergc3dd1512000-07-26 14:11:15 +0000343 /* an outline as seen by the hinter */
344 typedef struct AH_Outline_
David Turner3469d0d2000-07-19 20:02:14 +0000345 {
Werner Lembergc3dd1512000-07-26 14:11:15 +0000346 FT_Memory memory;
David Turner3469d0d2000-07-19 20:02:14 +0000347
Werner Lembergc3dd1512000-07-26 14:11:15 +0000348 AH_Direction vert_major_dir; /* vertical major direction */
349 AH_Direction horz_major_dir; /* horizontal major direction */
David Turner3469d0d2000-07-19 20:02:14 +0000350
Werner Lembergc3dd1512000-07-26 14:11:15 +0000351 FT_Fixed x_scale;
352 FT_Fixed y_scale;
353 FT_Pos edge_distance_threshold;
David Turner3469d0d2000-07-19 20:02:14 +0000354
Werner Lembergc3dd1512000-07-26 14:11:15 +0000355 FT_Int max_points;
356 FT_Int num_points;
357 AH_Point* points;
David Turner3469d0d2000-07-19 20:02:14 +0000358
Werner Lembergc3dd1512000-07-26 14:11:15 +0000359 FT_Int max_contours;
360 FT_Int num_contours;
361 AH_Point** contours;
David Turner3469d0d2000-07-19 20:02:14 +0000362
Werner Lembergc3dd1512000-07-26 14:11:15 +0000363 FT_Int num_hedges;
364 AH_Edge* horz_edges;
David Turner3469d0d2000-07-19 20:02:14 +0000365
Werner Lembergc3dd1512000-07-26 14:11:15 +0000366 FT_Int num_vedges;
367 AH_Edge* vert_edges;
David Turner3469d0d2000-07-19 20:02:14 +0000368
Werner Lembergc3dd1512000-07-26 14:11:15 +0000369 FT_Int num_hsegments;
370 AH_Segment* horz_segments;
David Turner3469d0d2000-07-19 20:02:14 +0000371
Werner Lembergc3dd1512000-07-26 14:11:15 +0000372 FT_Int num_vsegments;
373 AH_Segment* vert_segments;
David Turner3469d0d2000-07-19 20:02:14 +0000374
375 } AH_Outline;
376
377
Werner Lembergc3dd1512000-07-26 14:11:15 +0000378#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 )
David Turner3469d0d2000-07-19 20:02:14 +0000384
Werner Lembergc3dd1512000-07-26 14:11:15 +0000385 typedef FT_Int AH_Blue;
David Turner3469d0d2000-07-19 20:02:14 +0000386
387
Werner Lembergc3dd1512000-07-26 14:11:15 +0000388#define ah_hinter_monochrome 1
389#define ah_hinter_optimize 2
David Turner3469d0d2000-07-19 20:02:14 +0000390
Werner Lembergc3dd1512000-07-26 14:11:15 +0000391 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 /* */
David Turner3469d0d2000-07-19 20:02:14 +0000416 typedef struct AH_Globals_
417 {
418 FT_Int num_widths;
419 FT_Int num_heights;
420
Werner Lembergc3dd1512000-07-26 14:11:15 +0000421 FT_Pos widths [AH_MAX_WIDTHS];
422 FT_Pos heights[AH_MAX_HEIGHTS];
David Turner3469d0d2000-07-19 20:02:14 +0000423
Werner Lembergc3dd1512000-07-26 14:11:15 +0000424 FT_Pos blue_refs [ah_blue_max];
425 FT_Pos blue_shoots[ah_blue_max];
David Turner3469d0d2000-07-19 20:02:14 +0000426
427 } AH_Globals;
428
429
Werner Lembergc3dd1512000-07-26 14:11:15 +0000430 /*************************************************************************/
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_
David Turner3469d0d2000-07-19 20:02:14 +0000452 {
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
Werner Lembergc3dd1512000-07-26 14:11:15 +0000463 typedef struct AH_Hinter
David Turner3469d0d2000-07-19 20:02:14 +0000464 {
465 FT_Memory memory;
Werner Lembergc3dd1512000-07-26 14:11:15 +0000466 AH_Hinter_Flags flags;
David Turner3469d0d2000-07-19 20:02:14 +0000467
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
David Turnere0066752000-11-16 19:06:28 +0000479 FT_Bool transformed;
480 FT_Vector trans_delta;
481 FT_Matrix trans_matrix;
482
David Turner3469d0d2000-07-19 20:02:14 +0000483 } AH_Hinter;
484
Werner Lembergc3dd1512000-07-26 14:11:15 +0000485
David Turner19ed8af2000-12-08 02:42:29 +0000486FT_END_HEADER
Werner Lembergc713d922000-08-01 13:17:04 +0000487
Werner Lemberg90d99642000-12-09 00:45:38 +0000488#endif /* __AHTYPES_H__ */
Werner Lembergc3dd1512000-07-26 14:11:15 +0000489
490
491/* END */