OLD | NEW |
| (Empty) |
1 /***************************************************************************/ | |
2 /* */ | |
3 /* pshalgo.h */ | |
4 /* */ | |
5 /* PostScript hinting algorithm (specification). */ | |
6 /* */ | |
7 /* Copyright 2001-2003, 2008, 2013 by */ | |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | |
9 /* */ | |
10 /* This file is part of the FreeType project, and may only be used, */ | |
11 /* modified, and distributed under the terms of the FreeType project */ | |
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | |
13 /* this file you indicate that you have read the license and */ | |
14 /* understand and accept it fully. */ | |
15 /* */ | |
16 /***************************************************************************/ | |
17 | |
18 | |
19 #ifndef __PSHALGO_H__ | |
20 #define __PSHALGO_H__ | |
21 | |
22 | |
23 #include "pshrec.h" | |
24 #include "pshglob.h" | |
25 | |
26 | |
27 FT_BEGIN_HEADER | |
28 | |
29 | |
30 /* handle to Hint structure */ | |
31 typedef struct PSH_HintRec_* PSH_Hint; | |
32 | |
33 /* hint bit-flags */ | |
34 typedef enum PSH_Hint_Flags_ | |
35 { | |
36 PSH_HINT_GHOST = PS_HINT_FLAG_GHOST, | |
37 PSH_HINT_BOTTOM = PS_HINT_FLAG_BOTTOM, | |
38 PSH_HINT_ACTIVE = 4, | |
39 PSH_HINT_FITTED = 8 | |
40 | |
41 } PSH_Hint_Flags; | |
42 | |
43 | |
44 #define psh_hint_is_active( x ) ( ( (x)->flags & PSH_HINT_ACTIVE ) != 0 ) | |
45 #define psh_hint_is_ghost( x ) ( ( (x)->flags & PSH_HINT_GHOST ) != 0 ) | |
46 #define psh_hint_is_fitted( x ) ( ( (x)->flags & PSH_HINT_FITTED ) != 0 ) | |
47 | |
48 #define psh_hint_activate( x ) (x)->flags |= PSH_HINT_ACTIVE | |
49 #define psh_hint_deactivate( x ) (x)->flags &= ~PSH_HINT_ACTIVE | |
50 #define psh_hint_set_fitted( x ) (x)->flags |= PSH_HINT_FITTED | |
51 | |
52 /* hint structure */ | |
53 typedef struct PSH_HintRec_ | |
54 { | |
55 FT_Int org_pos; | |
56 FT_Int org_len; | |
57 FT_Pos cur_pos; | |
58 FT_Pos cur_len; | |
59 FT_UInt flags; | |
60 PSH_Hint parent; | |
61 FT_Int order; | |
62 | |
63 } PSH_HintRec; | |
64 | |
65 | |
66 /* this is an interpolation zone used for strong points; */ | |
67 /* weak points are interpolated according to their strong */ | |
68 /* neighbours */ | |
69 typedef struct PSH_ZoneRec_ | |
70 { | |
71 FT_Fixed scale; | |
72 FT_Fixed delta; | |
73 FT_Pos min; | |
74 FT_Pos max; | |
75 | |
76 } PSH_ZoneRec, *PSH_Zone; | |
77 | |
78 | |
79 typedef struct PSH_Hint_TableRec_ | |
80 { | |
81 FT_UInt max_hints; | |
82 FT_UInt num_hints; | |
83 PSH_Hint hints; | |
84 PSH_Hint* sort; | |
85 PSH_Hint* sort_global; | |
86 FT_UInt num_zones; | |
87 PSH_ZoneRec* zones; | |
88 PSH_Zone zone; | |
89 PS_Mask_Table hint_masks; | |
90 PS_Mask_Table counter_masks; | |
91 | |
92 } PSH_Hint_TableRec, *PSH_Hint_Table; | |
93 | |
94 | |
95 typedef struct PSH_PointRec_* PSH_Point; | |
96 typedef struct PSH_ContourRec_* PSH_Contour; | |
97 | |
98 enum | |
99 { | |
100 PSH_DIR_NONE = 4, | |
101 PSH_DIR_UP = -1, | |
102 PSH_DIR_DOWN = 1, | |
103 PSH_DIR_LEFT = -2, | |
104 PSH_DIR_RIGHT = 2 | |
105 }; | |
106 | |
107 #define PSH_DIR_HORIZONTAL 2 | |
108 #define PSH_DIR_VERTICAL 1 | |
109 | |
110 #define PSH_DIR_COMPARE( d1, d2 ) ( (d1) == (d2) || (d1) == -(d2) ) | |
111 #define PSH_DIR_IS_HORIZONTAL( d ) PSH_DIR_COMPARE( d, PSH_DIR_HORIZONTAL ) | |
112 #define PSH_DIR_IS_VERTICAL( d ) PSH_DIR_COMPARE( d, PSH_DIR_VERTICAL ) | |
113 | |
114 | |
115 /* the following bit-flags are computed once by the glyph */ | |
116 /* analyzer, for both dimensions */ | |
117 enum | |
118 { | |
119 PSH_POINT_OFF = 1, /* point is off the curve */ | |
120 PSH_POINT_SMOOTH = 2, /* point is smooth */ | |
121 PSH_POINT_INFLEX = 4 /* point is inflection */ | |
122 }; | |
123 | |
124 #define psh_point_is_smooth( p ) ( (p)->flags & PSH_POINT_SMOOTH ) | |
125 #define psh_point_is_off( p ) ( (p)->flags & PSH_POINT_OFF ) | |
126 #define psh_point_is_inflex( p ) ( (p)->flags & PSH_POINT_INFLEX ) | |
127 | |
128 #define psh_point_set_smooth( p ) (p)->flags |= PSH_POINT_SMOOTH | |
129 #define psh_point_set_off( p ) (p)->flags |= PSH_POINT_OFF | |
130 #define psh_point_set_inflex( p ) (p)->flags |= PSH_POINT_INFLEX | |
131 | |
132 /* the following bit-flags are re-computed for each dimension */ | |
133 enum | |
134 { | |
135 PSH_POINT_STRONG = 16, /* point is strong */ | |
136 PSH_POINT_FITTED = 32, /* point is already fitted */ | |
137 PSH_POINT_EXTREMUM = 64, /* point is local extremum */ | |
138 PSH_POINT_POSITIVE = 128, /* extremum has positive contour flow */ | |
139 PSH_POINT_NEGATIVE = 256, /* extremum has negative contour flow */ | |
140 PSH_POINT_EDGE_MIN = 512, /* point is aligned to left/bottom stem edge */ | |
141 PSH_POINT_EDGE_MAX = 1024 /* point is aligned to top/right stem edge */ | |
142 }; | |
143 | |
144 #define psh_point_is_strong( p ) ( (p)->flags2 & PSH_POINT_STRONG ) | |
145 #define psh_point_is_fitted( p ) ( (p)->flags2 & PSH_POINT_FITTED ) | |
146 #define psh_point_is_extremum( p ) ( (p)->flags2 & PSH_POINT_EXTREMUM ) | |
147 #define psh_point_is_positive( p ) ( (p)->flags2 & PSH_POINT_POSITIVE ) | |
148 #define psh_point_is_negative( p ) ( (p)->flags2 & PSH_POINT_NEGATIVE ) | |
149 #define psh_point_is_edge_min( p ) ( (p)->flags2 & PSH_POINT_EDGE_MIN ) | |
150 #define psh_point_is_edge_max( p ) ( (p)->flags2 & PSH_POINT_EDGE_MAX ) | |
151 | |
152 #define psh_point_set_strong( p ) (p)->flags2 |= PSH_POINT_STRONG | |
153 #define psh_point_set_fitted( p ) (p)->flags2 |= PSH_POINT_FITTED | |
154 #define psh_point_set_extremum( p ) (p)->flags2 |= PSH_POINT_EXTREMUM | |
155 #define psh_point_set_positive( p ) (p)->flags2 |= PSH_POINT_POSITIVE | |
156 #define psh_point_set_negative( p ) (p)->flags2 |= PSH_POINT_NEGATIVE | |
157 #define psh_point_set_edge_min( p ) (p)->flags2 |= PSH_POINT_EDGE_MIN | |
158 #define psh_point_set_edge_max( p ) (p)->flags2 |= PSH_POINT_EDGE_MAX | |
159 | |
160 | |
161 typedef struct PSH_PointRec_ | |
162 { | |
163 PSH_Point prev; | |
164 PSH_Point next; | |
165 PSH_Contour contour; | |
166 FT_UInt flags; | |
167 FT_UInt flags2; | |
168 FT_Char dir_in; | |
169 FT_Char dir_out; | |
170 PSH_Hint hint; | |
171 FT_Pos org_u; | |
172 FT_Pos org_v; | |
173 FT_Pos cur_u; | |
174 #ifdef DEBUG_HINTER | |
175 FT_Pos org_x; | |
176 FT_Pos cur_x; | |
177 FT_Pos org_y; | |
178 FT_Pos cur_y; | |
179 FT_UInt flags_x; | |
180 FT_UInt flags_y; | |
181 #endif | |
182 | |
183 } PSH_PointRec; | |
184 | |
185 | |
186 typedef struct PSH_ContourRec_ | |
187 { | |
188 PSH_Point start; | |
189 FT_UInt count; | |
190 | |
191 } PSH_ContourRec; | |
192 | |
193 | |
194 typedef struct PSH_GlyphRec_ | |
195 { | |
196 FT_UInt num_points; | |
197 FT_UInt num_contours; | |
198 | |
199 PSH_Point points; | |
200 PSH_Contour contours; | |
201 | |
202 FT_Memory memory; | |
203 FT_Outline* outline; | |
204 PSH_Globals globals; | |
205 PSH_Hint_TableRec hint_tables[2]; | |
206 | |
207 FT_Bool vertical; | |
208 FT_Int major_dir; | |
209 FT_Int minor_dir; | |
210 | |
211 FT_Bool do_horz_hints; | |
212 FT_Bool do_vert_hints; | |
213 FT_Bool do_horz_snapping; | |
214 FT_Bool do_vert_snapping; | |
215 FT_Bool do_stem_adjust; | |
216 | |
217 } PSH_GlyphRec, *PSH_Glyph; | |
218 | |
219 | |
220 #ifdef DEBUG_HINTER | |
221 extern PSH_Hint_Table ps_debug_hint_table; | |
222 | |
223 typedef void | |
224 (*PSH_HintFunc)( PSH_Hint hint, | |
225 FT_Bool vertical ); | |
226 | |
227 extern PSH_HintFunc ps_debug_hint_func; | |
228 | |
229 extern PSH_Glyph ps_debug_glyph; | |
230 #endif | |
231 | |
232 | |
233 extern FT_Error | |
234 ps_hints_apply( PS_Hints ps_hints, | |
235 FT_Outline* outline, | |
236 PSH_Globals globals, | |
237 FT_Render_Mode hint_mode ); | |
238 | |
239 | |
240 FT_END_HEADER | |
241 | |
242 | |
243 #endif /* __PSHALGO_H__ */ | |
244 | |
245 | |
246 /* END */ | |
OLD | NEW |