freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] 2 commits: [sfnt] Provide optional root


From: Werner Lemberg
Subject: [Git][freetype/freetype][master] 2 commits: [sfnt] Provide optional root transform for 'COLR' v1 glyph graph.
Date: Wed, 10 Feb 2021 18:04:37 +0000

Werner Lemberg pushed to branch master at FreeType / FreeType

Commits:

7 changed files:

Changes:

  • ChangeLog
    1
    +2021-02-09  Dominik Röttsches  <drott@chromium.org>
    
    2
    +
    
    3
    +	[sfnt] Provide optional root transform for 'COLR' v1 glyph graph.
    
    4
    +
    
    5
    +        * include/freetype/freetype.h (FT_Get_Color_Glyph_Paint):
    
    6
    +	Additional function argument `root_transform` to control whether
    
    7
    +	root transform should be returned.
    
    8
    +	(FT_OpaquePaint): Additional tracking field to denote whether
    
    9
    +	root transform is to be returned.
    
    10
    +	* include/freetype/internal/sfnt.h
    
    11
    +	(TT_Get_Color_Glyph_Paint_Func): Propagate additional argument.
    
    12
    +	* src/base/ftobjs.c (FT_Get_Color_Glyph_Paint): Ditto.
    
    13
    +	* src/sfnt/ttcolr.c (tt_face_get_colr_glyph_paint): Return root
    
    14
    +	transform reflecting the size and tranform configured on
    
    15
    +	`FT_Face`.
    
    16
    +	(read_paint): Initialize and track status of insert_root_transform
    
    17
    +	flag.
    
    18
    +
    
    1 19
     2021-02-09  Xavier Claessens  <xavier.claessens@collabora.com>
    
    2 20
     
    
    3 21
     	* meson.build: s/freetype2_dep/freetype_dep/.
    

  • include/freetype/freetype.h
    ... ... @@ -4479,11 +4479,15 @@ FT_BEGIN_HEADER
    4479 4479
        *   p ::
    
    4480 4480
        *     An internal offset to a Paint table, needs to be set to NULL before
    
    4481 4481
        *     passing this struct as an argument to @FT_Get_Paint.
    
    4482
    +   *
    
    4483
    +   *   insert_root_transform ::
    
    4484
    +   *     An internal boolean to track whether an initial root transform is
    
    4485
    +   *     to be provided.  Do not set this value.
    
    4482 4486
        */
    
    4483 4487
       typedef struct  FT_Opaque_Paint_
    
    4484 4488
       {
    
    4485 4489
         FT_Byte*  p;
    
    4486
    -
    
    4490
    +    FT_Bool   insert_root_transform;
    
    4487 4491
       } FT_OpaquePaint;
    
    4488 4492
     
    
    4489 4493
     
    
    ... ... @@ -4879,6 +4883,33 @@ FT_BEGIN_HEADER
    4879 4883
       } FT_COLR_Paint;
    
    4880 4884
     
    
    4881 4885
     
    
    4886
    +  /**************************************************************************
    
    4887
    +   *
    
    4888
    +   * @enum:
    
    4889
    +   *   FT_Color_Root_Transform
    
    4890
    +   *
    
    4891
    +   * @description:
    
    4892
    +   *   An enumeration to specify whether @FT_Get_Color_Glyph_Paint is to
    
    4893
    +   *   return a root transform to configure the client's graphics context
    
    4894
    +   *   matrix.
    
    4895
    +   *
    
    4896
    +   * @values:
    
    4897
    +   *   FT_COLOR_INCLUDE_ROOT_TRANSFORM ::
    
    4898
    +   *     Do include the root transform as the initial @FT_COLR_Paint object.
    
    4899
    +   *
    
    4900
    +   *   FT_COLOR_NO_ROOT_TRANSFORM ::
    
    4901
    +   *     Do not output an initial root transform.
    
    4902
    +   */
    
    4903
    +  typedef enum  FT_Color_Root_Transform_
    
    4904
    +  {
    
    4905
    +    FT_COLOR_INCLUDE_ROOT_TRANSFORM,
    
    4906
    +    FT_COLOR_NO_ROOT_TRANSFORM,
    
    4907
    +
    
    4908
    +    FT_COLOR_ROOT_TRANSFORM_MAX
    
    4909
    +
    
    4910
    +  } FT_Color_Root_Transform;
    
    4911
    +
    
    4912
    +
    
    4882 4913
       /**************************************************************************
    
    4883 4914
        *
    
    4884 4915
        * @function:
    
    ... ... @@ -4898,6 +4929,26 @@ FT_BEGIN_HEADER
    4898 4929
        *   function and specifying a glyph ID, one retrieves the root paint
    
    4899 4930
        *   table for this glyph ID.
    
    4900 4931
        *
    
    4932
    +   *   This function allows control whether an initial root transform is
    
    4933
    +   *   returned to configure scaling, transform, and translation correctly
    
    4934
    +   *   on the client's graphics context.  The initial root transform is
    
    4935
    +   *   computed and returned according to the values configured for @FT_Size
    
    4936
    +   *   and @FT_Set_Transform on the @FT_Face object, see below for details
    
    4937
    +   *   of the `root_transform` parameter.  This has implications for a
    
    4938
    +   *   client 'COLR' v1 implementation: When this function returns an
    
    4939
    +   *   initially computed root transform, at the time of executing the
    
    4940
    +   *   @FT_Paint_Glyph operation, the contours should be retrieved using
    
    4941
    +   *   @FT_Load_Glyph at unscaled, untransformed size.  This is because the
    
    4942
    +   *   root transform applied to the graphics context will take care of
    
    4943
    +   *   correct scaling.
    
    4944
    +   *
    
    4945
    +   *   Alternatively, to allow hinting of contours, at the time of executing
    
    4946
    +   *   @FT_Load_Glyph, the current graphics context transformation matrix
    
    4947
    +   *   can be decomposed into a scaling matrix and a remainder, and
    
    4948
    +   *   @FT_Load_Glyph can be used to retrieve the contours at scaled size.
    
    4949
    +   *   Care must then be taken to blit or clip to the graphics context with
    
    4950
    +   *   taking this remainder transformation into account.
    
    4951
    +   *
    
    4901 4952
        * @input:
    
    4902 4953
        *   face ::
    
    4903 4954
        *     A handle to the parent face object.
    
    ... ... @@ -4905,6 +4956,28 @@ FT_BEGIN_HEADER
    4905 4956
        *   base_glyph ::
    
    4906 4957
        *     The glyph index for which to retrieve the root paint table.
    
    4907 4958
        *
    
    4959
    +   *   root_transform ::
    
    4960
    +   *     Specifies whether an initially computed root is returned by
    
    4961
    +   *     @FT_Paint_Transformed to account for the activated size (see
    
    4962
    +   *     @FT_Activate_Size) and the configured transform and translate (see
    
    4963
    +   *     @FT_Set_Translate).
    
    4964
    +   *
    
    4965
    +   *     This root transform is returned before nodes of the glyph graph of
    
    4966
    +   *     the font are returned.  Subsequent @FT_COLR_Paint structures
    
    4967
    +   *     contain unscaled and untransformed values.  The inserted root
    
    4968
    +   *     transform enables the client application to apply an initial
    
    4969
    +   *     transform to its graphics context.  When executing subsequent
    
    4970
    +   *     FT_COLR_Paint operations, values from @FT_COLR_Paint operations
    
    4971
    +   *     will ultimately be correctly scaled because of the root transform
    
    4972
    +   *     applied to the graphics context.  Use
    
    4973
    +   *     @FT_COLOR_INCLUDE_ROOT_TRANSFORM to include the root transform, use
    
    4974
    +   *     @FT_COLOR_NO_ROOT_TRANSFORM to not include it.  The latter may be
    
    4975
    +   *     useful when traversing the 'COLR' v1 glyph graph and reaching a
    
    4976
    +   *     @FT_PaintColrGlyph.  When recursing into @FT_PaintColrGlyph and
    
    4977
    +   *     painting that inline, no additional root transform is needed as it
    
    4978
    +   *     has already been applied to the graphics context at the beginning
    
    4979
    +   *     of drawing this glyph.
    
    4980
    +   *
    
    4908 4981
        * @output:
    
    4909 4982
        *   paint ::
    
    4910 4983
        *     The @FT_OpaquePaint object that references the actual paint table.
    
    ... ... @@ -4918,9 +4991,10 @@ FT_BEGIN_HEADER
    4918 4991
        *   error, value~0 is returned also.
    
    4919 4992
        */
    
    4920 4993
       FT_EXPORT( FT_Bool )
    
    4921
    -  FT_Get_Color_Glyph_Paint( FT_Face          face,
    
    4922
    -                            FT_UInt          base_glyph,
    
    4923
    -                            FT_OpaquePaint*  paint );
    
    4994
    +  FT_Get_Color_Glyph_Paint( FT_Face                  face,
    
    4995
    +                            FT_UInt                  base_glyph,
    
    4996
    +                            FT_Color_Root_Transform  root_transform,
    
    4997
    +                            FT_OpaquePaint*          paint );
    
    4924 4998
     
    
    4925 4999
     
    
    4926 5000
       /**************************************************************************
    

  • include/freetype/internal/sfnt.h
    ... ... @@ -549,9 +549,10 @@ FT_BEGIN_HEADER
    549 549
        *   error, value~0 is returned also.
    
    550 550
        */
    
    551 551
       typedef FT_Bool
    
    552
    -  ( *TT_Get_Color_Glyph_Paint_Func )( TT_Face          face,
    
    553
    -                                      FT_UInt          base_glyph,
    
    554
    -                                      FT_OpaquePaint  *paint );
    
    552
    +  ( *TT_Get_Color_Glyph_Paint_Func )( TT_Face                   face,
    
    553
    +                                      FT_UInt                   base_glyph,
    
    554
    +                                      FT_Color_Root_Transform   root_transform,
    
    555
    +                                      FT_OpaquePaint           *paint );
    
    555 556
     
    
    556 557
     
    
    557 558
       /**************************************************************************
    

  • src/base/ftobjs.c
    ... ... @@ -5571,9 +5571,10 @@
    5571 5571
       /* documentation is in freetype.h */
    
    5572 5572
     
    
    5573 5573
       FT_EXPORT_DEF ( FT_Bool )
    
    5574
    -  FT_Get_Color_Glyph_Paint( FT_Face          face,
    
    5575
    -                            FT_UInt          base_glyph,
    
    5576
    -                            FT_OpaquePaint*  paint )
    
    5574
    +  FT_Get_Color_Glyph_Paint( FT_Face                  face,
    
    5575
    +                            FT_UInt                  base_glyph,
    
    5576
    +                            FT_Color_Root_Transform  root_transform,
    
    5577
    +                            FT_OpaquePaint*          paint )
    
    5577 5578
       {
    
    5578 5579
         TT_Face       ttface;
    
    5579 5580
         SFNT_Service  sfnt;
    
    ... ... @@ -5589,7 +5590,10 @@
    5589 5590
         sfnt   = (SFNT_Service)ttface->sfnt;
    
    5590 5591
     
    
    5591 5592
         if ( sfnt->get_colr_layer )
    
    5592
    -      return sfnt->get_colr_glyph_paint( ttface, base_glyph, paint );
    
    5593
    +      return sfnt->get_colr_glyph_paint( ttface,
    
    5594
    +                                         base_glyph,
    
    5595
    +                                         root_transform,
    
    5596
    +                                         paint );
    
    5593 5597
         else
    
    5594 5598
           return 0;
    
    5595 5599
       }
    

  • src/sfnt/ttcolr.c
    ... ... @@ -396,8 +396,9 @@
    396 396
           if ( paint_p > ( (FT_Byte*)colr->table + colr->table_size ) )
    
    397 397
             return 0;
    
    398 398
     
    
    399
    -      apaint->u.glyph.paint.p = paint_p;
    
    400
    -      apaint->u.glyph.glyphID = FT_NEXT_USHORT( p );
    
    399
    +      apaint->u.glyph.paint.p                     = paint_p;
    
    400
    +      apaint->u.glyph.paint.insert_root_transform = 0;
    
    401
    +      apaint->u.glyph.glyphID                     = FT_NEXT_USHORT( p );
    
    401 402
         }
    
    402 403
     
    
    403 404
         else if ( apaint->format == FT_COLR_PAINTFORMAT_SOLID )
    
    ... ... @@ -475,7 +476,8 @@
    475 476
           if ( paint_p > ( (FT_Byte*)colr->table + colr->table_size ) )
    
    476 477
             return 0;
    
    477 478
     
    
    478
    -      apaint->u.transformed.paint.p = paint_p;
    
    479
    +      apaint->u.transformed.paint.p                     = paint_p;
    
    480
    +      apaint->u.transformed.paint.insert_root_transform = 0;
    
    479 481
     
    
    480 482
           /* skip VarIdx entries */
    
    481 483
           apaint->u.transformed.affine.xx = FT_NEXT_LONG( p );
    
    ... ... @@ -506,7 +508,8 @@
    506 508
           if ( paint_p > ( (FT_Byte*)colr->table + colr->table_size ) )
    
    507 509
             return 0;
    
    508 510
     
    
    509
    -      apaint->u.translate.paint.p = paint_p;
    
    511
    +      apaint->u.translate.paint.p                     = paint_p;
    
    512
    +      apaint->u.translate.paint.insert_root_transform = 0;
    
    510 513
     
    
    511 514
           /* skip VarIdx entries */
    
    512 515
           apaint->u.translate.dx = FT_NEXT_LONG( p );
    
    ... ... @@ -529,7 +532,8 @@
    529 532
           if ( paint_p > ( (FT_Byte*)colr->table + colr->table_size ) )
    
    530 533
             return 0;
    
    531 534
     
    
    532
    -      apaint->u.rotate.paint.p = paint_p;
    
    535
    +      apaint->u.rotate.paint.p                     = paint_p;
    
    536
    +      apaint->u.rotate.paint.insert_root_transform = 0;
    
    533 537
     
    
    534 538
           /* skip VarIdx entries */
    
    535 539
           apaint->u.rotate.angle = FT_NEXT_LONG( p );
    
    ... ... @@ -555,7 +559,8 @@
    555 559
           if ( paint_p > ( (FT_Byte*)colr->table + colr->table_size ) )
    
    556 560
             return 0;
    
    557 561
     
    
    558
    -      apaint->u.skew.paint.p = paint_p;
    
    562
    +      apaint->u.skew.paint.p                     = paint_p;
    
    563
    +      apaint->u.skew.paint.insert_root_transform = 0;
    
    559 564
     
    
    560 565
           /* skip VarIdx entries */
    
    561 566
           apaint->u.skew.x_skew_angle = FT_NEXT_LONG( p );
    
    ... ... @@ -588,7 +593,10 @@
    588 593
           if ( source_paint_p > ( (FT_Byte*)colr->table + colr->table_size ) )
    
    589 594
             return 0;
    
    590 595
     
    
    591
    -      apaint->u.composite.source_paint.p = source_paint_p;
    
    596
    +      apaint->u.composite.source_paint.p =
    
    597
    +        source_paint_p;
    
    598
    +      apaint->u.composite.source_paint.insert_root_transform =
    
    599
    +        0;
    
    592 600
     
    
    593 601
           composite_mode = FT_NEXT_BYTE( p );
    
    594 602
           if ( composite_mode >= FT_COLR_COMPOSITE_MAX )
    
    ... ... @@ -604,7 +612,10 @@
    604 612
           if ( backdrop_paint_p > ( (FT_Byte*)colr->table + colr->table_size ) )
    
    605 613
             return 0;
    
    606 614
     
    
    607
    -      apaint->u.composite.backdrop_paint.p = backdrop_paint_p;
    
    615
    +      apaint->u.composite.backdrop_paint.p =
    
    616
    +        backdrop_paint_p;
    
    617
    +      apaint->u.composite.backdrop_paint.insert_root_transform =
    
    618
    +        0;
    
    608 619
         }
    
    609 620
     
    
    610 621
         else if ( apaint->format == FT_COLR_PAINTFORMAT_COLR_GLYPH )
    
    ... ... @@ -655,17 +666,16 @@
    655 666
     
    
    656 667
     
    
    657 668
       FT_LOCAL_DEF ( FT_Bool )
    
    658
    -  tt_face_get_colr_glyph_paint( TT_Face          face,
    
    659
    -                                FT_UInt          base_glyph,
    
    660
    -                                FT_OpaquePaint*  opaque_paint )
    
    669
    +  tt_face_get_colr_glyph_paint( TT_Face                  face,
    
    670
    +                                FT_UInt                  base_glyph,
    
    671
    +                                FT_Color_Root_Transform  root_transform,
    
    672
    +                                FT_OpaquePaint*          opaque_paint )
    
    661 673
       {
    
    662
    -    Colr*  colr = (Colr*)face->colr;
    
    663
    -
    
    674
    +    Colr*              colr = (Colr*)face->colr;
    
    664 675
         BaseGlyphV1Record  base_glyph_v1_record;
    
    665 676
         FT_Byte*           p;
    
    666 677
     
    
    667
    -
    
    668
    -    if ( !colr )
    
    678
    +    if ( !colr || !colr->table )
    
    669 679
           return 0;
    
    670 680
     
    
    671 681
         if ( colr->version < 1 || !colr->num_base_glyphs_v1 ||
    
    ... ... @@ -692,6 +702,11 @@
    692 702
     
    
    693 703
         opaque_paint->p = p;
    
    694 704
     
    
    705
    +    if ( root_transform == FT_COLOR_INCLUDE_ROOT_TRANSFORM )
    
    706
    +      opaque_paint->insert_root_transform = 1;
    
    707
    +    else
    
    708
    +      opaque_paint->insert_root_transform = 0;
    
    709
    +
    
    695 710
         return 1;
    
    696 711
       }
    
    697 712
     
    
    ... ... @@ -737,8 +752,12 @@
    737 752
                colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE ) )
    
    738 753
           return 0;
    
    739 754
     
    
    740
    -    paint_offset    = FT_NEXT_ULONG( p );
    
    741
    -    opaque_paint->p = (FT_Byte*)( colr->layers_v1 + paint_offset );
    
    755
    +    paint_offset =
    
    756
    +      FT_NEXT_ULONG( p );
    
    757
    +    opaque_paint->insert_root_transform =
    
    758
    +      0;
    
    759
    +    opaque_paint->p =
    
    760
    +      (FT_Byte*)( colr->layers_v1 + paint_offset );
    
    742 761
     
    
    743 762
         iterator->p = p;
    
    744 763
     
    
    ... ... @@ -794,21 +813,74 @@
    794 813
                          FT_OpaquePaint  opaque_paint,
    
    795 814
                          FT_COLR_Paint*  paint )
    
    796 815
       {
    
    797
    -    Colr*  colr = (Colr*)face->colr;
    
    816
    +    Colr*           colr = (Colr*)face->colr;
    
    817
    +    FT_OpaquePaint  next_paint;
    
    818
    +    FT_Matrix       ft_root_scale;
    
    798 819
     
    
    799
    -    FT_Byte*  p;
    
    820
    +    if ( !colr || !colr->base_glyphs_v1 || !colr->table )
    
    821
    +      return 0;
    
    800 822
     
    
    823
    +    if ( opaque_paint.insert_root_transform )
    
    824
    +    {
    
    825
    +      /* 'COLR' v1 glyph information is returned in unscaled coordinates,
    
    826
    +       * i.e., `FT_Size` is not applied or multiplied into the values.  When
    
    827
    +       * client applications draw color glyphs, they can request to include
    
    828
    +       * a top-level transform, which includes the active `x_scale` and
    
    829
    +       * `y_scale` information for scaling the glyph, as well the additional
    
    830
    +       * transform and translate configured through `FT_Set_Transform`.
    
    831
    +       * This allows client applications to apply this top-level transform
    
    832
    +       * to the graphics context first and only once, then have gradient and
    
    833
    +       * contour scaling applied correctly when performing the additional
    
    834
    +       * drawing operations for subsequenct paints.  Prepare this initial
    
    835
    +       * transform here.
    
    836
    +       */
    
    837
    +      paint->format = FT_COLR_PAINTFORMAT_TRANSFORMED;
    
    801 838
     
    
    802
    -    if ( !colr )
    
    803
    -      return 0;
    
    839
    +      next_paint.p                     = opaque_paint.p;
    
    840
    +      next_paint.insert_root_transform = 0;
    
    841
    +      paint->u.transformed.paint       = next_paint;
    
    804 842
     
    
    805
    -    if ( opaque_paint.p < (FT_Byte*)colr->table                         ||
    
    806
    -         opaque_paint.p >= ( (FT_Byte*)colr->table + colr->table_size ) )
    
    807
    -      return 0;
    
    843
    +      /* `x_scale` and `y_scale` are in 26.6 format, representing the scale
    
    844
    +       * factor to get from font units to requested size.  However, expected
    
    845
    +       * return values are in 16.16, so we shift accordingly with rounding. 
    
    846
    +       */
    
    847
    +      ft_root_scale.xx = ( face->root.size->metrics.x_scale + 32 ) >> 6;
    
    848
    +      ft_root_scale.xy = 0;
    
    849
    +      ft_root_scale.yx = 0;
    
    850
    +      ft_root_scale.yy = ( face->root.size->metrics.y_scale + 32 ) >> 6;
    
    851
    +
    
    852
    +      if ( face->root.internal->transform_flags & 1 )
    
    853
    +        FT_Matrix_Multiply( &face->root.internal->transform_matrix,
    
    854
    +                            &ft_root_scale );
    
    855
    +
    
    856
    +      paint->u.transformed.affine.xx = ft_root_scale.xx;
    
    857
    +      paint->u.transformed.affine.xy = ft_root_scale.xy;
    
    858
    +      paint->u.transformed.affine.yx = ft_root_scale.yx;
    
    859
    +      paint->u.transformed.affine.yy = ft_root_scale.yy;
    
    860
    +
    
    861
    +      /* The translation is specified in 26.6 format and, according to the
    
    862
    +       * documentation of `FT_Set_Translate`, is performed on the character
    
    863
    +       * size given in the last call to `FT_Set_Char_Size`.  The
    
    864
    +       * 'PaintTransformed' paint table's `FT_Affine23` format expects
    
    865
    +       * values in 16.16 format, thus we need to shift by 10 bits.
    
    866
    +       */
    
    867
    +      if ( face->root.internal->transform_flags & 2 )
    
    868
    +      {
    
    869
    +        paint->u.transformed.affine.dx =
    
    870
    +          face->root.internal->transform_delta.x << 10;
    
    871
    +        paint->u.transformed.affine.dy =
    
    872
    +          face->root.internal->transform_delta.y << 10;
    
    873
    +      }
    
    874
    +      else
    
    875
    +      {
    
    876
    +        paint->u.transformed.affine.dx = 0;
    
    877
    +        paint->u.transformed.affine.dy = 0;
    
    878
    +      }
    
    808 879
     
    
    809
    -    p = opaque_paint.p;
    
    880
    +      return 1;
    
    881
    +    }
    
    810 882
     
    
    811
    -    return read_paint( colr, p, paint );
    
    883
    +    return read_paint( colr, opaque_paint.p, paint );
    
    812 884
       }
    
    813 885
     
    
    814 886
     
    

  • src/sfnt/ttcolr.h
    ... ... @@ -43,9 +43,10 @@ FT_BEGIN_HEADER
    43 43
                               FT_LayerIterator*  iterator );
    
    44 44
     
    
    45 45
       FT_LOCAL( FT_Bool )
    
    46
    -  tt_face_get_colr_glyph_paint( TT_Face          face,
    
    47
    -                                FT_UInt          base_glyph,
    
    48
    -                                FT_OpaquePaint*  paint );
    
    46
    +  tt_face_get_colr_glyph_paint( TT_Face                  face,
    
    47
    +                                FT_UInt                  base_glyph,
    
    48
    +                                FT_Color_Root_Transform  root_transform,
    
    49
    +                                FT_OpaquePaint*          paint );
    
    49 50
     
    
    50 51
       FT_LOCAL ( FT_Bool )
    
    51 52
       tt_face_get_paint_layers( TT_Face            face,
    

  • submodules/dlg
    1
    -Subproject commit 9f0c8b221a49bd9581bdb9b79c6393c956ddc8eb
    1
    +Subproject commit 6e83f637efd10b736350496c565c24a86a98b07b


  • reply via email to

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