1 /**************************************************************************** 2 * 3 * ttgxvar.h 4 * 5 * TrueType GX Font Variation loader (specification) 6 * 7 * Copyright (C) 2004-2020 by 8 * David Turner, Robert Wilhelm, Werner Lemberg and George Williams. 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 TTGXVAR_H_ 20 #define TTGXVAR_H_ 21 22 23 #include "ttobjs.h" 24 25 26 FT_BEGIN_HEADER 27 28 29 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 30 31 /************************************************************************** 32 * 33 * @Struct: 34 * GX_AVarCorrespondenceRec 35 * 36 * @Description: 37 * A data structure representing `shortFracCorrespondence' in `avar' 38 * table according to the specifications from Apple. 39 */ 40 typedef struct GX_AVarCorrespondenceRec_ 41 { 42 FT_Fixed fromCoord; 43 FT_Fixed toCoord; 44 45 } GX_AVarCorrespondenceRec_, *GX_AVarCorrespondence; 46 47 48 /************************************************************************** 49 * 50 * @Struct: 51 * GX_AVarRec 52 * 53 * @Description: 54 * Data from the segment field of `avar' table. 55 * There is one of these for each axis. 56 */ 57 typedef struct GX_AVarSegmentRec_ 58 { 59 FT_UShort pairCount; 60 GX_AVarCorrespondence correspondence; /* array with pairCount entries */ 61 62 } GX_AVarSegmentRec, *GX_AVarSegment; 63 64 65 typedef struct GX_ItemVarDataRec_ 66 { 67 FT_UInt itemCount; /* number of delta sets per item */ 68 FT_UInt regionIdxCount; /* number of region indices in this data */ 69 FT_UInt* regionIndices; /* array of `regionCount' indices; */ 70 /* these index `varRegionList' */ 71 FT_Short* deltaSet; /* array of `itemCount' deltas */ 72 /* use `innerIndex' for this array */ 73 74 } GX_ItemVarDataRec, *GX_ItemVarData; 75 76 77 /* contribution of one axis to a region */ 78 typedef struct GX_AxisCoordsRec_ 79 { 80 FT_Fixed startCoord; 81 FT_Fixed peakCoord; /* zero means no effect (factor = 1) */ 82 FT_Fixed endCoord; 83 84 } GX_AxisCoordsRec, *GX_AxisCoords; 85 86 87 typedef struct GX_VarRegionRec_ 88 { 89 GX_AxisCoords axisList; /* array of axisCount records */ 90 91 } GX_VarRegionRec, *GX_VarRegion; 92 93 94 /* item variation store */ 95 typedef struct GX_ItemVarStoreRec_ 96 { 97 FT_UInt dataCount; 98 GX_ItemVarData varData; /* array of dataCount records; */ 99 /* use `outerIndex' for this array */ 100 FT_UShort axisCount; 101 FT_UInt regionCount; /* total number of regions defined */ 102 GX_VarRegion varRegionList; 103 104 } GX_ItemVarStoreRec, *GX_ItemVarStore; 105 106 107 typedef struct GX_DeltaSetIdxMapRec_ 108 { 109 FT_UInt mapCount; 110 FT_UInt* outerIndex; /* indices to item var data */ 111 FT_UInt* innerIndex; /* indices to delta set */ 112 113 } GX_DeltaSetIdxMapRec, *GX_DeltaSetIdxMap; 114 115 116 /************************************************************************** 117 * 118 * @Struct: 119 * GX_HVVarTableRec 120 * 121 * @Description: 122 * Data from either the `HVAR' or `VVAR' table. 123 */ 124 typedef struct GX_HVVarTableRec_ 125 { 126 GX_ItemVarStoreRec itemStore; /* Item Variation Store */ 127 GX_DeltaSetIdxMapRec widthMap; /* Advance Width Mapping */ 128 129 #if 0 130 GX_DeltaSetIdxMapRec lsbMap; /* not implemented */ 131 GX_DeltaSetIdxMapRec rsbMap; /* not implemented */ 132 133 GX_DeltaSetIdxMapRec tsbMap; /* not implemented */ 134 GX_DeltaSetIdxMapRec bsbMap; /* not implemented */ 135 GX_DeltaSetIdxMapRec vorgMap; /* not implemented */ 136 #endif 137 138 } GX_HVVarTableRec, *GX_HVVarTable; 139 140 141 #define MVAR_TAG_GASP_0 FT_MAKE_TAG( 'g', 's', 'p', '0' ) 142 #define MVAR_TAG_GASP_1 FT_MAKE_TAG( 'g', 's', 'p', '1' ) 143 #define MVAR_TAG_GASP_2 FT_MAKE_TAG( 'g', 's', 'p', '2' ) 144 #define MVAR_TAG_GASP_3 FT_MAKE_TAG( 'g', 's', 'p', '3' ) 145 #define MVAR_TAG_GASP_4 FT_MAKE_TAG( 'g', 's', 'p', '4' ) 146 #define MVAR_TAG_GASP_5 FT_MAKE_TAG( 'g', 's', 'p', '5' ) 147 #define MVAR_TAG_GASP_6 FT_MAKE_TAG( 'g', 's', 'p', '6' ) 148 #define MVAR_TAG_GASP_7 FT_MAKE_TAG( 'g', 's', 'p', '7' ) 149 #define MVAR_TAG_GASP_8 FT_MAKE_TAG( 'g', 's', 'p', '8' ) 150 #define MVAR_TAG_GASP_9 FT_MAKE_TAG( 'g', 's', 'p', '9' ) 151 152 #define MVAR_TAG_CPHT FT_MAKE_TAG( 'c', 'p', 'h', 't' ) 153 #define MVAR_TAG_HASC FT_MAKE_TAG( 'h', 'a', 's', 'c' ) 154 #define MVAR_TAG_HCLA FT_MAKE_TAG( 'h', 'c', 'l', 'a' ) 155 #define MVAR_TAG_HCLD FT_MAKE_TAG( 'h', 'c', 'l', 'd' ) 156 #define MVAR_TAG_HCOF FT_MAKE_TAG( 'h', 'c', 'o', 'f' ) 157 #define MVAR_TAG_HCRN FT_MAKE_TAG( 'h', 'c', 'r', 'n' ) 158 #define MVAR_TAG_HCRS FT_MAKE_TAG( 'h', 'c', 'r', 's' ) 159 #define MVAR_TAG_HDSC FT_MAKE_TAG( 'h', 'd', 's', 'c' ) 160 #define MVAR_TAG_HLGP FT_MAKE_TAG( 'h', 'l', 'g', 'p' ) 161 #define MVAR_TAG_SBXO FT_MAKE_TAG( 's', 'b', 'x', 'o' ) 162 #define MVAR_TAG_SBXS FT_MAKE_TAG( 's', 'b', 'x', 's' ) 163 #define MVAR_TAG_SBYO FT_MAKE_TAG( 's', 'b', 'y', 'o' ) 164 #define MVAR_TAG_SBYS FT_MAKE_TAG( 's', 'b', 'y', 's' ) 165 #define MVAR_TAG_SPXO FT_MAKE_TAG( 's', 'p', 'x', 'o' ) 166 #define MVAR_TAG_SPXS FT_MAKE_TAG( 's', 'p', 'x', 's' ) 167 #define MVAR_TAG_SPYO FT_MAKE_TAG( 's', 'p', 'y', 'o' ) 168 #define MVAR_TAG_SPYS FT_MAKE_TAG( 's', 'p', 'y', 's' ) 169 #define MVAR_TAG_STRO FT_MAKE_TAG( 's', 't', 'r', 'o' ) 170 #define MVAR_TAG_STRS FT_MAKE_TAG( 's', 't', 'r', 's' ) 171 #define MVAR_TAG_UNDO FT_MAKE_TAG( 'u', 'n', 'd', 'o' ) 172 #define MVAR_TAG_UNDS FT_MAKE_TAG( 'u', 'n', 'd', 's' ) 173 #define MVAR_TAG_VASC FT_MAKE_TAG( 'v', 'a', 's', 'c' ) 174 #define MVAR_TAG_VCOF FT_MAKE_TAG( 'v', 'c', 'o', 'f' ) 175 #define MVAR_TAG_VCRN FT_MAKE_TAG( 'v', 'c', 'r', 'n' ) 176 #define MVAR_TAG_VCRS FT_MAKE_TAG( 'v', 'c', 'r', 's' ) 177 #define MVAR_TAG_VDSC FT_MAKE_TAG( 'v', 'd', 's', 'c' ) 178 #define MVAR_TAG_VLGP FT_MAKE_TAG( 'v', 'l', 'g', 'p' ) 179 #define MVAR_TAG_XHGT FT_MAKE_TAG( 'x', 'h', 'g', 't' ) 180 181 182 typedef struct GX_ValueRec_ 183 { 184 FT_ULong tag; 185 FT_UShort outerIndex; 186 FT_UShort innerIndex; 187 188 FT_Short unmodified; /* values are either FT_Short or FT_UShort */ 189 190 } GX_ValueRec, *GX_Value; 191 192 193 /************************************************************************** 194 * 195 * @Struct: 196 * GX_MVarTableRec 197 * 198 * @Description: 199 * Data from the `MVAR' table. 200 */ 201 typedef struct GX_MVarTableRec_ 202 { 203 FT_UShort valueCount; 204 205 GX_ItemVarStoreRec itemStore; /* Item Variation Store */ 206 GX_Value values; /* Value Records */ 207 208 } GX_MVarTableRec, *GX_MVarTable; 209 210 211 /************************************************************************** 212 * 213 * @Struct: 214 * GX_BlendRec 215 * 216 * @Description: 217 * Data for interpolating a font from a distortable font specified 218 * by the GX *var tables ([fgcahvm]var). 219 * 220 * @Fields: 221 * num_axis :: 222 * The number of axes along which interpolation may happen. 223 * 224 * coords :: 225 * An array of design coordinates (in user space) indicating the 226 * contribution along each axis to the final interpolated font. 227 * `normalizedcoords' holds the same values. 228 * 229 * normalizedcoords :: 230 * An array of normalized values (between [-1,1]) indicating the 231 * contribution along each axis to the final interpolated font. 232 * `coords' holds the same values. 233 * 234 * mmvar :: 235 * Data from the `fvar' table. 236 * 237 * mmvar_len :: 238 * The length of the `mmvar' structure. 239 * 240 * normalized_stylecoords :: 241 * A two-dimensional array that holds the named instance data from 242 * `mmvar' as normalized values. 243 * 244 * avar_loaded :: 245 * A Boolean; if set, FreeType tried to load (and parse) the `avar' 246 * table. 247 * 248 * avar_segment :: 249 * Data from the `avar' table. 250 * 251 * hvar_loaded :: 252 * A Boolean; if set, FreeType tried to load (and parse) the `hvar' 253 * table. 254 * 255 * hvar_checked :: 256 * A Boolean; if set, FreeType successfully loaded and parsed the 257 * `hvar' table. 258 * 259 * hvar_error :: 260 * If loading and parsing of the `hvar' table failed, this field 261 * holds the corresponding error code. 262 * 263 * hvar_table :: 264 * Data from the `hvar' table. 265 * 266 * vvar_loaded :: 267 * A Boolean; if set, FreeType tried to load (and parse) the `vvar' 268 * table. 269 * 270 * vvar_checked :: 271 * A Boolean; if set, FreeType successfully loaded and parsed the 272 * `vvar' table. 273 * 274 * vvar_error :: 275 * If loading and parsing of the `vvar' table failed, this field 276 * holds the corresponding error code. 277 * 278 * vvar_table :: 279 * Data from the `vvar' table. 280 * 281 * mvar_table :: 282 * Data from the `mvar' table. 283 * 284 * tuplecount :: 285 * The number of shared tuples in the `gvar' table. 286 * 287 * tuplecoords :: 288 * A two-dimensional array that holds the shared tuple coordinates 289 * in the `gvar' table. 290 * 291 * gv_glyphcnt :: 292 * The number of glyphs handled in the `gvar' table. 293 * 294 * glyphoffsets :: 295 * Offsets into the glyph variation data array. 296 * 297 * gvar_size :: 298 * The size of the `gvar' table. 299 */ 300 typedef struct GX_BlendRec_ 301 { 302 FT_UInt num_axis; 303 FT_Fixed* coords; 304 FT_Fixed* normalizedcoords; 305 306 FT_MM_Var* mmvar; 307 FT_Offset mmvar_len; 308 309 FT_Fixed* normalized_stylecoords; 310 /* normalized_stylecoords[num_namedstyles][num_axis] */ 311 312 FT_Bool avar_loaded; 313 GX_AVarSegment avar_segment; /* avar_segment[num_axis] */ 314 315 FT_Bool hvar_loaded; 316 FT_Bool hvar_checked; 317 FT_Error hvar_error; 318 GX_HVVarTable hvar_table; 319 320 FT_Bool vvar_loaded; 321 FT_Bool vvar_checked; 322 FT_Error vvar_error; 323 GX_HVVarTable vvar_table; 324 325 GX_MVarTable mvar_table; 326 327 FT_UInt tuplecount; 328 FT_Fixed* tuplecoords; /* tuplecoords[tuplecount][num_axis] */ 329 330 FT_UInt gv_glyphcnt; 331 FT_ULong* glyphoffsets; /* glyphoffsets[gv_glyphcnt + 1] */ 332 333 FT_ULong gvar_size; 334 335 } GX_BlendRec; 336 337 338 /************************************************************************** 339 * 340 * @enum: 341 * GX_TupleCountFlags 342 * 343 * @Description: 344 * Flags used within the `TupleCount' field of the `gvar' table. 345 */ 346 typedef enum GX_TupleCountFlags_ 347 { 348 GX_TC_TUPLES_SHARE_POINT_NUMBERS = 0x8000, 349 GX_TC_RESERVED_TUPLE_FLAGS = 0x7000, 350 GX_TC_TUPLE_COUNT_MASK = 0x0FFF 351 352 } GX_TupleCountFlags; 353 354 355 /************************************************************************** 356 * 357 * @enum: 358 * GX_TupleIndexFlags 359 * 360 * @Description: 361 * Flags used within the `TupleIndex' field of the `gvar' and `cvar' 362 * tables. 363 */ 364 typedef enum GX_TupleIndexFlags_ 365 { 366 GX_TI_EMBEDDED_TUPLE_COORD = 0x8000, 367 GX_TI_INTERMEDIATE_TUPLE = 0x4000, 368 GX_TI_PRIVATE_POINT_NUMBERS = 0x2000, 369 GX_TI_RESERVED_TUPLE_FLAG = 0x1000, 370 GX_TI_TUPLE_INDEX_MASK = 0x0FFF 371 372 } GX_TupleIndexFlags; 373 374 375 #define TTAG_wght FT_MAKE_TAG( 'w', 'g', 'h', 't' ) 376 #define TTAG_wdth FT_MAKE_TAG( 'w', 'd', 't', 'h' ) 377 #define TTAG_opsz FT_MAKE_TAG( 'o', 'p', 's', 'z' ) 378 #define TTAG_slnt FT_MAKE_TAG( 's', 'l', 'n', 't' ) 379 380 381 FT_LOCAL( FT_Error ) 382 TT_Set_MM_Blend( TT_Face face, 383 FT_UInt num_coords, 384 FT_Fixed* coords ); 385 386 FT_LOCAL( FT_Error ) 387 TT_Get_MM_Blend( TT_Face face, 388 FT_UInt num_coords, 389 FT_Fixed* coords ); 390 391 FT_LOCAL( FT_Error ) 392 TT_Set_Var_Design( TT_Face face, 393 FT_UInt num_coords, 394 FT_Fixed* coords ); 395 396 FT_LOCAL( FT_Error ) 397 TT_Get_MM_Var( TT_Face face, 398 FT_MM_Var* *master ); 399 400 FT_LOCAL( FT_Error ) 401 TT_Get_Var_Design( TT_Face face, 402 FT_UInt num_coords, 403 FT_Fixed* coords ); 404 405 FT_LOCAL( FT_Error ) 406 TT_Set_Named_Instance( TT_Face face, 407 FT_UInt instance_index ); 408 409 FT_LOCAL( FT_Error ) 410 tt_face_vary_cvt( TT_Face face, 411 FT_Stream stream ); 412 413 414 FT_LOCAL( FT_Error ) 415 TT_Vary_Apply_Glyph_Deltas( TT_Face face, 416 FT_UInt glyph_index, 417 FT_Outline* outline, 418 FT_Vector* unrounded, 419 FT_UInt n_points ); 420 421 FT_LOCAL( FT_Error ) 422 tt_hadvance_adjust( TT_Face face, 423 FT_UInt gindex, 424 FT_Int *adelta ); 425 426 FT_LOCAL( FT_Error ) 427 tt_vadvance_adjust( TT_Face face, 428 FT_UInt gindex, 429 FT_Int *adelta ); 430 431 FT_LOCAL( void ) 432 tt_apply_mvar( TT_Face face ); 433 434 FT_LOCAL( FT_Error ) 435 tt_get_var_blend( TT_Face face, 436 FT_UInt *num_coords, 437 FT_Fixed* *coords, 438 FT_Fixed* *normalizedcoords, 439 FT_MM_Var* *mm_var ); 440 441 FT_LOCAL( void ) 442 tt_done_blend( TT_Face face ); 443 444 #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ 445 446 447 FT_END_HEADER 448 449 450 #endif /* TTGXVAR_H_ */ 451 452 453 /* END */ 454