1 /***************************************************************************/ 2 /* */ 3 /* ttobjs.h */ 4 /* */ 5 /* Objects manager (specification). */ 6 /* */ 7 /* Copyright 1996-2016 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 TTOBJS_H_ 20 #define TTOBJS_H_ 21 22 23 #include <ft2build.h> 24 #include FT_INTERNAL_OBJECTS_H 25 #include FT_INTERNAL_TRUETYPE_TYPES_H 26 27 28 FT_BEGIN_HEADER 29 30 31 /*************************************************************************/ 32 /* */ 33 /* <Type> */ 34 /* TT_Driver */ 35 /* */ 36 /* <Description> */ 37 /* A handle to a TrueType driver object. */ 38 /* */ 39 typedef struct TT_DriverRec_* TT_Driver; 40 41 42 /*************************************************************************/ 43 /* */ 44 /* <Type> */ 45 /* TT_GlyphSlot */ 46 /* */ 47 /* <Description> */ 48 /* A handle to a TrueType glyph slot object. */ 49 /* */ 50 /* <Note> */ 51 /* This is a direct typedef of FT_GlyphSlot, as there is nothing */ 52 /* specific about the TrueType glyph slot. */ 53 /* */ 54 typedef FT_GlyphSlot TT_GlyphSlot; 55 56 57 /*************************************************************************/ 58 /* */ 59 /* <Struct> */ 60 /* TT_GraphicsState */ 61 /* */ 62 /* <Description> */ 63 /* The TrueType graphics state used during bytecode interpretation. */ 64 /* */ 65 typedef struct TT_GraphicsState_ 66 { 67 FT_UShort rp0; 68 FT_UShort rp1; 69 FT_UShort rp2; 70 71 FT_UnitVector dualVector; 72 FT_UnitVector projVector; 73 FT_UnitVector freeVector; 74 75 FT_Long loop; 76 FT_F26Dot6 minimum_distance; 77 FT_Int round_state; 78 79 FT_Bool auto_flip; 80 FT_F26Dot6 control_value_cutin; 81 FT_F26Dot6 single_width_cutin; 82 FT_F26Dot6 single_width_value; 83 FT_UShort delta_base; 84 FT_UShort delta_shift; 85 86 FT_Byte instruct_control; 87 /* According to Greg Hitchcock from Microsoft, the `scan_control' */ 88 /* variable as documented in the TrueType specification is a 32-bit */ 89 /* integer; the high-word part holds the SCANTYPE value, the low-word */ 90 /* part the SCANCTRL value. We separate it into two fields. */ 91 FT_Bool scan_control; 92 FT_Int scan_type; 93 94 FT_UShort gep0; 95 FT_UShort gep1; 96 FT_UShort gep2; 97 98 } TT_GraphicsState; 99 100 101 #ifdef TT_USE_BYTECODE_INTERPRETER 102 103 FT_LOCAL( void ) 104 tt_glyphzone_done( TT_GlyphZone zone ); 105 106 FT_LOCAL( FT_Error ) 107 tt_glyphzone_new( FT_Memory memory, 108 FT_UShort maxPoints, 109 FT_Short maxContours, 110 TT_GlyphZone zone ); 111 112 #endif /* TT_USE_BYTECODE_INTERPRETER */ 113 114 115 116 /*************************************************************************/ 117 /* */ 118 /* EXECUTION SUBTABLES */ 119 /* */ 120 /* These sub-tables relate to instruction execution. */ 121 /* */ 122 /*************************************************************************/ 123 124 125 #define TT_MAX_CODE_RANGES 3 126 127 128 /*************************************************************************/ 129 /* */ 130 /* There can only be 3 active code ranges at once: */ 131 /* - the Font Program */ 132 /* - the CVT Program */ 133 /* - a glyph's instructions set */ 134 /* */ 135 typedef enum TT_CodeRange_Tag_ 136 { 137 tt_coderange_none = 0, 138 tt_coderange_font, 139 tt_coderange_cvt, 140 tt_coderange_glyph 141 142 } TT_CodeRange_Tag; 143 144 145 typedef struct TT_CodeRange_ 146 { 147 FT_Byte* base; 148 FT_Long size; 149 150 } TT_CodeRange; 151 152 typedef TT_CodeRange TT_CodeRangeTable[TT_MAX_CODE_RANGES]; 153 154 155 /*************************************************************************/ 156 /* */ 157 /* Defines a function/instruction definition record. */ 158 /* */ 159 typedef struct TT_DefRecord_ 160 { 161 FT_Int range; /* in which code range is it located? */ 162 FT_Long start; /* where does it start? */ 163 FT_Long end; /* where does it end? */ 164 FT_UInt opc; /* function #, or instruction code */ 165 FT_Bool active; /* is it active? */ 166 FT_Bool inline_delta; /* is function that defines inline delta? */ 167 FT_ULong sph_fdef_flags; /* flags to identify special functions */ 168 169 } TT_DefRecord, *TT_DefArray; 170 171 172 /*************************************************************************/ 173 /* */ 174 /* Subglyph transformation record. */ 175 /* */ 176 typedef struct TT_Transform_ 177 { 178 FT_Fixed xx, xy; /* transformation matrix coefficients */ 179 FT_Fixed yx, yy; 180 FT_F26Dot6 ox, oy; /* offsets */ 181 182 } TT_Transform; 183 184 185 /*************************************************************************/ 186 /* */ 187 /* A note regarding non-squared pixels: */ 188 /* */ 189 /* (This text will probably go into some docs at some time; for now, it */ 190 /* is kept here to explain some definitions in the TT_Size_Metrics */ 191 /* record). */ 192 /* */ 193 /* The CVT is a one-dimensional array containing values that control */ 194 /* certain important characteristics in a font, like the height of all */ 195 /* capitals, all lowercase letter, default spacing or stem width/height. */ 196 /* */ 197 /* These values are found in FUnits in the font file, and must be scaled */ 198 /* to pixel coordinates before being used by the CVT and glyph programs. */ 199 /* Unfortunately, when using distinct x and y resolutions (or distinct x */ 200 /* and y pointsizes), there are two possible scalings. */ 201 /* */ 202 /* A first try was to implement a `lazy' scheme where all values were */ 203 /* scaled when first used. However, while some values are always used */ 204 /* in the same direction, some others are used under many different */ 205 /* circumstances and orientations. */ 206 /* */ 207 /* I have found a simpler way to do the same, and it even seems to work */ 208 /* in most of the cases: */ 209 /* */ 210 /* - All CVT values are scaled to the maximum ppem size. */ 211 /* */ 212 /* - When performing a read or write in the CVT, a ratio factor is used */ 213 /* to perform adequate scaling. Example: */ 214 /* */ 215 /* x_ppem = 14 */ 216 /* y_ppem = 10 */ 217 /* */ 218 /* We choose ppem = x_ppem = 14 as the CVT scaling size. All cvt */ 219 /* entries are scaled to it. */ 220 /* */ 221 /* x_ratio = 1.0 */ 222 /* y_ratio = y_ppem/ppem (< 1.0) */ 223 /* */ 224 /* We compute the current ratio like: */ 225 /* */ 226 /* - If projVector is horizontal, */ 227 /* ratio = x_ratio = 1.0 */ 228 /* */ 229 /* - if projVector is vertical, */ 230 /* ratio = y_ratio */ 231 /* */ 232 /* - else, */ 233 /* ratio = sqrt( (proj.x * x_ratio) ^ 2 + (proj.y * y_ratio) ^ 2 ) */ 234 /* */ 235 /* Reading a cvt value returns */ 236 /* ratio * cvt[index] */ 237 /* */ 238 /* Writing a cvt value in pixels: */ 239 /* cvt[index] / ratio */ 240 /* */ 241 /* The current ppem is simply */ 242 /* ratio * ppem */ 243 /* */ 244 /*************************************************************************/ 245 246 247 /*************************************************************************/ 248 /* */ 249 /* Metrics used by the TrueType size and context objects. */ 250 /* */ 251 typedef struct TT_Size_Metrics_ 252 { 253 /* for non-square pixels */ 254 FT_Long x_ratio; 255 FT_Long y_ratio; 256 257 FT_UShort ppem; /* maximum ppem size */ 258 FT_Long ratio; /* current ratio */ 259 FT_Fixed scale; 260 261 FT_F26Dot6 compensations[4]; /* device-specific compensations */ 262 263 FT_Bool valid; 264 265 FT_Bool rotated; /* `is the glyph rotated?'-flag */ 266 FT_Bool stretched; /* `is the glyph stretched?'-flag */ 267 268 } TT_Size_Metrics; 269 270 271 /*************************************************************************/ 272 /* */ 273 /* TrueType size class. */ 274 /* */ 275 typedef struct TT_SizeRec_ 276 { 277 FT_SizeRec root; 278 279 /* we have our own copy of metrics so that we can modify */ 280 /* it without affecting auto-hinting (when used) */ 281 FT_Size_Metrics metrics; 282 283 TT_Size_Metrics ttmetrics; 284 285 FT_ULong strike_index; /* 0xFFFFFFFF to indicate invalid */ 286 287 #ifdef TT_USE_BYTECODE_INTERPRETER 288 289 FT_Long point_size; /* for the `MPS' bytecode instruction */ 290 291 FT_UInt num_function_defs; /* number of function definitions */ 292 FT_UInt max_function_defs; 293 TT_DefArray function_defs; /* table of function definitions */ 294 295 FT_UInt num_instruction_defs; /* number of ins. definitions */ 296 FT_UInt max_instruction_defs; 297 TT_DefArray instruction_defs; /* table of ins. definitions */ 298 299 FT_UInt max_func; 300 FT_UInt max_ins; 301 302 TT_CodeRangeTable codeRangeTable; 303 304 TT_GraphicsState GS; 305 306 FT_ULong cvt_size; /* the scaled control value table */ 307 FT_Long* cvt; 308 309 FT_UShort storage_size; /* The storage area is now part of */ 310 FT_Long* storage; /* the instance */ 311 312 TT_GlyphZoneRec twilight; /* The instance's twilight zone */ 313 314 TT_ExecContext context; 315 316 /* if negative, `fpgm' (resp. `prep'), wasn't executed yet; */ 317 /* otherwise it is the returned error code */ 318 FT_Error bytecode_ready; 319 FT_Error cvt_ready; 320 321 #endif /* TT_USE_BYTECODE_INTERPRETER */ 322 323 } TT_SizeRec; 324 325 326 /*************************************************************************/ 327 /* */ 328 /* TrueType driver class. */ 329 /* */ 330 typedef struct TT_DriverRec_ 331 { 332 FT_DriverRec root; 333 334 TT_GlyphZoneRec zone; /* glyph loader points zone */ 335 336 FT_UInt interpreter_version; 337 338 } TT_DriverRec; 339 340 341 /* Note: All of the functions below (except tt_size_reset()) are used */ 342 /* as function pointers in a FT_Driver_ClassRec. Therefore their */ 343 /* parameters are of types FT_Face, FT_Size, etc., rather than TT_Face, */ 344 /* TT_Size, etc., so that the compiler can confirm that the types and */ 345 /* number of parameters are correct. In all cases the FT_xxx types are */ 346 /* cast to their TT_xxx counterparts inside the functions since FreeType */ 347 /* will always use the TT driver to create them. */ 348 349 350 /*************************************************************************/ 351 /* */ 352 /* Face functions */ 353 /* */ 354 FT_LOCAL( FT_Error ) 355 tt_face_init( FT_Stream stream, 356 FT_Face ttface, /* TT_Face */ 357 FT_Int face_index, 358 FT_Int num_params, 359 FT_Parameter* params ); 360 361 FT_LOCAL( void ) 362 tt_face_done( FT_Face ttface ); /* TT_Face */ 363 364 365 /*************************************************************************/ 366 /* */ 367 /* Size functions */ 368 /* */ 369 FT_LOCAL( FT_Error ) 370 tt_size_init( FT_Size ttsize ); /* TT_Size */ 371 372 FT_LOCAL( void ) 373 tt_size_done( FT_Size ttsize ); /* TT_Size */ 374 375 #ifdef TT_USE_BYTECODE_INTERPRETER 376 377 FT_LOCAL( FT_Error ) 378 tt_size_run_fpgm( TT_Size size, 379 FT_Bool pedantic ); 380 381 FT_LOCAL( FT_Error ) 382 tt_size_run_prep( TT_Size size, 383 FT_Bool pedantic ); 384 385 FT_LOCAL( FT_Error ) 386 tt_size_ready_bytecode( TT_Size size, 387 FT_Bool pedantic ); 388 389 #endif /* TT_USE_BYTECODE_INTERPRETER */ 390 391 FT_LOCAL( FT_Error ) 392 tt_size_reset( TT_Size size ); 393 394 395 /*************************************************************************/ 396 /* */ 397 /* Driver functions */ 398 /* */ 399 FT_LOCAL( FT_Error ) 400 tt_driver_init( FT_Module ttdriver ); /* TT_Driver */ 401 402 FT_LOCAL( void ) 403 tt_driver_done( FT_Module ttdriver ); /* TT_Driver */ 404 405 406 /*************************************************************************/ 407 /* */ 408 /* Slot functions */ 409 /* */ 410 FT_LOCAL( FT_Error ) 411 tt_slot_init( FT_GlyphSlot slot ); 412 413 414 /* auxiliary */ 415 #define IS_HINTED( flags ) ( ( flags & FT_LOAD_NO_HINTING ) == 0 ) 416 417 418 FT_END_HEADER 419 420 #endif /* TTOBJS_H_ */ 421 422 423 /* END */ 424