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