Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
cf2hints.h
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* cf2hints.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 
39 #ifndef __CF2HINTS_H__
40 #define __CF2HINTS_H__
41 
42 
44 
45 
46  enum
47  {
48  CF2_MAX_HINTS = 96 /* maximum # of hints */
49  };
50 
51 
52  /*
53  * A HintMask object stores a bit mask that specifies which hints in the
54  * charstring are active at a given time. Hints in CFF must be declared
55  * at the start, before any drawing operators, with horizontal hints
56  * preceding vertical hints. The HintMask is ordered the same way, with
57  * horizontal hints immediately followed by vertical hints. Clients are
58  * responsible for knowing how many of each type are present.
59  *
60  * The maximum total number of hints is 96, as specified by the CFF
61  * specification.
62  *
63  * A HintMask is built 0 or more times while interpreting a charstring, by
64  * the HintMask operator. There is only one HintMask, but it is built or
65  * rebuilt each time there is a hint substitution (HintMask operator) in
66  * the charstring. A default HintMask with all bits set is built if there
67  * has been no HintMask operator prior to the first drawing operator.
68  *
69  */
70 
71  typedef struct CF2_HintMaskRec_
72  {
74 
77 
78  size_t bitCount;
79  size_t byteCount;
80 
81  FT_Byte mask[( CF2_MAX_HINTS + 7 ) / 8];
82 
84 
85 
86  typedef struct CF2_StemHintRec_
87  {
88  FT_Bool used; /* DS positions are valid */
89 
90  CF2_Fixed min; /* original character space value */
92 
93  CF2_Fixed minDS; /* DS position after first use */
95 
97 
98 
99  /*
100  * A HintMap object stores a piecewise linear function for mapping
101  * y-coordinates from character space to device space, providing
102  * appropriate pixel alignment to stem edges.
103  *
104  * The map is implemented as an array of `CF2_Hint' elements, each
105  * representing an edge. When edges are paired, as from stem hints, the
106  * bottom edge must immediately precede the top edge in the array.
107  * Element character space AND device space positions must both increase
108  * monotonically in the array. `CF2_Hint' elements are also used as
109  * parameters to `cf2_blues_capture'.
110  *
111  * The `cf2_hintmap_build' method must be called before any drawing
112  * operation (beginning with a Move operator) and at each hint
113  * substitution (HintMask operator).
114  *
115  * The `cf2_hintmap_map' method is called to transform y-coordinates at
116  * each drawing operation (move, line, curve).
117  *
118  */
119 
120  /* TODO: make this a CF2_ArrStack and add a deep copy method */
121  enum
122  {
124  };
125 
126 
127  typedef struct CF2_HintMapRec_
128  {
130 
131  /* initial map based on blue zones */
133 
134  /* working storage for 2nd pass adjustHints */
136 
139 
142 
143  /* start search from this index */
145 
147 
149 
150 
151  FT_LOCAL( FT_Bool )
152  cf2_hint_isValid( const CF2_Hint hint );
153  FT_LOCAL( FT_Bool )
154  cf2_hint_isTop( const CF2_Hint hint );
155  FT_LOCAL( FT_Bool )
156  cf2_hint_isBottom( const CF2_Hint hint );
157  FT_LOCAL( void )
158  cf2_hint_lock( CF2_Hint hint );
159 
160 
161  FT_LOCAL( void )
162  cf2_hintmap_init( CF2_HintMap hintmap,
163  CF2_Font font,
164  CF2_HintMap initialMap,
166  CF2_Fixed scale );
167  FT_LOCAL( void )
168  cf2_hintmap_build( CF2_HintMap hintmap,
169  CF2_ArrStack hStemHintArray,
170  CF2_ArrStack vStemHintArray,
171  CF2_HintMask hintMask,
172  CF2_Fixed hintOrigin,
173  FT_Bool initialMap );
174 
175 
176  /*
177  * GlyphPath is a wrapper for drawing operations that scales the
178  * coordinates according to the render matrix and HintMap. It also tracks
179  * open paths to control ClosePath and to insert MoveTo for broken fonts.
180  *
181  */
182  typedef struct CF2_GlyphPathRec_
183  {
184  /* TODO: gather some of these into a hinting context */
185 
186  CF2_Font font; /* font instance */
187  CF2_OutlineCallbacks callbacks; /* outline consumer */
188 
189 
190  CF2_HintMapRec hintMap; /* current hint map */
191  CF2_HintMapRec firstHintMap; /* saved copy */
192  CF2_HintMapRec initialHintMap; /* based on all captured hints */
193 
194  CF2_ArrStackRec hintMoves; /* list of hint moves for 2nd pass */
195 
196  CF2_Fixed scaleX; /* matrix a */
197  CF2_Fixed scaleC; /* matrix c */
198  CF2_Fixed scaleY; /* matrix d */
199 
200  FT_Vector fractionalTranslation; /* including deviceXScale */
201 #if 0
202  CF2_Fixed hShift; /* character space horizontal shift */
203  /* (for fauxing) */
204 #endif
205 
206  FT_Bool pathIsOpen; /* true after MoveTo */
207  FT_Bool darken; /* true if stem darkening */
208  FT_Bool moveIsPending; /* true between MoveTo and offset MoveTo */
209 
210  /* references used to call `cf2_hintmap_build', if necessary */
213  CF2_HintMask hintMask; /* ptr to the current mask */
214  CF2_Fixed hintOriginY; /* copy of current origin */
216 
217  CF2_Fixed xOffset; /* character space offsets */
219 
220  /* character space miter limit threshold */
222  /* vertical/horzizontal snap distance in character space */
224 
225  FT_Vector offsetStart0; /* first and second points of first */
226  FT_Vector offsetStart1; /* element with offset applied */
227 
228  /* current point, character space, before offset */
230  /* current point, device space */
232  FT_Vector start; /* start point of subpath */
233 
234  /* the following members constitute the `queue' of one element */
237 
242 
244 
245 
246  FT_LOCAL( void )
247  cf2_glyphpath_init( CF2_GlyphPath glyphpath,
248  CF2_Font font,
249  CF2_OutlineCallbacks callbacks,
250  CF2_Fixed scaleY,
251  /* CF2_Fixed hShift, */
252  CF2_ArrStack hStemHintArray,
253  CF2_ArrStack vStemHintArray,
254  CF2_HintMask hintMask,
255  CF2_Fixed hintOrigin,
256  const CF2_Blues blues,
257  const FT_Vector* fractionalTranslation );
258  FT_LOCAL( void )
259  cf2_glyphpath_finalize( CF2_GlyphPath glyphpath );
260 
261  FT_LOCAL( void )
262  cf2_glyphpath_moveTo( CF2_GlyphPath glyphpath,
263  CF2_Fixed x,
264  CF2_Fixed y );
265  FT_LOCAL( void )
266  cf2_glyphpath_lineTo( CF2_GlyphPath glyphpath,
267  CF2_Fixed x,
268  CF2_Fixed y );
269  FT_LOCAL( void )
270  cf2_glyphpath_curveTo( CF2_GlyphPath glyphpath,
271  CF2_Fixed x1,
272  CF2_Fixed y1,
273  CF2_Fixed x2,
274  CF2_Fixed y2,
275  CF2_Fixed x3,
276  CF2_Fixed y3 );
277  FT_LOCAL( void )
278  cf2_glyphpath_closeOpenPath( CF2_GlyphPath glyphpath );
279 
280 
282 
283 
284 #endif /* __CF2HINTS_H__ */
285 
286 
287 /* END */
#define CF2_Int
Definition: cf2types.h:65
struct CF2_HintMapRec_ CF2_HintMapRec
int FT_Error
Definition: fttypes.h:296
struct CF2_HintMaskRec_ * CF2_HintMask
CF2_Fixed hintOriginY
Definition: cf2hints.h:214
FT_Vector offsetStart1
Definition: cf2hints.h:226
GLenum GLenum GLenum GLenum GLenum scale
CF2_HintMask hintMask
Definition: cf2hints.h:213
CF2_Fixed scaleX
Definition: cf2hints.h:196
cf2_hintmap_build(CF2_HintMap hintmap, CF2_ArrStack hStemHintArray, CF2_ArrStack vStemHintArray, CF2_HintMask hintMask, CF2_Fixed hintOrigin, FT_Bool initialMap)
Definition: cf2hints.c:719
CF2_HintMapRec hintMap
Definition: cf2hints.h:190
cf2_hint_isBottom(const CF2_Hint hint)
Definition: cf2hints.c:248
#define FT_END_HEADER
Definition: ftheader.h:54
cf2_hintmap_init(CF2_HintMap hintmap, CF2_Font font, CF2_HintMap initialMap, CF2_ArrStack hintMoves, CF2_Fixed scale)
Definition: cf2hints.c:277
GLint GLint GLint GLint GLint GLint y
struct CF2_GlyphPathRec_ * CF2_GlyphPath
FT_Bool moveIsPending
Definition: cf2hints.h:208
CF2_Font font
Definition: cf2hints.h:186
struct CF2_HintMaskRec_ CF2_HintMaskRec
CF2_Fixed min
Definition: cf2hints.h:90
CF2_UInt count
Definition: cf2hints.h:141
CF2_Fixed miterLimit
Definition: cf2hints.h:221
CF2_ArrStack hStemHintArray
Definition: cf2hints.h:211
CF2_OutlineCallbacks callbacks
Definition: cf2hints.h:187
const CF2_BluesRec * blues
Definition: cf2hints.h:215
cf2_hint_lock(CF2_Hint hint)
Definition: cf2hints.c:270
CF2_HintMapRec initialHintMap
Definition: cf2hints.h:192
GLint GLint GLint GLint GLint x
CF2_Fixed minDS
Definition: cf2hints.h:93
FT_Bool pathIsOpen
Definition: cf2hints.h:206
cf2_glyphpath_lineTo(CF2_GlyphPath glyphpath, CF2_Fixed x, CF2_Fixed y)
Definition: cf2hints.c:1544
CF2_Fixed scale
Definition: cf2hints.h:140
cf2_glyphpath_closeOpenPath(CF2_GlyphPath glyphpath)
Definition: cf2hints.c:1701
CF2_HintMapRec firstHintMap
Definition: cf2hints.h:191
FT_Bool isValid
Definition: cf2hints.h:75
CF2_ArrStack hintMoves
Definition: cf2hints.h:135
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:104
cf2_glyphpath_curveTo(CF2_GlyphPath glyphpath, CF2_Fixed x1, CF2_Fixed y1, CF2_Fixed x2, CF2_Fixed y2, CF2_Fixed x3, CF2_Fixed y3)
Definition: cf2hints.c:1613
unsigned char FT_Byte
Definition: fttypes.h:150
#define FT_BEGIN_HEADER
Definition: ftheader.h:36
FT_Bool darken
Definition: cf2hints.h:207
FT_Bool isValid
Definition: cf2hints.h:137
struct CF2_HintMapRec_ * CF2_HintMap
CF2_UInt lastIndex
Definition: cf2hints.h:144
cf2_glyphpath_init(CF2_GlyphPath glyphpath, CF2_Font font, CF2_OutlineCallbacks callbacks, CF2_Fixed scaleY, CF2_ArrStack hStemHintArray, CF2_ArrStack vStemHintArray, CF2_HintMask hintMask, CF2_Fixed hintOrigin, const CF2_Blues blues, const FT_Vector *fractionalTranslation)
Definition: cf2hints.c:972
FT_Bool isNew
Definition: cf2hints.h:76
FT_Vector start
Definition: cf2hints.h:232
#define FT_LOCAL(x)
Definition: ftconfig.h:235
GLenum GLint GLuint mask
CF2_HintRec edge[CF2_MAX_HINT_EDGES]
Definition: cf2hints.h:146
CF2_Fixed scaleY
Definition: cf2hints.h:198
cf2_glyphpath_finalize(CF2_GlyphPath glyphpath)
Definition: cf2hints.c:1042
#define CF2_Fixed
Definition: cf2fixed.h:48
CF2_Fixed xOffset
Definition: cf2hints.h:217
FT_BEGIN_HEADER struct CF2_ArrStackRec_ CF2_ArrStackRec
CF2_Font font
Definition: cf2hints.h:129
size_t byteCount
Definition: cf2hints.h:79
FT_Bool elemIsQueued
Definition: cf2hints.h:235
CF2_ArrStack vStemHintArray
Definition: cf2hints.h:212
CF2_Fixed scaleC
Definition: cf2hints.h:197
cf2_hint_isValid(const CF2_Hint hint)
Definition: cf2hints.c:218
FT_Vector currentDS
Definition: cf2hints.h:231
struct CF2_GlyphPathRec_ CF2_GlyphPathRec
CF2_ArrStackRec hintMoves
Definition: cf2hints.h:194
#define CF2_UInt
Definition: cf2types.h:64
FT_Error * error
Definition: cf2hints.h:73
size_t bitCount
Definition: cf2hints.h:78
struct CF2_HintMapRec_ * initialHintMap
Definition: cf2hints.h:132
CF2_Fixed maxDS
Definition: cf2hints.h:94
CF2_Fixed snapThreshold
Definition: cf2hints.h:223
FT_Vector fractionalTranslation
Definition: cf2hints.h:200
FT_Vector prevElemP1
Definition: cf2hints.h:239
FT_Bool used
Definition: cf2hints.h:88
cf2_hint_isTop(const CF2_Hint hint)
Definition: cf2hints.c:240
FT_Vector prevElemP0
Definition: cf2hints.h:238
FT_Vector prevElemP3
Definition: cf2hints.h:241
struct CF2_StemHintRec_ * CF2_StemHint
struct CF2_StemHintRec_ CF2_StemHintRec
cf2_glyphpath_moveTo(CF2_GlyphPath glyphpath, CF2_Fixed x, CF2_Fixed y)
Definition: cf2hints.c:1514
FT_Bool hinted
Definition: cf2hints.h:138
CF2_Int prevElemOp
Definition: cf2hints.h:236
CF2_Fixed yOffset
Definition: cf2hints.h:218
FT_Vector offsetStart0
Definition: cf2hints.h:225
CF2_Fixed max
Definition: cf2hints.h:91
FT_BEGIN_HEADER struct CF2_ArrStackRec_ * CF2_ArrStack
FT_Vector prevElemP2
Definition: cf2hints.h:240
FT_Vector currentCS
Definition: cf2hints.h:229