freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] colr f0e36dd 5/8: [sfnt] Add 'COLR' v1 API to iterate color


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

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

    [sfnt] Add 'COLR' v1 API to iterate color stops (#59703).
    
    * src/sfnt/ttcolr.c (tt_face_get_colorline_stops): New function to
    return the current `FT_ColorStop` object from `FT_ColorStopIterator`.
    Also increment the iterator.
    
    * src/sfnt/ttcolr.h: Updated.
---
 ChangeLog         | 10 ++++++++++
 src/sfnt/ttcolr.c | 38 ++++++++++++++++++++++++++++++++++++++
 src/sfnt/ttcolr.h |  5 +++++
 3 files changed, 53 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index de74160..9ac91c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 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
+       return the current `FT_ColorStop` object from `FT_ColorStopIterator`.
+       Also increment the iterator.
+
+       * src/sfnt/ttcolr.h: Updated.
+
+2020-12-16  Dominik Röttsches  <drott@chromium.org>
+
        [sfnt] Add API to get actual paint from `FT_OpaquePaint` (#59703).
 
        * src/sfnt/ttcolr.c (tt_face_get_paint): New function to resolve an
diff --git a/src/sfnt/ttcolr.c b/src/sfnt/ttcolr.c
index 0d2b866..1e97d87 100644
--- a/src/sfnt/ttcolr.c
+++ b/src/sfnt/ttcolr.c
@@ -693,6 +693,44 @@
   }
 
 
+  FT_LOCAL_DEF ( FT_Bool )
+  tt_face_get_colorline_stops( TT_Face                face,
+                               FT_ColorStop*          color_stop,
+                               FT_ColorStopIterator  *iterator )
+  {
+    Colr*  colr = (Colr*)face->colr;
+
+    FT_Byte*  p;
+
+
+    if ( iterator->current_color_stop >= iterator->num_color_stops )
+      return 0;
+
+    if ( iterator->p +
+           ( ( iterator->num_color_stops - iterator->current_color_stop ) *
+             COLOR_STOP_SIZE ) >
+         ( (FT_Byte *)colr->table + colr->table_size ) )
+      return 0;
+
+    /* Iterator points at first `ColorStop` of `ColorLine`. */
+    p = iterator->p;
+
+    /* skip VarIdx entries */
+    color_stop->stop_offset = FT_NEXT_USHORT ( p );
+    FT_NEXT_ULONG ( p );
+
+    color_stop->color.palette_index = FT_NEXT_USHORT ( p );
+
+    color_stop->color.alpha = FT_NEXT_USHORT ( p );
+    FT_NEXT_ULONG ( p );
+
+    iterator->p = p;
+    iterator->current_color_stop++;
+
+    return 1;
+  }
+
+
   FT_LOCAL_DEF( FT_Bool )
   tt_face_get_paint( TT_Face         face,
                      FT_OpaquePaint  opaque_paint,
diff --git a/src/sfnt/ttcolr.h b/src/sfnt/ttcolr.h
index cdae3fa..77690f6 100644
--- a/src/sfnt/ttcolr.h
+++ b/src/sfnt/ttcolr.h
@@ -48,6 +48,11 @@ FT_BEGIN_HEADER
                                 FT_OpaquePaint*  paint );
 
   FT_LOCAL( FT_Bool )
+  tt_face_get_colorline_stops( TT_Face                face,
+                               FT_ColorStop*          color_stop,
+                               FT_ColorStopIterator*  iterator );
+
+  FT_LOCAL( FT_Bool )
   tt_face_get_paint( TT_Face         face,
                      FT_OpaquePaint  opaque_paint,
                      FT_COLR_Paint*  paint );



reply via email to

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