| OLD | NEW |
| (Empty) |
| 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 | |
| 43 FT_BEGIN_HEADER | |
| 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 { | |
| 73 FT_Error* error; | |
| 74 | |
| 75 FT_Bool isValid; | |
| 76 FT_Bool isNew; | |
| 77 | |
| 78 size_t bitCount; | |
| 79 size_t byteCount; | |
| 80 | |
| 81 FT_Byte mask[( CF2_MAX_HINTS + 7 ) / 8]; | |
| 82 | |
| 83 } CF2_HintMaskRec, *CF2_HintMask; | |
| 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 */ | |
| 91 CF2_Fixed max; | |
| 92 | |
| 93 CF2_Fixed minDS; /* DS position after first use */ | |
| 94 CF2_Fixed maxDS; | |
| 95 | |
| 96 } CF2_StemHintRec, *CF2_StemHint; | |
| 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 { | |
| 123 CF2_MAX_HINT_EDGES = CF2_MAX_HINTS * 2 | |
| 124 }; | |
| 125 | |
| 126 | |
| 127 typedef struct CF2_HintMapRec_ | |
| 128 { | |
| 129 CF2_Font font; | |
| 130 | |
| 131 /* initial map based on blue zones */ | |
| 132 struct CF2_HintMapRec_* initialHintMap; | |
| 133 | |
| 134 /* working storage for 2nd pass adjustHints */ | |
| 135 CF2_ArrStack hintMoves; | |
| 136 | |
| 137 FT_Bool isValid; | |
| 138 FT_Bool hinted; | |
| 139 | |
| 140 CF2_Fixed scale; | |
| 141 CF2_UInt count; | |
| 142 | |
| 143 /* start search from this index */ | |
| 144 CF2_UInt lastIndex; | |
| 145 | |
| 146 CF2_HintRec edge[CF2_MAX_HINT_EDGES]; /* 192 */ | |
| 147 | |
| 148 } CF2_HintMapRec, *CF2_HintMap; | |
| 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, | |
| 165 CF2_ArrStack hintMoves, | |
| 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 */ | |
| 211 CF2_ArrStack hStemHintArray; | |
| 212 CF2_ArrStack vStemHintArray; | |
| 213 CF2_HintMask hintMask; /* ptr to the current mask */ | |
| 214 CF2_Fixed hintOriginY; /* copy of current origin */ | |
| 215 const CF2_BluesRec* blues; | |
| 216 | |
| 217 CF2_Fixed xOffset; /* character space offsets */ | |
| 218 CF2_Fixed yOffset; | |
| 219 | |
| 220 /* character space miter limit threshold */ | |
| 221 CF2_Fixed miterLimit; | |
| 222 /* vertical/horzizontal snap distance in character space */ | |
| 223 CF2_Fixed snapThreshold; | |
| 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 */ | |
| 229 FT_Vector currentCS; | |
| 230 /* current point, device space */ | |
| 231 FT_Vector currentDS; | |
| 232 FT_Vector start; /* start point of subpath */ | |
| 233 | |
| 234 /* the following members constitute the `queue' of one element */ | |
| 235 FT_Bool elemIsQueued; | |
| 236 CF2_Int prevElemOp; | |
| 237 | |
| 238 FT_Vector prevElemP0; | |
| 239 FT_Vector prevElemP1; | |
| 240 FT_Vector prevElemP2; | |
| 241 FT_Vector prevElemP3; | |
| 242 | |
| 243 } CF2_GlyphPathRec, *CF2_GlyphPath; | |
| 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 | |
| 281 FT_END_HEADER | |
| 282 | |
| 283 | |
| 284 #endif /* __CF2HINTS_H__ */ | |
| 285 | |
| 286 | |
| 287 /* END */ | |
| OLD | NEW |