tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ttgxvar.h (13859B)


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