diff options
author | Dominik Röttsches <drott@chromium.org> | 2020-12-16 17:06:42 +0200 |
---|---|---|
committer | Werner Lemberg <wl@gnu.org> | 2021-01-02 08:42:00 +0100 |
commit | 0c4f47fc07991b5985ab376d90790c042b4220a7 (patch) | |
tree | d4d394d73d53237e9dd840359d9cdfa060983bb5 | |
parent | f0e36dd3998536b7acf5eaf726d34008d2d2f8c9 (diff) | |
download | freetype2-0c4f47fc07991b5985ab376d90790c042b4220a7.tar.gz |
[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.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/sfnt/ttcolr.c | 52 | ||||
-rw-r--r-- | src/sfnt/ttcolr.h | 5 |
3 files changed, 68 insertions, 0 deletions
@@ -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 1e97d87cd..a39773d61 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 77690f668..4a65cb831 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, |