freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype][master] [sfnt] Support PaintScale in 'COLR' v1


From: Werner Lemberg (@wl)
Subject: [Git][freetype/freetype][master] [sfnt] Support PaintScale in 'COLR' v1 parsing.
Date: Thu, 01 Jul 2021 04:50:38 +0000

Werner Lemberg pushed to branch master at FreeType / FreeType

Commits:

3 changed files:

Changes:

  • ChangeLog
    1
    +2021-06-30  Dominik Röttsches  <drott@chromium.org>
    
    2
    +
    
    3
    +	[sfnt] Support PaintScale in 'COLR' v1 parsing.
    
    4
    +
    
    5
    +	* include/freetype/ftcolor.h (FT_PaintFormat): Renumber values, add
    
    6
    +	`FT_COLR_PAINTFORMAT_SCALE`.
    
    7
    +	(FT_PaintScale): New structure to represent 'PaintScale*' tables.
    
    8
    +	(FT_COLR_Paint): Updated.
    
    9
    +
    
    10
    +	* src/sfnt/ttcolr.c (FT_PaintFormat_Internal): New enumeration.
    
    11
    +	(read_paint): Parse 'PaintScale' and friends.
    
    12
    +
    
    1 13
     2021-06-30  Dominik Röttsches  <drott@chromium.org>
    
    2 14
     
    
    3 15
     	[sfnt] Handle fonts without layer list in 'COLR' v1.
    

  • include/freetype/ftcolor.h
    ... ... @@ -475,12 +475,18 @@ FT_BEGIN_HEADER
    475 475
        *   extensions to the 'COLR' table, see
    
    476 476
        *   'https://github.com/googlefonts/colr-gradients-spec'.
    
    477 477
        *
    
    478
    -   *   Only non-variable format identifiers are listed in this enumeration;
    
    479
    -   *   as soon as support for variable 'COLR' v1 fonts is implemented,
    
    480
    -   *   interpolation is performed dependent on axis coordinates, which are
    
    481
    -   *   configured on the @FT_Face through @FT_Set_Var_Design_Coordinates.
    
    482
    -   *   This implies that always static (interpolated) values are returned
    
    483
    -   *   for both variable and non-variable formats.
    
    478
    +   *   The enumeration values losely correspond with the format numbers of
    
    479
    +   *   the specification: FreeType always returns a fully specified 'Paint'
    
    480
    +   *   structure for the 'Transform', 'Translate', 'Scale', 'Rotate', and
    
    481
    +   *   'Skew' table types even though the specification has different formats
    
    482
    +   *   depending on whether or not a center is specified, whether the scale
    
    483
    +   *   is uniform in x and y~direction or not, etc.  Also, only non-variable
    
    484
    +   *   format identifiers are listed in this enumeration; as soon as support
    
    485
    +   *   for variable 'COLR' v1 fonts is implemented, interpolation is
    
    486
    +   *   performed dependent on axis coordinates, which are configured on the
    
    487
    +   *   @FT_Face through @FT_Set_Var_Design_Coordinates.  This implies that
    
    488
    +   *   always static, readily interpolated values are returned in the 'Paint'
    
    489
    +   *   structures.
    
    484 490
        *
    
    485 491
        * @since:
    
    486 492
        *   2.11 -- **currently experimental only!**  There might be changes
    
    ... ... @@ -498,10 +504,11 @@ FT_BEGIN_HEADER
    498 504
         FT_COLR_PAINTFORMAT_COLR_GLYPH      = 11,
    
    499 505
         FT_COLR_PAINTFORMAT_TRANSFORM       = 12,
    
    500 506
         FT_COLR_PAINTFORMAT_TRANSLATE       = 14,
    
    501
    -    FT_COLR_PAINTFORMAT_ROTATE          = 16,
    
    502
    -    FT_COLR_PAINTFORMAT_SKEW            = 18,
    
    503
    -    FT_COLR_PAINTFORMAT_COMPOSITE       = 20,
    
    504
    -    FT_COLR_PAINT_FORMAT_MAX            = 21,
    
    507
    +    FT_COLR_PAINTFORMAT_SCALE           = 16,
    
    508
    +    FT_COLR_PAINTFORMAT_ROTATE          = 24,
    
    509
    +    FT_COLR_PAINTFORMAT_SKEW            = 28,
    
    510
    +    FT_COLR_PAINTFORMAT_COMPOSITE       = 32,
    
    511
    +    FT_COLR_PAINT_FORMAT_MAX            = 33,
    
    505 512
         FT_COLR_PAINTFORMAT_UNSUPPORTED     = 255
    
    506 513
     
    
    507 514
       } FT_PaintFormat;
    
    ... ... @@ -1101,6 +1108,56 @@ FT_BEGIN_HEADER
    1101 1108
       } FT_PaintTranslate;
    
    1102 1109
     
    
    1103 1110
     
    
    1111
    +  /**************************************************************************
    
    1112
    +   *
    
    1113
    +   * @struct:
    
    1114
    +   *   FT_PaintScale
    
    1115
    +   *
    
    1116
    +   * @description:
    
    1117
    +   *   A structure representing all of the 'COLR' v1 'PaintScale*' paint
    
    1118
    +   *   tables.  Used for scaling downstream paints by a given x and y~scale,
    
    1119
    +   *   with a given center.  This structure is used for all 'PaintScale*'
    
    1120
    +   *   types that are part of specification; fields of this structure are
    
    1121
    +   *   filled accordingly.  If there is a center, the center values are set,
    
    1122
    +   *   otherwise they are set to the zero coordinate.  If the source font
    
    1123
    +   *   file has 'PaintScaleUniform*' set, the scale values are set
    
    1124
    +   *   accordingly to the same value.
    
    1125
    +   *
    
    1126
    +   * @fields:
    
    1127
    +   *   paint ::
    
    1128
    +   *     An @FT_OpaquePaint object referencing the paint that is to be
    
    1129
    +   *     scaled.
    
    1130
    +   *
    
    1131
    +   *   scale_x ::
    
    1132
    +   *     Scale factor in x~direction.
    
    1133
    +   *
    
    1134
    +   *   scale_y ::
    
    1135
    +   *     Scale factor in y~direction.
    
    1136
    +   *
    
    1137
    +   *   center_x ::
    
    1138
    +   *     x~coordinate of center point to scale from.
    
    1139
    +   *
    
    1140
    +   *   center_y ::
    
    1141
    +   *     y~coordinate of center point to scale from.
    
    1142
    +   *
    
    1143
    +   * @since:
    
    1144
    +   *   2.11 -- **currently experimental only!**  There might be changes
    
    1145
    +   *   without retaining backward-compatibility of both the API and ABI.
    
    1146
    +   *
    
    1147
    +   */
    
    1148
    +  typedef struct  FT_PaintScale_
    
    1149
    +  {
    
    1150
    +    FT_OpaquePaint  paint;
    
    1151
    +
    
    1152
    +    FT_Fixed  scale_x;
    
    1153
    +    FT_Fixed  scale_y;
    
    1154
    +
    
    1155
    +    FT_Fixed  center_x;
    
    1156
    +    FT_Fixed  center_y;
    
    1157
    +
    
    1158
    +  } FT_PaintScale;
    
    1159
    +
    
    1160
    +
    
    1104 1161
       /**************************************************************************
    
    1105 1162
        *
    
    1106 1163
        * @struct:
    
    ... ... @@ -1277,6 +1334,7 @@ FT_BEGIN_HEADER
    1277 1334
           FT_PaintSweepGradient   sweep_gradient;
    
    1278 1335
           FT_PaintTransform       transform;
    
    1279 1336
           FT_PaintTranslate       translate;
    
    1337
    +      FT_PaintScale           scale;
    
    1280 1338
           FT_PaintRotate          rotate;
    
    1281 1339
           FT_PaintSkew            skew;
    
    1282 1340
           FT_PaintComposite       composite;
    

  • src/sfnt/ttcolr.c
    ... ... @@ -49,6 +49,17 @@
    49 49
     #define COLR_HEADER_SIZE                 14U
    
    50 50
     
    
    51 51
     
    
    52
    +  typedef enum  FT_PaintFormat_Internal_
    
    53
    +  {
    
    54
    +    FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER         = 18,
    
    55
    +    FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM        = 20,
    
    56
    +    FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER = 22,
    
    57
    +    FT_COLR_PAINTFORMAT_INTERNAL_ROTATE_CENTER        = 26,
    
    58
    +    FT_COLR_PAINTFORMAT_INTERNAL_SKEW_CENTER          = 30
    
    59
    +
    
    60
    +  } FT_PaintFormat_Internal;
    
    61
    +
    
    62
    +
    
    52 63
       typedef struct  BaseGlyphRecord_
    
    53 64
       {
    
    54 65
         FT_UShort  gid;
    
    ... ... @@ -561,6 +572,53 @@
    561 572
           return 1;
    
    562 573
         }
    
    563 574
     
    
    575
    +    else if ( apaint->format ==
    
    576
    +                FT_COLR_PAINTFORMAT_SCALE                         ||
    
    577
    +              (FT_PaintFormat_Internal)apaint->format ==
    
    578
    +                FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER         ||
    
    579
    +              (FT_PaintFormat_Internal)apaint->format ==
    
    580
    +                FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM        ||
    
    581
    +              (FT_PaintFormat_Internal)apaint->format ==
    
    582
    +                FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER )
    
    583
    +    {
    
    584
    +      apaint->u.scale.paint.p                     = child_table_p;
    
    585
    +      apaint->u.scale.paint.insert_root_transform = 0;
    
    586
    +
    
    587
    +      /* All scale paints get at least one scale value. */
    
    588
    +      apaint->u.scale.scale_x = FT_NEXT_LONG( p );
    
    589
    +
    
    590
    +      /* Non-uniform ones read an extra y value. */
    
    591
    +      if ( apaint->format ==
    
    592
    +             FT_COLR_PAINTFORMAT_SCALE                 ||
    
    593
    +           (FT_PaintFormat_Internal)apaint->format ==
    
    594
    +             FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER )
    
    595
    +        apaint->u.scale.scale_y = FT_NEXT_LONG( p );
    
    596
    +      else
    
    597
    +        apaint->u.scale.scale_y = apaint->u.scale.scale_x;
    
    598
    +
    
    599
    +      /* Scale paints that have a center read center coordinates, */
    
    600
    +      /* otherwise the center is (0,0).                           */
    
    601
    +      if ( (FT_PaintFormat_Internal)apaint->format ==
    
    602
    +             FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER         ||
    
    603
    +           (FT_PaintFormat_Internal)apaint->format ==
    
    604
    +             FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER )
    
    605
    +      {
    
    606
    +        apaint->u.scale.center_x = FT_NEXT_LONG ( p );
    
    607
    +        apaint->u.scale.center_y = FT_NEXT_LONG ( p );
    
    608
    +      }
    
    609
    +      else
    
    610
    +      {
    
    611
    +        apaint->u.scale.center_x = 0;
    
    612
    +        apaint->u.scale.center_y = 0;
    
    613
    +      }
    
    614
    +
    
    615
    +      /* FT 'COLR' v1 API output format always returns fully defined */
    
    616
    +      /* structs; we thus set the format to the public API value.    */
    
    617
    +      apaint->format = FT_COLR_PAINTFORMAT_SCALE;
    
    618
    +
    
    619
    +      return 1;
    
    620
    +    }
    
    621
    +
    
    564 622
         else if ( apaint->format == FT_COLR_PAINTFORMAT_ROTATE )
    
    565 623
         {
    
    566 624
           apaint->u.rotate.paint.p                     = child_table_p;
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]