blob: b45366c4798ac7afc30919102762a9dcedd5d95e [file] [log] [blame]
David Turner3469d0d2000-07-19 20:02:14 +00001/***************************************************************************/
2/* */
Werner Lembergc3dd1512000-07-26 14:11:15 +00003/* ahoptim.h */
David Turner3469d0d2000-07-19 20:02:14 +00004/* */
Werner Lembergc3dd1512000-07-26 14:11:15 +00005/* FreeType auto hinting outline optimization (declaration). */
David Turner3469d0d2000-07-19 20:02:14 +00006/* */
Werner Lembergc3dd1512000-07-26 14:11:15 +00007/* Copyright 2000 Catharon Productions Inc. */
David Turner3469d0d2000-07-19 20:02:14 +00008/* 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 */
Werner Lembergc3dd1512000-07-26 14:11:15 +000013/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */
David Turner3469d0d2000-07-19 20:02:14 +000014/* this file you indicate that you have read the license and */
15/* understand and accept it fully. */
16/* */
Werner Lembergc3dd1512000-07-26 14:11:15 +000017/* Note that this license is compatible with the FreeType license. */
David Turner3469d0d2000-07-19 20:02:14 +000018/* */
19/***************************************************************************/
20
Werner Lembergc3dd1512000-07-26 14:11:15 +000021
Werner Lemberg90d99642000-12-09 00:45:38 +000022#ifndef __AHOPTIM_H__
23#define __AHOPTIM_H__
Werner Lembergc3dd1512000-07-26 14:11:15 +000024
Werner Lembergcc069be2000-12-08 16:17:16 +000025
26#include <ft2build.h>
27#include FT_SOURCE_FILE(autohint,ahtypes.h)
28
David Turner3469d0d2000-07-19 20:02:14 +000029
David Turner19ed8af2000-12-08 02:42:29 +000030FT_BEGIN_HEADER
Werner Lembergc713d922000-08-01 13:17:04 +000031
32
Werner Lembergc3dd1512000-07-26 14:11:15 +000033 /* the maximal number of stem configurations to record */
34 /* during optimization */
David Turner3469d0d2000-07-19 20:02:14 +000035#define AH_MAX_CONFIGS 8
36
37
Werner Lembergc3dd1512000-07-26 14:11:15 +000038 typedef struct AH_Stem_
David Turner3469d0d2000-07-19 20:02:14 +000039 {
Werner Lembergc3dd1512000-07-26 14:11:15 +000040 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 */
David Turner3469d0d2000-07-19 20:02:14 +000044
Werner Lembergc3dd1512000-07-26 14:11:15 +000045 FT_Pos min_pos; /* minimum grid position */
46 FT_Pos max_pos; /* maximum grid position */
David Turner3469d0d2000-07-19 20:02:14 +000047
Werner Lembergc3dd1512000-07-26 14:11:15 +000048 AH_Edge* edge1; /* left/bottom edge */
49 AH_Edge* edge2; /* right/top edge */
David Turner3469d0d2000-07-19 20:02:14 +000050
Werner Lembergc3dd1512000-07-26 14:11:15 +000051 FT_Pos opos; /* original position */
52 FT_Pos owidth; /* original width */
David Turner3469d0d2000-07-19 20:02:14 +000053
Werner Lembergc3dd1512000-07-26 14:11:15 +000054 FT_Pos min_coord; /* minimum coordinate */
55 FT_Pos max_coord; /* maximum coordinate */
David Turner3469d0d2000-07-19 20:02:14 +000056
57 } AH_Stem;
58
59
60 /* A spring between two stems */
Werner Lembergc3dd1512000-07-26 14:11:15 +000061 typedef struct AH_Spring_
David Turner3469d0d2000-07-19 20:02:14 +000062 {
63 AH_Stem* stem1;
64 AH_Stem* stem2;
65 FT_Pos owidth; /* original width */
66 FT_Pos tension; /* current tension */
67
68 } AH_Spring;
69
70
71 /* A configuration records the position of each stem at a given time */
Werner Lembergc3dd1512000-07-26 14:11:15 +000072 /* as well as the associated distortion */
David Turner3469d0d2000-07-19 20:02:14 +000073 typedef struct AH_Configuration_
74 {
75 FT_Pos* positions;
Werner Lembergc3dd1512000-07-26 14:11:15 +000076 FT_Long distortion;
David Turner3469d0d2000-07-19 20:02:14 +000077
78 } AH_Configuration;
79
80
Werner Lembergc3dd1512000-07-26 14:11:15 +000081 typedef struct AH_Optimizer_
David Turner3469d0d2000-07-19 20:02:14 +000082 {
Werner Lembergc3dd1512000-07-26 14:11:15 +000083 FT_Memory memory;
84 AH_Outline* outline;
David Turner3469d0d2000-07-19 20:02:14 +000085
Werner Lembergc3dd1512000-07-26 14:11:15 +000086 FT_Int num_hstems;
87 AH_Stem* horz_stems;
David Turner3469d0d2000-07-19 20:02:14 +000088
Werner Lembergc3dd1512000-07-26 14:11:15 +000089 FT_Int num_vstems;
90 AH_Stem* vert_stems;
David Turner3469d0d2000-07-19 20:02:14 +000091
Werner Lembergc3dd1512000-07-26 14:11:15 +000092 FT_Int num_hsprings;
93 FT_Int num_vsprings;
94 AH_Spring* horz_springs;
95 AH_Spring* vert_springs;
David Turner3469d0d2000-07-19 20:02:14 +000096
97 FT_Int num_configs;
Werner Lembergc3dd1512000-07-26 14:11:15 +000098 AH_Configuration configs[AH_MAX_CONFIGS];
David Turner3469d0d2000-07-19 20:02:14 +000099 FT_Pos* positions;
100
101 /* during each pass, use these instead */
Werner Lembergc3dd1512000-07-26 14:11:15 +0000102 FT_Int num_stems;
103 AH_Stem* stems;
David Turner3469d0d2000-07-19 20:02:14 +0000104
Werner Lembergc3dd1512000-07-26 14:11:15 +0000105 FT_Int num_springs;
106 AH_Spring* springs;
107 FT_Bool vertical;
David Turner3469d0d2000-07-19 20:02:14 +0000108
Werner Lembergc3dd1512000-07-26 14:11:15 +0000109 FT_Fixed tension_scale;
110 FT_Pos tension_threshold;
David Turner3469d0d2000-07-19 20:02:14 +0000111
112 } AH_Optimizer;
113
114
115 /* loads the outline into the optimizer */
David Turner3469d0d2000-07-19 20:02:14 +0000116 int AH_Optimizer_Init( AH_Optimizer* optimizer,
117 AH_Outline* outline,
118 FT_Memory memory );
119
120
David Turner3469d0d2000-07-19 20:02:14 +0000121 /* compute optimal outline */
David Turner3469d0d2000-07-19 20:02:14 +0000122 void AH_Optimizer_Compute( AH_Optimizer* optimizer );
123
124
Werner Lembergc3dd1512000-07-26 14:11:15 +0000125 /* release the optimization data */
David Turner3469d0d2000-07-19 20:02:14 +0000126 void AH_Optimizer_Done( AH_Optimizer* optimizer );
127
128
David Turner19ed8af2000-12-08 02:42:29 +0000129FT_END_HEADER
Werner Lembergc713d922000-08-01 13:17:04 +0000130
Werner Lemberg90d99642000-12-09 00:45:38 +0000131#endif /* __AHOPTIM_H__ */
Werner Lembergc3dd1512000-07-26 14:11:15 +0000132
133
134/* END */