freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] colr 0c4f47f 6/8: [sfnt] Add 'COLR' v1 API to retrieve color


From: Werner LEMBERG
Subject: [freetype2] colr 0c4f47f 6/8: [sfnt] Add 'COLR' v1 API to retrieve color layers (#59703).
Date: Sat, 2 Jan 2021 04:34:52 -0500 (EST)

branch: colr
commit 0c4f47fc07991b5985ab376d90790c042b4220a7
Author: Dominik Röttsches <drott@chromium.org>
Commit: Werner Lemberg <wl@gnu.org>

    [sfnt] Add 'COLR' v1 API to retrieve color layers (#59703).
    
    * src/sfnt/ttcolr.c (tt_face_get_paint_layers): New function to get
    the layers of a `PaintColrLayers` table in the font, using an
    `FT_LayerIterator` from an `FT_PaintColrLayers` object retrieved via
    `tt_face_get_paint`.
    
    * src/sfnt/ttcolr.h: Updated.
---
 ChangeLog         | 11 +++++++++++
 src/sfnt/ttcolr.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/sfnt/ttcolr.h |  5 +++++
 3 files changed, 68 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 9ac91c4..481a558 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2020-12-16  Dominik Röttsches  <drott@chromium.org>
 
+       [sfnt] Add 'COLR' v1 API to retrieve color layers (#59703).
+
+       * src/sfnt/ttcolr.c (tt_face_get_paint_layers): New function to get
+       the layers of a `PaintColrLayers` table in the font, using an
+       `FT_LayerIterator` from an `FT_PaintColrLayers` object retrieved via
+       `tt_face_get_paint`.
+
+       * src/sfnt/ttcolr.h: Updated.
+
+2020-12-16  Dominik Röttsches  <drott@chromium.org>
+
        [sfnt] Add 'COLR' v1 API to iterate color stops (#59703).
 
        * src/sfnt/ttcolr.c (tt_face_get_colorline_stops): New function to
diff --git a/src/sfnt/ttcolr.c b/src/sfnt/ttcolr.c
index 1e97d87..a39773d 100644
--- a/src/sfnt/ttcolr.c
+++ b/src/sfnt/ttcolr.c
@@ -693,6 +693,58 @@
   }
 
 
+  FT_LOCAL_DEF( FT_Bool )
+  tt_face_get_paint_layers( TT_Face            face,
+                            FT_LayerIterator*  iterator,
+                            FT_OpaquePaint*    opaque_paint )
+  {
+    FT_Byte*   p             = NULL;
+    FT_Byte*   p_first_layer = NULL;
+    FT_UInt32  paint_offset;
+
+    Colr*  colr;
+
+
+    if ( iterator->layer == iterator->num_layers )
+      return 0;
+
+    colr = (Colr*)face->colr;
+    if ( !colr )
+      return 0;
+
+    /*
+     * We have an iterator pointing at a paint offset as part of the
+     * `paintOffset` array in `LayerV1List`.
+     */
+    p = iterator->p;
+
+    /*
+     * Do a cursor sanity check of the iterator.  Counting backwards from
+     * where it stands, we need to end up at a position after the beginning
+     * of the `LayerV1List` table and not after the end of the
+     * `LayerV1List`.
+     */
+    p_first_layer = p -
+                      iterator->layer * LAYER_V1_LIST_PAINT_OFFSET_SIZE -
+                      LAYER_V1_LIST_NUM_LAYERS_SIZE;
+    if ( p_first_layer < (FT_Byte*)colr->layers_v1 )
+      return 0;
+    if ( p_first_layer >= (FT_Byte*)(
+           colr->layers_v1 + LAYER_V1_LIST_NUM_LAYERS_SIZE +
+           colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE ) )
+      return 0;
+
+    paint_offset    = FT_NEXT_ULONG( p );
+    opaque_paint->p = (FT_Byte*)( colr->layers_v1 + paint_offset );
+
+    iterator->p = p;
+
+    iterator->layer++;
+
+    return 1;
+  }
+
+
   FT_LOCAL_DEF ( FT_Bool )
   tt_face_get_colorline_stops( TT_Face                face,
                                FT_ColorStop*          color_stop,
diff --git a/src/sfnt/ttcolr.h b/src/sfnt/ttcolr.h
index 77690f6..4a65cb8 100644
--- a/src/sfnt/ttcolr.h
+++ b/src/sfnt/ttcolr.h
@@ -47,6 +47,11 @@ FT_BEGIN_HEADER
                                 FT_UInt          base_glyph,
                                 FT_OpaquePaint*  paint );
 
+  FT_LOCAL ( FT_Bool )
+  tt_face_get_paint_layers( TT_Face            face,
+                            FT_LayerIterator*  iterator,
+                            FT_OpaquePaint*    paint );
+
   FT_LOCAL( FT_Bool )
   tt_face_get_colorline_stops( TT_Face                face,
                                FT_ColorStop*          color_stop,



reply via email to

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