sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
pshints.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * pshints.h
4 *
5 * Adobe's code for handling CFF hints (body).
6 *
7 * Copyright 2007-2013 Adobe Systems Incorporated.
8 *
9 * This software, and all works of authorship, whether in source or
10 * object code form as indicated by the copyright notice(s) included
11 * herein (collectively, the "Work") is made available, and may only be
12 * used, modified, and distributed under the FreeType Project License,
13 * LICENSE.TXT. Additionally, subject to the terms and conditions of the
14 * FreeType Project License, each contributor to the Work hereby grants
15 * to any individual or legal entity exercising permissions granted by
16 * the FreeType Project License and this section (hereafter, "You" or
17 * "Your") a perpetual, worldwide, non-exclusive, no-charge,
18 * royalty-free, irrevocable (except as stated in this section) patent
19 * license to make, have made, use, offer to sell, sell, import, and
20 * otherwise transfer the Work, where such license applies only to those
21 * patent claims licensable by such contributor that are necessarily
22 * infringed by their contribution(s) alone or by combination of their
23 * contribution(s) with the Work to which such contribution(s) was
24 * submitted. If You institute patent litigation against any entity
25 * (including a cross-claim or counterclaim in a lawsuit) alleging that
26 * the Work or a contribution incorporated within the Work constitutes
27 * direct or contributory patent infringement, then any patent licenses
28 * granted to You under this License for that Work shall terminate as of
29 * the date such litigation is filed.
30 *
31 * By using, modifying, or distributing the Work you indicate that you
32 * have read and understood the terms and conditions of the
33 * FreeType Project License as well as those provided in this section,
34 * and you accept them fully.
35 *
36 */
37
38
43#ifndef PSHINT_H_
44#define PSHINT_H_
45
46FT_BEGIN_HEADER
47
48
49 enum
50 {
51 CF2_MAX_HINTS = 96 /* maximum # of hints */
52 };
53
54
55 /*
56 * A HintMask object stores a bit mask that specifies which hints in the
57 * charstring are active at a given time. Hints in CFF must be declared
58 * at the start, before any drawing operators, with horizontal hints
59 * preceding vertical hints. The HintMask is ordered the same way, with
60 * horizontal hints immediately followed by vertical hints. Clients are
61 * responsible for knowing how many of each type are present.
62 *
63 * The maximum total number of hints is 96, as specified by the CFF
64 * specification.
65 *
66 * A HintMask is built 0 or more times while interpreting a charstring, by
67 * the HintMask operator. There is only one HintMask, but it is built or
68 * rebuilt each time there is a hint substitution (HintMask operator) in
69 * the charstring. A default HintMask with all bits set is built if there
70 * has been no HintMask operator prior to the first drawing operator.
71 *
72 */
73
74 typedef struct CF2_HintMaskRec_
75 {
76 FT_Error* error;
77
78 FT_Bool isValid;
79 FT_Bool isNew;
80
81 size_t bitCount;
82 size_t byteCount;
83
84 FT_Byte mask[( CF2_MAX_HINTS + 7 ) / 8];
85
86 } CF2_HintMaskRec, *CF2_HintMask;
87
88
89 typedef struct CF2_StemHintRec_
90 {
91 FT_Bool used; /* DS positions are valid */
92
93 CF2_Fixed min; /* original character space value */
94 CF2_Fixed max;
95
96 CF2_Fixed minDS; /* DS position after first use */
97 CF2_Fixed maxDS;
98
99 } CF2_StemHintRec, *CF2_StemHint;
100
101
102 /*
103 * A HintMap object stores a piecewise linear function for mapping
104 * y-coordinates from character space to device space, providing
105 * appropriate pixel alignment to stem edges.
106 *
107 * The map is implemented as an array of `CF2_Hint' elements, each
108 * representing an edge. When edges are paired, as from stem hints, the
109 * bottom edge must immediately precede the top edge in the array.
110 * Element character space AND device space positions must both increase
111 * monotonically in the array. `CF2_Hint' elements are also used as
112 * parameters to `cf2_blues_capture'.
113 *
114 * The `cf2_hintmap_build' method must be called before any drawing
115 * operation (beginning with a Move operator) and at each hint
116 * substitution (HintMask operator).
117 *
118 * The `cf2_hintmap_map' method is called to transform y-coordinates at
119 * each drawing operation (move, line, curve).
120 *
121 */
122
123 /* TODO: make this a CF2_ArrStack and add a deep copy method */
124 enum
125 {
126 CF2_MAX_HINT_EDGES = CF2_MAX_HINTS * 2
127 };
128
129
130 typedef struct CF2_HintMapRec_
131 {
132 CF2_Font font;
133
134 /* initial map based on blue zones */
135 struct CF2_HintMapRec_* initialHintMap;
136
137 /* working storage for 2nd pass adjustHints */
138 CF2_ArrStack hintMoves;
139
140 FT_Bool isValid;
141 FT_Bool hinted;
142
143 CF2_Fixed scale;
144 CF2_UInt count;
145
146 /* start search from this index */
147 CF2_UInt lastIndex;
148
149 CF2_HintRec edge[CF2_MAX_HINT_EDGES]; /* 192 */
150
151 } CF2_HintMapRec, *CF2_HintMap;
152
153
154 FT_LOCAL( FT_Bool )
155 cf2_hint_isValid( const CF2_Hint hint );
156 FT_LOCAL( FT_Bool )
157 cf2_hint_isTop( const CF2_Hint hint );
158 FT_LOCAL( FT_Bool )
159 cf2_hint_isBottom( const CF2_Hint hint );
160 FT_LOCAL( void )
161 cf2_hint_lock( CF2_Hint hint );
162
163
164 FT_LOCAL( void )
165 cf2_hintmap_init( CF2_HintMap hintmap,
166 CF2_Font font,
167 CF2_HintMap initialMap,
168 CF2_ArrStack hintMoves,
169 CF2_Fixed scale );
170 FT_LOCAL( void )
171 cf2_hintmap_build( CF2_HintMap hintmap,
172 CF2_ArrStack hStemHintArray,
173 CF2_ArrStack vStemHintArray,
174 CF2_HintMask hintMask,
175 CF2_Fixed hintOrigin,
176 FT_Bool initialMap );
177
178
179 /*
180 * GlyphPath is a wrapper for drawing operations that scales the
181 * coordinates according to the render matrix and HintMap. It also tracks
182 * open paths to control ClosePath and to insert MoveTo for broken fonts.
183 *
184 */
185 typedef struct CF2_GlyphPathRec_
186 {
187 /* TODO: gather some of these into a hinting context */
188
189 CF2_Font font; /* font instance */
190 CF2_OutlineCallbacks callbacks; /* outline consumer */
191
192
193 CF2_HintMapRec hintMap; /* current hint map */
194 CF2_HintMapRec firstHintMap; /* saved copy */
195 CF2_HintMapRec initialHintMap; /* based on all captured hints */
196
197 CF2_ArrStackRec hintMoves; /* list of hint moves for 2nd pass */
198
199 CF2_Fixed scaleX; /* matrix a */
200 CF2_Fixed scaleC; /* matrix c */
201 CF2_Fixed scaleY; /* matrix d */
202
203 FT_Vector fractionalTranslation; /* including deviceXScale */
204#if 0
205 CF2_Fixed hShift; /* character space horizontal shift */
206 /* (for fauxing) */
207#endif
208
209 FT_Bool pathIsOpen; /* true after MoveTo */
210 FT_Bool pathIsClosing; /* true when synthesizing closepath line */
211 FT_Bool darken; /* true if stem darkening */
212 FT_Bool moveIsPending; /* true between MoveTo and offset MoveTo */
213
214 /* references used to call `cf2_hintmap_build', if necessary */
215 CF2_ArrStack hStemHintArray;
216 CF2_ArrStack vStemHintArray;
217 CF2_HintMask hintMask; /* ptr to the current mask */
218 CF2_Fixed hintOriginY; /* copy of current origin */
219 const CF2_BluesRec* blues;
220
221 CF2_Fixed xOffset; /* character space offsets */
222 CF2_Fixed yOffset;
223
224 /* character space miter limit threshold */
225 CF2_Fixed miterLimit;
226 /* vertical/horizontal snap distance in character space */
227 CF2_Fixed snapThreshold;
228
229 FT_Vector offsetStart0; /* first and second points of first */
230 FT_Vector offsetStart1; /* element with offset applied */
231
232 /* current point, character space, before offset */
233 FT_Vector currentCS;
234 /* current point, device space */
235 FT_Vector currentDS;
236 /* start point of subpath, character space */
237 FT_Vector start;
238
239 /* the following members constitute the `queue' of one element */
240 FT_Bool elemIsQueued;
241 CF2_Int prevElemOp;
242
243 FT_Vector prevElemP0;
244 FT_Vector prevElemP1;
245 FT_Vector prevElemP2;
246 FT_Vector prevElemP3;
247
248 } CF2_GlyphPathRec, *CF2_GlyphPath;
249
250
251 FT_LOCAL( void )
252 cf2_glyphpath_init( CF2_GlyphPath glyphpath,
253 CF2_Font font,
254 CF2_OutlineCallbacks callbacks,
255 CF2_Fixed scaleY,
256 /* CF2_Fixed hShift, */
257 CF2_ArrStack hStemHintArray,
258 CF2_ArrStack vStemHintArray,
259 CF2_HintMask hintMask,
260 CF2_Fixed hintOrigin,
261 const CF2_Blues blues,
262 const FT_Vector* fractionalTranslation );
263 FT_LOCAL( void )
264 cf2_glyphpath_finalize( CF2_GlyphPath glyphpath );
265
266 FT_LOCAL( void )
267 cf2_glyphpath_moveTo( CF2_GlyphPath glyphpath,
268 CF2_Fixed x,
269 CF2_Fixed y );
270 FT_LOCAL( void )
271 cf2_glyphpath_lineTo( CF2_GlyphPath glyphpath,
272 CF2_Fixed x,
273 CF2_Fixed y );
274 FT_LOCAL( void )
275 cf2_glyphpath_curveTo( CF2_GlyphPath glyphpath,
276 CF2_Fixed x1,
277 CF2_Fixed y1,
278 CF2_Fixed x2,
279 CF2_Fixed y2,
280 CF2_Fixed x3,
281 CF2_Fixed y3 );
282 FT_LOCAL( void )
283 cf2_glyphpath_closeOpenPath( CF2_GlyphPath glyphpath );
284
285
286FT_END_HEADER
287
288
289#endif /* PSHINT_H_ */
290
291
292/* END */