1 /***************************************************************************/
2 /* */
3 /* ahoptim.h */
4 /* */
5 /* FreeType auto hinting outline optimization (declaration). */
6 /* */
7 /* Copyright 2000-2001 Catharon Productions Inc. */
8 /* Author: David Turner */
9 /* */
10 /* This file is part of the Catharon Typography Project and shall only */
11 /* be used, modified, and distributed under the terms of the Catharon */
12 /* Open Source License that should come with this file under the name */
13 /* `CatharonLicense.txt'. By continuing to use, modify, or distribute */
14 /* this file you indicate that you have read the license and */
15 /* understand and accept it fully. */
16 /* */
17 /* Note that this license is compatible with the FreeType license. */
18 /* */
19 /***************************************************************************/
22 #ifndef __AHOPTIM_H__
23 #define __AHOPTIM_H__
26 #include <ft2build.h>
27 #include "ahtypes.h"
30 FT_BEGIN_HEADER
33 /* the maximal number of stem configurations to record */
34 /* during optimization */
35 #define AH_MAX_CONFIGS 8
38 typedef struct AH_Stem_
39 {
40 FT_Pos pos; /* current position */
41 FT_Pos velocity; /* current velocity */
42 FT_Pos force; /* sum of current forces */
43 FT_Pos width; /* normalized width */
45 FT_Pos min_pos; /* minimum grid position */
46 FT_Pos max_pos; /* maximum grid position */
48 AH_Edge* edge1; /* left/bottom edge */
49 AH_Edge* edge2; /* right/top edge */
51 FT_Pos opos; /* original position */
52 FT_Pos owidth; /* original width */
54 FT_Pos min_coord; /* minimum coordinate */
55 FT_Pos max_coord; /* maximum coordinate */
57 } AH_Stem;
60 /* A spring between two stems */
61 typedef struct AH_Spring_
62 {
63 AH_Stem* stem1;
64 AH_Stem* stem2;
65 FT_Pos owidth; /* original width */
66 FT_Pos tension; /* current tension */
68 } AH_Spring;
71 /* A configuration records the position of each stem at a given time */
72 /* as well as the associated distortion */
73 typedef struct AH_Configuration_
74 {
75 FT_Pos* positions;
76 FT_Long distortion;
78 } AH_Configuration;
81 typedef struct AH_Optimizer_
82 {
83 FT_Memory memory;
84 AH_Outline* outline;
86 FT_Int num_hstems;
87 AH_Stem* horz_stems;
89 FT_Int num_vstems;
90 AH_Stem* vert_stems;
92 FT_Int num_hsprings;
93 FT_Int num_vsprings;
94 AH_Spring* horz_springs;
95 AH_Spring* vert_springs;
97 FT_Int num_configs;
98 AH_Configuration configs[AH_MAX_CONFIGS];
99 FT_Pos* positions;
101 /* during each pass, use these instead */
102 FT_Int num_stems;
103 AH_Stem* stems;
105 FT_Int num_springs;
106 AH_Spring* springs;
107 FT_Bool vertical;
109 FT_Fixed tension_scale;
110 FT_Pos tension_threshold;
112 } AH_Optimizer;
115 /* loads the outline into the optimizer */
116 int
117 AH_Optimizer_Init( AH_Optimizer* optimizer,
118 AH_Outline* outline,
119 FT_Memory memory );
122 /* compute optimal outline */
123 void
124 AH_Optimizer_Compute( AH_Optimizer* optimizer );
127 /* release the optimization data */
128 void
129 AH_Optimizer_Done( AH_Optimizer* optimizer );
132 FT_END_HEADER
134 #endif /* __AHOPTIM_H__ */
137 /* END */