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