freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] [sfnt] Add API for retrieving a 'COLR'


From: Werner Lemberg (@wl)
Subject: [Git][freetype/freetype][master] [sfnt] Add API for retrieving a 'COLR' v1 'ClipBox' table.
Date: Sat, 07 Aug 2021 12:44:34 +0000

Werner Lemberg pushed to branch master at FreeType / FreeType

Commits:

6 changed files:

Changes:

  • include/freetype/ftcolor.h
    ... ... @@ -1383,6 +1383,49 @@ FT_BEGIN_HEADER
    1383 1383
       } FT_Color_Root_Transform;
    
    1384 1384
     
    
    1385 1385
     
    
    1386
    +  /**************************************************************************
    
    1387
    +   *
    
    1388
    +   * @struct:
    
    1389
    +   *   FT_ClipBox
    
    1390
    +   *
    
    1391
    +   * @description:
    
    1392
    +   *   A structure representing a 'COLR' v1 'ClipBox' table.  'COLR' v1
    
    1393
    +   *   glyphs may optionally define a clip box for aiding allocation or
    
    1394
    +   *   defining a maximum drawable region.  Use @FT_Get_Color_Glyph_ClipBox
    
    1395
    +   *   to retrieve it.
    
    1396
    +   *
    
    1397
    +   * @fields:
    
    1398
    +   *   bottom_left ::
    
    1399
    +   *     The bottom left corner of the clip box as an @FT_Vector with
    
    1400
    +   *     fixed-point coordinates in 26.6 format.
    
    1401
    +   *
    
    1402
    +   *   top_left ::
    
    1403
    +   *     The top left corner of the clip box as an @FT_Vector with
    
    1404
    +   *     fixed-point coordinates in 26.6 format.
    
    1405
    +   *
    
    1406
    +   *   top_right ::
    
    1407
    +   *     The top right corner of the clip box as an @FT_Vector with
    
    1408
    +   *     fixed-point coordinates in 26.6 format.
    
    1409
    +   *
    
    1410
    +   *   bottom_right ::
    
    1411
    +   *     The bottom right corner of the clip box as an @FT_Vector with
    
    1412
    +   *     fixed-point coordinates in 26.6 format.
    
    1413
    +   *
    
    1414
    +   * @since:
    
    1415
    +   *   2.12 -- **currently experimental only!**  There might be changes
    
    1416
    +   *   without retaining backward compatibility of both the API and ABI.
    
    1417
    +   *
    
    1418
    +   */
    
    1419
    +  typedef struct  FT_ClipBox_
    
    1420
    +  {
    
    1421
    +    FT_Vector  bottom_left;
    
    1422
    +    FT_Vector  top_left;
    
    1423
    +    FT_Vector  top_right;
    
    1424
    +    FT_Vector  bottom_right;
    
    1425
    +
    
    1426
    +  } FT_ClipBox;
    
    1427
    +
    
    1428
    +
    
    1386 1429
       /**************************************************************************
    
    1387 1430
        *
    
    1388 1431
        * @function:
    
    ... ... @@ -1475,6 +1518,49 @@ FT_BEGIN_HEADER
    1475 1518
                                 FT_OpaquePaint*          paint );
    
    1476 1519
     
    
    1477 1520
     
    
    1521
    +  /**************************************************************************
    
    1522
    +   *
    
    1523
    +   * @function:
    
    1524
    +   *   FT_Get_Color_Glyph_ClipBox
    
    1525
    +   *
    
    1526
    +   * @description:
    
    1527
    +   *   Search for a 'COLR' v1 clip box for the specified `base_glyph` and
    
    1528
    +   *   fill the `clip_box` parameter with the 'COLR' v1 'ClipBox' information
    
    1529
    +   *   if one is found.
    
    1530
    +   *
    
    1531
    +   * @input:
    
    1532
    +   *   face ::
    
    1533
    +   *     A handle to the parent face object.
    
    1534
    +   *
    
    1535
    +   *   base_glyph ::
    
    1536
    +   *     The glyph index for which to retrieve the clip box.
    
    1537
    +   *
    
    1538
    +   * @output:
    
    1539
    +   *   clip_box ::
    
    1540
    +   *     The clip box for the requested `base_glyph` if one is found.  The
    
    1541
    +   *     clip box is computed taking scale and transformations configured on
    
    1542
    +   *     the @FT_Face into account.  @FT_ClipBox contains @FT_Vector values
    
    1543
    +   *     in 26.6 format.
    
    1544
    +   *
    
    1545
    +   * @return:
    
    1546
    +   *   Value~1 if a clip box is found.  If no clip box is found or an error
    
    1547
    +   *   occured, value~0 is returned.
    
    1548
    +   *
    
    1549
    +   * @note:
    
    1550
    +   *   To retrieve the clip box in font units, reset scale to units-per-em
    
    1551
    +   *   and remove transforms configured using @FT_Set_Transform.
    
    1552
    +   *
    
    1553
    +   * @since:
    
    1554
    +   *   2.12 -- **currently experimental only!**  There might be changes
    
    1555
    +   *   without retaining backward compatibility of both the API and ABI.
    
    1556
    +   *
    
    1557
    +   */
    
    1558
    +  FT_EXPORT( FT_Bool )
    
    1559
    +  FT_Get_Color_Glyph_ClipBox( FT_Face      face,
    
    1560
    +                              FT_UInt      base_glyph,
    
    1561
    +                              FT_ClipBox*  clip_box );
    
    1562
    +
    
    1563
    +
    
    1478 1564
       /**************************************************************************
    
    1479 1565
        *
    
    1480 1566
        * @function:
    

  • include/freetype/internal/sfnt.h
    ... ... @@ -555,6 +555,44 @@ FT_BEGIN_HEADER
    555 555
                                           FT_OpaquePaint           *paint );
    
    556 556
     
    
    557 557
     
    
    558
    +  /**************************************************************************
    
    559
    +   *
    
    560
    +   * @functype:
    
    561
    +   *   TT_Get_Color_Glyph_ClipBox_Func
    
    562
    +   *
    
    563
    +   * @description:
    
    564
    +   *   Search for a 'COLR' v1 clip box for the specified `base_glyph` and
    
    565
    +   *   fill the `clip_box` parameter with the 'COLR' v1 'ClipBox' information
    
    566
    +   *   if one is found.
    
    567
    +   *
    
    568
    +   * @input:
    
    569
    +   *   face ::
    
    570
    +   *     A handle to the parent face object.
    
    571
    +   *
    
    572
    +   *   base_glyph ::
    
    573
    +   *     The glyph index for which to retrieve the clip box.
    
    574
    +   *
    
    575
    +   * @output:
    
    576
    +   *   clip_box ::
    
    577
    +   *     The clip box for the requested base_glyph if one is found.  The clip
    
    578
    +   *     box is computed taking scale and transformations configured on the
    
    579
    +   *     @FT_Face into account.  @FT_ClipBox contains @FT_Vector values in
    
    580
    +   *     26.6 format.
    
    581
    +   *
    
    582
    +   * @note:
    
    583
    +   *     To retrieve the clip box in font units, reset scale to units-per-em
    
    584
    +   *     and remove transforms configured using @FT_Set_Transform.
    
    585
    +   *
    
    586
    +   * @return:
    
    587
    +   *   Value~1 if a ClipBox is found.  If no clip box is found or an
    
    588
    +   *   error occured, value~0 is returned.
    
    589
    +   */
    
    590
    +  typedef FT_Bool
    
    591
    +  ( *TT_Get_Color_Glyph_ClipBox_Func )( TT_Face      face,
    
    592
    +                                        FT_UInt      base_glyph,
    
    593
    +                                        FT_ClipBox*  clip_box );
    
    594
    +
    
    595
    +
    
    558 596
       /**************************************************************************
    
    559 597
        *
    
    560 598
        * @functype:
    
    ... ... @@ -890,17 +928,18 @@ FT_BEGIN_HEADER
    890 928
         TT_Set_SBit_Strike_Func      set_sbit_strike;
    
    891 929
         TT_Load_Strike_Metrics_Func  load_strike_metrics;
    
    892 930
     
    
    893
    -    TT_Load_Table_Func             load_cpal;
    
    894
    -    TT_Load_Table_Func             load_colr;
    
    895
    -    TT_Free_Table_Func             free_cpal;
    
    896
    -    TT_Free_Table_Func             free_colr;
    
    897
    -    TT_Set_Palette_Func            set_palette;
    
    898
    -    TT_Get_Colr_Layer_Func         get_colr_layer;
    
    899
    -    TT_Get_Color_Glyph_Paint_Func  get_colr_glyph_paint;
    
    900
    -    TT_Get_Paint_Layers_Func       get_paint_layers;
    
    901
    -    TT_Get_Colorline_Stops_Func    get_colorline_stops;
    
    902
    -    TT_Get_Paint_Func              get_paint;
    
    903
    -    TT_Blend_Colr_Func             colr_blend;
    
    931
    +    TT_Load_Table_Func               load_cpal;
    
    932
    +    TT_Load_Table_Func               load_colr;
    
    933
    +    TT_Free_Table_Func               free_cpal;
    
    934
    +    TT_Free_Table_Func               free_colr;
    
    935
    +    TT_Set_Palette_Func              set_palette;
    
    936
    +    TT_Get_Colr_Layer_Func           get_colr_layer;
    
    937
    +    TT_Get_Color_Glyph_Paint_Func    get_colr_glyph_paint;
    
    938
    +    TT_Get_Color_Glyph_ClipBox_Func  get_color_glyph_clipbox;
    
    939
    +    TT_Get_Paint_Layers_Func         get_paint_layers;
    
    940
    +    TT_Get_Colorline_Stops_Func      get_colorline_stops;
    
    941
    +    TT_Get_Paint_Func                get_paint;
    
    942
    +    TT_Blend_Colr_Func               colr_blend;
    
    904 943
     
    
    905 944
         TT_Get_Metrics_Func  get_metrics;
    
    906 945
     
    
    ... ... @@ -951,6 +990,7 @@ FT_BEGIN_HEADER
    951 990
               set_palette_,                  \
    
    952 991
               get_colr_layer_,               \
    
    953 992
               get_colr_glyph_paint_,         \
    
    993
    +          get_color_glyph_clipbox,       \
    
    954 994
               get_paint_layers_,             \
    
    955 995
               get_colorline_stops_,          \
    
    956 996
               get_paint_,                    \
    
    ... ... @@ -995,6 +1035,7 @@ FT_BEGIN_HEADER
    995 1035
         set_palette_,                        \
    
    996 1036
         get_colr_layer_,                     \
    
    997 1037
         get_colr_glyph_paint_,               \
    
    1038
    +    get_color_glyph_clipbox,             \
    
    998 1039
         get_paint_layers_,                   \
    
    999 1040
         get_colorline_stops_,                \
    
    1000 1041
         get_paint_,                          \
    

  • src/base/ftobjs.c
    ... ... @@ -5639,6 +5639,35 @@
    5639 5639
       }
    
    5640 5640
     
    
    5641 5641
     
    
    5642
    +  /* documentation is in ftcolor.h */
    
    5643
    +
    
    5644
    +  FT_EXPORT_DEF( FT_Bool )
    
    5645
    +  FT_Get_Color_Glyph_ClipBox( FT_Face      face,
    
    5646
    +                              FT_UInt      base_glyph,
    
    5647
    +                              FT_ClipBox*  clip_box )
    
    5648
    +  {
    
    5649
    +    TT_Face       ttface;
    
    5650
    +    SFNT_Service  sfnt;
    
    5651
    +
    
    5652
    +
    
    5653
    +    if ( !face || !clip_box )
    
    5654
    +      return 0;
    
    5655
    +
    
    5656
    +    if ( !FT_IS_SFNT( face ) )
    
    5657
    +      return 0;
    
    5658
    +
    
    5659
    +    ttface = (TT_Face)face;
    
    5660
    +    sfnt   = (SFNT_Service)ttface->sfnt;
    
    5661
    +
    
    5662
    +    if ( sfnt->get_color_glyph_clipbox )
    
    5663
    +      return sfnt->get_color_glyph_clipbox( ttface,
    
    5664
    +                                            base_glyph,
    
    5665
    +                                            clip_box );
    
    5666
    +    else
    
    5667
    +      return 0;
    
    5668
    +  }
    
    5669
    +
    
    5670
    +
    
    5642 5671
       /* documentation is in freetype.h */
    
    5643 5672
     
    
    5644 5673
       FT_EXPORT_DEF( FT_Bool )
    

  • src/sfnt/sfdriver.c
    ... ... @@ -1292,13 +1292,15 @@
    1292 1292
                                 /* TT_Get_Colr_Layer_Func  get_colr_layer  */
    
    1293 1293
     
    
    1294 1294
         PUT_COLOR_LAYERS_V1( tt_face_get_colr_glyph_paint ),
    
    1295
    -                 /* TT_Get_Colr_Glyph_Paint_Func  get_colr_glyph_paint */
    
    1295
    +              /* TT_Get_Color_Glyph_Paint_Func    get_colr_glyph_paint */
    
    1296
    +    PUT_COLOR_LAYERS_V1( tt_face_get_color_glyph_clipbox ),
    
    1297
    +              /* TT_Get_Color_Glyph_ClipBox_Func  get_clipbox          */
    
    1296 1298
         PUT_COLOR_LAYERS_V1( tt_face_get_paint_layers ),
    
    1297
    -                 /* TT_Get_Paint_Layers_Func      get_paint_layers     */
    
    1299
    +              /* TT_Get_Paint_Layers_Func         get_paint_layers     */
    
    1298 1300
         PUT_COLOR_LAYERS_V1( tt_face_get_colorline_stops ),
    
    1299
    -                 /* TT_Get_Paint                  get_paint            */
    
    1301
    +              /* TT_Get_Paint                     get_paint            */
    
    1300 1302
         PUT_COLOR_LAYERS_V1( tt_face_get_paint ),
    
    1301
    -                 /* TT_Get_Colorline_Stops_Func   get_colorline_stops  */
    
    1303
    +              /* TT_Get_Colorline_Stops_Func      get_colorline_stops  */
    
    1302 1304
     
    
    1303 1305
         PUT_COLOR_LAYERS( tt_face_colr_blend_layer ),
    
    1304 1306
                                 /* TT_Blend_Colr_Func      colr_blend      */
    

  • src/sfnt/ttcolr.c
    ... ... @@ -94,6 +94,8 @@
    94 94
         FT_ULong  num_layers_v1;
    
    95 95
         FT_Byte*  layers_v1;
    
    96 96
     
    
    97
    +    FT_Byte*  clip_list;
    
    98
    +
    
    97 99
         /*
    
    98 100
          * Paint tables start at the minimum of the end of the LayerList and the
    
    99 101
          * end of the BaseGlyphList.  Record this location in a field here for
    
    ... ... @@ -134,7 +136,7 @@
    134 136
     
    
    135 137
         FT_ULong  base_glyph_offset, layer_offset;
    
    136 138
         FT_ULong  base_glyphs_offset_v1, num_base_glyphs_v1;
    
    137
    -    FT_ULong  layer_offset_v1, num_layers_v1;
    
    139
    +    FT_ULong  layer_offset_v1, num_layers_v1, clip_list_offset;
    
    138 140
         FT_ULong  table_size;
    
    139 141
     
    
    140 142
     
    
    ... ... @@ -226,6 +228,16 @@
    226 228
               colr->base_glyphs_v1 +
    
    227 229
               colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE;
    
    228 230
           }
    
    231
    +
    
    232
    +      clip_list_offset = FT_NEXT_ULONG( p );
    
    233
    +
    
    234
    +      if ( clip_list_offset >= table_size )
    
    235
    +        goto InvalidTable;
    
    236
    +
    
    237
    +      if ( clip_list_offset )
    
    238
    +        colr->clip_list = (FT_Byte*)( table + clip_list_offset );
    
    239
    +      else
    
    240
    +        colr->clip_list = 0;
    
    229 241
         }
    
    230 242
     
    
    231 243
         colr->base_glyphs = (FT_Byte*)( table + base_glyph_offset );
    
    ... ... @@ -796,6 +808,117 @@
    796 808
       }
    
    797 809
     
    
    798 810
     
    
    811
    +  FT_LOCAL_DEF( FT_Bool )
    
    812
    +  tt_face_get_color_glyph_clipbox( TT_Face      face,
    
    813
    +                                   FT_UInt      base_glyph,
    
    814
    +                                   FT_ClipBox*  clip_box )
    
    815
    +  {
    
    816
    +    Colr*  colr;
    
    817
    +
    
    818
    +    FT_Byte  *p, *p1, *clip_base;
    
    819
    +
    
    820
    +    FT_Byte    clip_list_format;
    
    821
    +    FT_ULong   num_clip_boxes, i;
    
    822
    +    FT_UShort  gid_start, gid_end;
    
    823
    +    FT_UInt32  clip_box_offset;
    
    824
    +    FT_Byte    format;
    
    825
    +
    
    826
    +    const FT_Byte  num_corners = 4;
    
    827
    +    FT_Vector      corners[4];
    
    828
    +    FT_Byte        j;
    
    829
    +    FT_BBox        font_clip_box;
    
    830
    +
    
    831
    +
    
    832
    +    colr = (Colr*)face->colr;
    
    833
    +    if ( !colr )
    
    834
    +      return 0;
    
    835
    +
    
    836
    +    if ( !colr->clip_list )
    
    837
    +      return 0;
    
    838
    +
    
    839
    +    p = colr->clip_list;
    
    840
    +
    
    841
    +    clip_base        = p;
    
    842
    +    clip_list_format = FT_NEXT_BYTE ( p );
    
    843
    +
    
    844
    +    /* Format byte used here to be able to upgrade ClipList for >16bit */
    
    845
    +    /* glyph ids; for now we can expect it to be 0. */
    
    846
    +    if ( !( clip_list_format == 0 ) )
    
    847
    +      return 0;
    
    848
    +
    
    849
    +    num_clip_boxes = FT_NEXT_ULONG( p );
    
    850
    +
    
    851
    +    for ( i = 0; i < num_clip_boxes; ++i )
    
    852
    +    {
    
    853
    +      gid_start       = FT_NEXT_USHORT( p );
    
    854
    +      gid_end         = FT_NEXT_USHORT( p );
    
    855
    +      clip_box_offset = FT_NEXT_UOFF3( p );
    
    856
    +
    
    857
    +      if ( base_glyph >= gid_start && base_glyph <= gid_end )
    
    858
    +      {
    
    859
    +        p1 = (FT_Byte*)( clip_base + clip_box_offset );
    
    860
    +
    
    861
    +        if ( p1 >= ( (FT_Byte*)colr->table + colr->table_size ) )
    
    862
    +          return 0;
    
    863
    +
    
    864
    +        format = FT_NEXT_BYTE( p1 );
    
    865
    +
    
    866
    +        if ( format < 0 || format > 1 )
    
    867
    +          return 0;
    
    868
    +
    
    869
    +        /* `face->root.size->metrics.x_scale` and `y_scale` are factors   */
    
    870
    +        /* that scale a font unit value in integers to a 26.6 fixed value */
    
    871
    +        /* according to the requested size, see for example               */
    
    872
    +        /* `ft_recompute_scaled_metrics`.                                 */
    
    873
    +        font_clip_box.xMin = FT_MulFix( FT_NEXT_SHORT( p1 ),
    
    874
    +                                        face->root.size->metrics.x_scale );
    
    875
    +        font_clip_box.yMin = FT_MulFix( FT_NEXT_SHORT( p1 ),
    
    876
    +                                        face->root.size->metrics.x_scale );
    
    877
    +        font_clip_box.xMax = FT_MulFix( FT_NEXT_SHORT( p1 ),
    
    878
    +                                        face->root.size->metrics.x_scale );
    
    879
    +        font_clip_box.yMax = FT_MulFix( FT_NEXT_SHORT( p1 ),
    
    880
    +                                        face->root.size->metrics.x_scale );
    
    881
    +
    
    882
    +        /* Make 4 corner points (xMin, yMin), (xMax, yMax) and transform */
    
    883
    +        /* them.  If we we would only transform two corner points and    */
    
    884
    +        /* span a rectangle based on those, the rectangle may become too */
    
    885
    +        /* small to cover the glyph.                                     */
    
    886
    +        corners[0].x = font_clip_box.xMin;
    
    887
    +        corners[1].x = font_clip_box.xMin;
    
    888
    +        corners[2].x = font_clip_box.xMax;
    
    889
    +        corners[3].x = font_clip_box.xMax;
    
    890
    +
    
    891
    +        corners[0].y = font_clip_box.yMin;
    
    892
    +        corners[1].y = font_clip_box.yMax;
    
    893
    +        corners[2].y = font_clip_box.yMax;
    
    894
    +        corners[3].y = font_clip_box.yMin;
    
    895
    +
    
    896
    +        for ( j = 0; j < num_corners; ++j )
    
    897
    +        {
    
    898
    +          if ( face->root.internal->transform_flags & 1 )
    
    899
    +            FT_Vector_Transform( &corners[j],
    
    900
    +                                 &face->root.internal->transform_matrix );
    
    901
    +
    
    902
    +          if ( face->root.internal->transform_flags & 2 )
    
    903
    +          {
    
    904
    +            corners[j].x += face->root.internal->transform_delta.x;
    
    905
    +            corners[j].y += face->root.internal->transform_delta.y;
    
    906
    +          }
    
    907
    +        }
    
    908
    +
    
    909
    +        clip_box->bottom_left  = corners[0];
    
    910
    +        clip_box->top_left     = corners[1];
    
    911
    +        clip_box->top_right    = corners[2];
    
    912
    +        clip_box->bottom_right = corners[3];
    
    913
    +
    
    914
    +        return 1;
    
    915
    +      }
    
    916
    +    }
    
    917
    +
    
    918
    +    return 0;
    
    919
    +  }
    
    920
    +
    
    921
    +
    
    799 922
       FT_LOCAL_DEF( FT_Bool )
    
    800 923
       tt_face_get_paint_layers( TT_Face            face,
    
    801 924
                                 FT_LayerIterator*  iterator,
    

  • src/sfnt/ttcolr.h
    ... ... @@ -48,6 +48,11 @@ FT_BEGIN_HEADER
    48 48
                                     FT_Color_Root_Transform  root_transform,
    
    49 49
                                     FT_OpaquePaint*          paint );
    
    50 50
     
    
    51
    +  FT_LOCAL( FT_Bool )
    
    52
    +  tt_face_get_color_glyph_clipbox( TT_Face      face,
    
    53
    +                                   FT_UInt      base_glyph,
    
    54
    +                                   FT_ClipBox*  clip_box );
    
    55
    +
    
    51 56
       FT_LOCAL( FT_Bool )
    
    52 57
       tt_face_get_paint_layers( TT_Face            face,
    
    53 58
                                 FT_LayerIterator*  iterator,
    


  • reply via email to

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