From 6260b4901c66b8f03a5f4aa95b5f3842a10db6a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20R=C3=B6ttsches?= Date: Wed, 16 Dec 2020 17:06:42 +0200 Subject: [PATCH] [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 5b3ee82d6..dd73988eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2020-12-16 Dominik Röttsches + + [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 [sfnt] Add 'COLR' v1 API to iterate color stops (#59703). 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,