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