1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
/***************************************************************************/
/* */
/* pshalgo3.h */
/* */
/* PostScript hinting algorithm 3 (specification). */
/* */
/* Copyright 2001, 2002 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
#ifndef __PSHALGO3_H__
#define __PSHALGO3_H__
#include "pshrec.h"
#include "pshglob.h"
#include FT_TRIGONOMETRY_H
FT_BEGIN_HEADER
/* handle to Hint structure */
typedef struct PSH3_HintRec_* PSH3_Hint;
/* hint bit-flags */
typedef enum
{
PSH3_HINT_GHOST = PS_HINT_FLAG_GHOST,
PSH3_HINT_BOTTOM = PS_HINT_FLAG_BOTTOM,
PSH3_HINT_ACTIVE = 4,
PSH3_HINT_FITTED = 8
} PSH3_Hint_Flags;
#define psh3_hint_is_active( x ) ( ( (x)->flags & PSH3_HINT_ACTIVE ) != 0 )
#define psh3_hint_is_ghost( x ) ( ( (x)->flags & PSH3_HINT_GHOST ) != 0 )
#define psh3_hint_is_fitted( x ) ( ( (x)->flags & PSH3_HINT_FITTED ) != 0 )
#define psh3_hint_activate( x ) (x)->flags |= PSH3_HINT_ACTIVE
#define psh3_hint_deactivate( x ) (x)->flags &= ~PSH3_HINT_ACTIVE
#define psh3_hint_set_fitted( x ) (x)->flags |= PSH3_HINT_FITTED
/* hint structure */
typedef struct PSH3_HintRec_
{
FT_Int org_pos;
FT_Int org_len;
FT_Pos cur_pos;
FT_Pos cur_len;
FT_UInt flags;
PSH3_Hint parent;
FT_Int order;
} PSH3_HintRec;
/* this is an interpolation zone used for strong points; */
/* weak points are interpolated according to their strong */
/* neighbours */
typedef struct PSH3_ZoneRec_
{
FT_Fixed scale;
FT_Fixed delta;
FT_Pos min;
FT_Pos max;
} PSH3_ZoneRec, *PSH3_Zone;
typedef struct PSH3_Hint_TableRec_
{
FT_UInt max_hints;
FT_UInt num_hints;
PSH3_Hint hints;
PSH3_Hint* sort;
PSH3_Hint* sort_global;
FT_UInt num_zones;
PSH3_ZoneRec* zones;
PSH3_Zone zone;
PS_Mask_Table hint_masks;
PS_Mask_Table counter_masks;
} PSH3_Hint_TableRec, *PSH3_Hint_Table;
typedef struct PSH3_PointRec_* PSH3_Point;
typedef struct PSH3_ContourRec_* PSH3_Contour;
enum
{
PSH3_DIR_NONE = 4,
PSH3_DIR_UP = -1,
PSH3_DIR_DOWN = 1,
PSH3_DIR_LEFT = -2,
PSH3_DIR_RIGHT = 2
};
#define PSH3_DIR_HORIZONTAL 2
#define PSH3_DIR_VERTICAL 1
#define PSH3_DIR_COMPARE( d1, d2 ) ( (d1) == (d2) || (d1) == -(d2) )
#define PSH3_DIR_IS_HORIZONTAL( d ) PSH3_DIR_COMPARE( d, PSH3_DIR_HORIZONTAL )
#define PSH3_DIR_IS_VERTICAL( d ) PSH3_DIR_COMPARE( d, PSH3_DIR_VERTICAL )
/* the following bit-flags are computed once by the glyph */
/* analyzer, for both dimensions */
enum
{
PSH3_POINT_OFF = 1, /* point is off the curve */
PSH3_POINT_SMOOTH = 2, /* point is smooth */
PSH3_POINT_INFLEX = 4 /* point is inflection */
};
#define psh3_point_is_smooth( p ) ( (p)->flags & PSH3_POINT_SMOOTH )
#define psh3_point_is_off( p ) ( (p)->flags & PSH3_POINT_OFF )
#define psh3_point_is_inflex( p ) ( (p)->flags & PSH3_POINT_INFLEX )
#define psh3_point_set_smooth( p ) (p)->flags |= PSH3_POINT_SMOOTH
#define psh3_point_set_off( p ) (p)->flags |= PSH3_POINT_OFF
#define psh3_point_set_inflex( p ) (p)->flags |= PSH3_POINT_INFLEX
/* the following bit-flags are re-computed for each dimension */
enum
{
PSH3_POINT_STRONG = 16, /* point is strong */
PSH3_POINT_FITTED = 32, /* point is already fitted */
PSH3_POINT_EXTREMUM = 64, /* point is local extremum */
PSH3_POINT_POSITIVE = 128, /* extremum has positive contour flow */
PSH3_POINT_NEGATIVE = 256, /* extremum has negative contour flow */
PSH3_POINT_EDGE_MIN = 512, /* point is aligned to left/bottom stem edge */
PSH3_POINT_EDGE_MAX = 1024 /* point is aligned to top/right stem edge */
};
#define psh3_point_is_strong( p ) ( (p)->flags2 & PSH3_POINT_STRONG )
#define psh3_point_is_fitted( p ) ( (p)->flags2 & PSH3_POINT_FITTED )
#define psh3_point_is_extremum( p ) ( (p)->flags2 & PSH3_POINT_EXTREMUM )
#define psh3_point_is_positive( p ) ( (p)->flags2 & PSH3_POINT_POSITIVE )
#define psh3_point_is_negative( p ) ( (p)->flags2 & PSH3_POINT_NEGATIVE )
#define psh3_point_is_edge_min( p ) ( (p)->flags2 & PSH3_POINT_EDGE_MIN )
#define psh3_point_is_edge_max( p ) ( (p)->flags2 & PSH3_POINT_EDGE_MAX )
#define psh3_point_set_strong( p ) (p)->flags2 |= PSH3_POINT_STRONG
#define psh3_point_set_fitted( p ) (p)->flags2 |= PSH3_POINT_FITTED
#define psh3_point_set_extremum( p ) (p)->flags2 |= PSH3_POINT_EXTREMUM
#define psh3_point_set_positive( p ) (p)->flags2 |= PSH3_POINT_POSITIVE
#define psh3_point_set_negative( p ) (p)->flags2 |= PSH3_POINT_NEGATIVE
#define psh3_point_set_edge_min( p ) (p)->flags2 |= PSH3_POINT_EDGE_MIN
#define psh3_point_set_edge_max( p ) (p)->flags2 |= PSH3_POINT_EDGE_MAX
typedef struct PSH3_PointRec_
{
PSH3_Point prev;
PSH3_Point next;
PSH3_Contour contour;
FT_UInt flags;
FT_UInt flags2;
FT_Char dir_in;
FT_Char dir_out;
FT_Angle angle_in;
FT_Angle angle_out;
PSH3_Hint hint;
FT_Pos org_u;
FT_Pos org_v;
FT_Pos cur_u;
#ifdef DEBUG_HINTER
FT_Pos org_x;
FT_Pos cur_x;
FT_Pos org_y;
FT_Pos cur_y;
FT_UInt flags_x;
FT_UInt flags_y;
#endif
} PSH3_PointRec;
#define PSH3_POINT_EQUAL_ORG( a, b ) ( (a)->org_u == (b)->org_u && \
(a)->org_v == (b)->org_v )
#define PSH3_POINT_ANGLE( a, b ) FT_Atan2( (b)->org_u - (a)->org_u, \
(b)->org_v - (a)->org_v )
typedef struct PSH3_ContourRec_
{
PSH3_Point start;
FT_UInt count;
} PSH3_ContourRec;
typedef struct PSH3_GlyphRec_
{
FT_UInt num_points;
FT_UInt num_contours;
PSH3_Point points;
PSH3_Contour contours;
FT_Memory memory;
FT_Outline* outline;
PSH_Globals globals;
PSH3_Hint_TableRec hint_tables[2];
FT_Bool vertical;
FT_Int major_dir;
FT_Int minor_dir;
FT_Bool do_horz_hints;
FT_Bool do_vert_hints;
FT_Bool do_horz_snapping;
FT_Bool do_vert_snapping;
} PSH3_GlyphRec, *PSH3_Glyph;
#ifdef DEBUG_HINTER
extern PSH3_Hint_Table ps3_debug_hint_table;
typedef void
(*PSH3_HintFunc)( PSH3_Hint hint,
FT_Bool vertical );
extern PSH3_HintFunc ps3_debug_hint_func;
extern PSH3_Glyph ps3_debug_glyph;
#endif
extern FT_Error
ps3_hints_apply( PS_Hints ps_hints,
FT_Outline* outline,
PSH_Globals globals,
FT_Render_Mode hint_mode );
FT_END_HEADER
#endif /* __PSHALGO3_H__ */
/* END */
|