tor-browser

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

ttobjs.h (9468B)


      1 /****************************************************************************
      2 *
      3 * ttobjs.h
      4 *
      5 *   Objects manager (specification).
      6 *
      7 * Copyright (C) 1996-2025 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 <freetype/internal/ftobjs.h>
     24 #include <freetype/internal/tttypes.h>
     25 
     26 
     27 FT_BEGIN_HEADER
     28 
     29 
     30  /**************************************************************************
     31   *
     32   * @Type:
     33   *   TT_Driver
     34   *
     35   * @Description:
     36   *   A handle to a TrueType driver object.
     37   */
     38  typedef struct TT_DriverRec_*  TT_Driver;
     39 
     40 
     41  /**************************************************************************
     42   *
     43   * @Type:
     44   *   TT_GlyphSlot
     45   *
     46   * @Description:
     47   *   A handle to a TrueType glyph slot object.
     48   *
     49   * @Note:
     50   *   This is a direct typedef of FT_GlyphSlot, as there is nothing
     51   *   specific about the TrueType glyph slot.
     52   */
     53  typedef FT_GlyphSlot  TT_GlyphSlot;
     54 
     55 
     56 #ifdef TT_USE_BYTECODE_INTERPRETER
     57 
     58  /**************************************************************************
     59   *
     60   * @Struct:
     61   *   TT_GraphicsState
     62   *
     63   * @Description:
     64   *   The TrueType graphics state used during bytecode interpretation.
     65   */
     66  typedef struct  TT_GraphicsState_
     67  {
     68    FT_UShort      rp0;
     69    FT_UShort      rp1;
     70    FT_UShort      rp2;
     71 
     72    FT_UShort      gep0;
     73    FT_UShort      gep1;
     74    FT_UShort      gep2;
     75 
     76    FT_UnitVector  dualVector;
     77    FT_UnitVector  projVector;
     78    FT_UnitVector  freeVector;
     79 
     80    FT_Long        loop;
     81    FT_Int         round_state;
     82    FT_F26Dot6     compensation[4];   /* device-specific compensations  */
     83 
     84    /* default values below can be modified by 'fpgm' and 'prep' */
     85    FT_F26Dot6     minimum_distance;
     86    FT_F26Dot6     control_value_cutin;
     87    FT_F26Dot6     single_width_cutin;
     88    FT_F26Dot6     single_width_value;
     89    FT_UShort      delta_base;
     90    FT_UShort      delta_shift;
     91 
     92    FT_Bool        auto_flip;
     93    FT_Byte        instruct_control;
     94    /* According to Greg Hitchcock from Microsoft, the `scan_control'     */
     95    /* variable as documented in the TrueType specification is a 32-bit   */
     96    /* integer; the high-word part holds the SCANTYPE value, the low-word */
     97    /* part the SCANCTRL value.  We separate it into two fields.          */
     98    FT_Bool        scan_control;
     99    FT_Int         scan_type;
    100 
    101  } TT_GraphicsState;
    102 
    103 
    104  FT_LOCAL( void )
    105  tt_glyphzone_done( FT_Memory     memory,
    106                     TT_GlyphZone  zone );
    107 
    108  FT_LOCAL( FT_Error )
    109  tt_glyphzone_new( FT_Memory     memory,
    110                    FT_UShort     maxPoints,
    111                    FT_UShort     maxContours,
    112                    TT_GlyphZone  zone );
    113 
    114 #endif /* TT_USE_BYTECODE_INTERPRETER */
    115 
    116 
    117 
    118  /**************************************************************************
    119   *
    120   * A note regarding non-squared pixels:
    121   *
    122   * (This text will probably go into some docs at some time; for now, it
    123   * is kept here to explain some definitions in the TT_Size_Metrics
    124   * record).
    125   *
    126   * The CVT is a one-dimensional array containing values that control
    127   * certain important characteristics in a font, like the height of all
    128   * capitals, all lowercase letter, default spacing or stem width/height.
    129   *
    130   * These values are found in FUnits in the font file, and must be scaled
    131   * to pixel coordinates before being used by the CVT and glyph programs.
    132   * Unfortunately, when using distinct x and y resolutions (or distinct x
    133   * and y pointsizes), there are two possible scalings.
    134   *
    135   * A first try was to implement a `lazy' scheme where all values were
    136   * scaled when first used.  However, while some values are always used
    137   * in the same direction, some others are used under many different
    138   * circumstances and orientations.
    139   *
    140   * I have found a simpler way to do the same, and it even seems to work
    141   * in most of the cases:
    142   *
    143   * - All CVT values are scaled to the maximum ppem size.
    144   *
    145   * - When performing a read or write in the CVT, a ratio factor is used
    146   *   to perform adequate scaling.  Example:
    147   *
    148   *     x_ppem = 14
    149   *     y_ppem = 10
    150   *
    151   *   We choose ppem = x_ppem = 14 as the CVT scaling size.  All cvt
    152   *   entries are scaled to it.
    153   *
    154   *     x_ratio = 1.0
    155   *     y_ratio = y_ppem/ppem (< 1.0)
    156   *
    157   *   We compute the current ratio like:
    158   *
    159   *   - If projVector is horizontal,
    160   *       ratio = x_ratio = 1.0
    161   *
    162   *   - if projVector is vertical,
    163   *       ratio = y_ratio
    164   *
    165   *   - else,
    166   *       ratio = sqrt( (proj.x * x_ratio) ^ 2 + (proj.y * y_ratio) ^ 2 )
    167   *
    168   *   Reading a cvt value returns
    169   *     ratio * cvt[index]
    170   *
    171   *   Writing a cvt value in pixels:
    172   *     cvt[index] / ratio
    173   *
    174   *   The current ppem is simply
    175   *     ratio * ppem
    176   *
    177   */
    178 
    179 
    180  /**************************************************************************
    181   *
    182   * Metrics used by the TrueType size and context objects.
    183   */
    184  typedef struct  TT_Size_Metrics_
    185  {
    186    /* for non-square pixels */
    187    FT_Long     x_ratio;
    188    FT_Long     y_ratio;
    189 
    190    FT_Long     ratio;              /* current ratio                  */
    191    FT_Fixed    scale;
    192    FT_UShort   ppem;               /* maximum ppem size              */
    193 
    194    FT_Bool     rotated;            /* `is the glyph rotated?'-flag   */
    195    FT_Bool     stretched;          /* `is the glyph stretched?'-flag */
    196 
    197  } TT_Size_Metrics;
    198 
    199 
    200  /**************************************************************************
    201   *
    202   * TrueType size class.
    203   */
    204  typedef struct  TT_SizeRec_
    205  {
    206    FT_SizeRec         root;
    207 
    208    /* we have our own copy of metrics so that we can modify */
    209    /* it without affecting auto-hinting (when used)         */
    210    FT_Size_Metrics*   metrics;        /* for the current rendering mode */
    211    FT_Size_Metrics    hinted_metrics; /* for the hinted rendering mode  */
    212 
    213    TT_Size_Metrics    ttmetrics;
    214 
    215    FT_Byte*           widthp;          /* glyph widths from the hdmx table */
    216 
    217    FT_ULong           strike_index;      /* 0xFFFFFFFF to indicate invalid */
    218 
    219 #ifdef TT_USE_BYTECODE_INTERPRETER
    220 
    221    FT_Long            point_size;    /* for the `MPS' bytecode instruction */
    222 
    223    TT_GraphicsState   GS;
    224 
    225    TT_GlyphZoneRec    twilight;     /* The instance's twilight zone    */
    226 
    227    TT_ExecContext     context;
    228 
    229    /* if negative, `fpgm' (resp. `prep'), wasn't executed yet; */
    230    /* otherwise it is the returned error code                  */
    231    FT_Error           bytecode_ready;
    232    FT_Error           cvt_ready;
    233 
    234 #endif /* TT_USE_BYTECODE_INTERPRETER */
    235 
    236  } TT_SizeRec;
    237 
    238 
    239  /**************************************************************************
    240   *
    241   * TrueType driver class.
    242   */
    243  typedef struct  TT_DriverRec_
    244  {
    245    FT_DriverRec  root;
    246 
    247    TT_GlyphZoneRec  zone;     /* glyph loader points zone */
    248 
    249    FT_UInt  interpreter_version;
    250 
    251  } TT_DriverRec;
    252 
    253 
    254  /* Note: All of the functions below (except tt_size_reset()) are used    */
    255  /* as function pointers in a FT_Driver_ClassRec.  Therefore their        */
    256  /* parameters are of types FT_Face, FT_Size, etc., rather than TT_Face,  */
    257  /* TT_Size, etc., so that the compiler can confirm that the types and    */
    258  /* number of parameters are correct.  In all cases the FT_xxx types are  */
    259  /* cast to their TT_xxx counterparts inside the functions since FreeType */
    260  /* will always use the TT driver to create them.                         */
    261 
    262 
    263  /**************************************************************************
    264   *
    265   * Face functions
    266   */
    267  FT_LOCAL( FT_Error )
    268  tt_face_init( FT_Stream      stream,
    269                FT_Face        ttface,      /* TT_Face */
    270                FT_Int         face_index,
    271                FT_Int         num_params,
    272                FT_Parameter*  params );
    273 
    274  FT_LOCAL( void )
    275  tt_face_done( FT_Face  ttface );          /* TT_Face */
    276 
    277 
    278  /**************************************************************************
    279   *
    280   * Size functions
    281   */
    282  FT_LOCAL( FT_Error )
    283  tt_size_init( FT_Size  ttsize );          /* TT_Size */
    284 
    285  FT_LOCAL( void )
    286  tt_size_done( FT_Size  ttsize );          /* TT_Size */
    287 
    288 #ifdef TT_USE_BYTECODE_INTERPRETER
    289 
    290  FT_LOCAL( FT_Error )
    291  tt_size_run_fpgm( TT_Size  size );
    292 
    293  FT_LOCAL( FT_Error )
    294  tt_size_run_prep( TT_Size  size );
    295 
    296  FT_LOCAL( FT_Error )
    297  tt_size_init_bytecode( TT_Size  size,
    298                         FT_Bool  pedantic );
    299 
    300 #endif /* TT_USE_BYTECODE_INTERPRETER */
    301 
    302  FT_LOCAL( void )
    303  tt_size_reset_height( FT_Size  size );
    304 
    305  FT_LOCAL( FT_Error )
    306  tt_size_reset( TT_Size  size );
    307 
    308 
    309  /**************************************************************************
    310   *
    311   * Driver functions
    312   */
    313  FT_LOCAL( FT_Error )
    314  tt_driver_init( FT_Module  ttdriver );    /* TT_Driver */
    315 
    316  FT_LOCAL( void )
    317  tt_driver_done( FT_Module  ttdriver );    /* TT_Driver */
    318 
    319 
    320  /**************************************************************************
    321   *
    322   * Slot functions
    323   */
    324  FT_LOCAL( FT_Error )
    325  tt_slot_init( FT_GlyphSlot  slot );
    326 
    327 
    328  /* auxiliary */
    329 #define IS_HINTED( flags )  ( ( flags & FT_LOAD_NO_HINTING ) == 0 )
    330 
    331 
    332 FT_END_HEADER
    333 
    334 #endif /* TTOBJS_H_ */
    335 
    336 
    337 /* END */