Make `FT_Get_Color_Glyph_Layer' return FT_Bool.

* include/freetype/freetype.h, src/base/ftobjs.c
(FT_Get_Color_Glyph_Layer, FT_Render_Glyph_Internal): Updated.

* include/freetype/internal/sfnt.h (TT_Get_Colr_Layer_Func),
src/sfnt/ttcolr.h, src/sfnt/ttcolr.c (tt_face_get_colr_layer):
Updated.
This commit is contained in:
Werner Lemberg 2018-07-02 11:41:44 +02:00
parent f6ccb524af
commit 4e3b2473d8
6 changed files with 70 additions and 41 deletions

View File

@ -1,3 +1,14 @@
2018-07-02 Werner Lemberg <wl@gnu.org>
Make `FT_Get_Color_Glyph_Layer' return FT_Bool.
* include/freetype/freetype.h, src/base/ftobjs.c
(FT_Get_Color_Glyph_Layer, FT_Render_Glyph_Internal): Updated.
* include/freetype/internal/sfnt.h (TT_Get_Colr_Layer_Func),
src/sfnt/ttcolr.h, src/sfnt/ttcolr.c (tt_face_get_colr_layer):
Updated.
2018-07-01 Werner Lemberg <wl@gnu.org>
* src/base/ftobjs.c (FT_Get_Color_Glyph_Layer): Guard SFNT function.

View File

@ -4255,6 +4255,9 @@ FT_BEGIN_HEADER
* same object again.
*
* @output:
* aglyph_index ::
* The glyph index of the current layer.
*
* acolor_index ::
* The color index into the font face's color palette of the current
* layer. The value 0xFFFF is special; it doesn't reference a palette
@ -4264,9 +4267,9 @@ FT_BEGIN_HEADER
* The color palette can be retrieved with @FT_Palette_Select.
*
* @return:
* The glyph index of the current layer. If there are no more layers
* (or if there are no layers at all), value~0 gets returned. In case
* of an error, value~0 is returned also.
* Value~1 if everything is OK. If there are no more layers (or if
* there are no layers at all), value~0 gets returned. In case of an
* error, value~0 is returned also.
*
* @note:
* This function is necessary if you want to handle glyph layers by
@ -4282,6 +4285,7 @@ FT_BEGIN_HEADER
* FT_Color* palette;
* FT_LayerIterator iterator;
*
* FT_Bool have_layers;
* FT_UInt layer_glyph_index;
* FT_UInt layer_color_index;
*
@ -4290,33 +4294,41 @@ FT_BEGIN_HEADER
* if ( error )
* palette = NULL;
*
* iterator.p = NULL;
* layer_glyph_index = FT_Get_Color_Glyph_Layer( face,
* glyph_index,
* &layer_color_index,
* &iterator );
* iterator.p = NULL;
* have_layers = FT_Get_Color_Glyph_Layer( face,
* glyph_index,
* &layer_glyph_index,
* &layer_color_index,
* &iterator );
*
* if ( palette && layer_glyph_index )
* if ( palette && have_layers )
* {
* do
* {
* FT_Color layer_color = palette[layer_color_index];
* FT_Color layer_color;
*
*
* if ( layer_color_index == 0xFFFF )
* layer_color = text_foreground_color;
* else
* layer_color = palette[layer_color_index];
*
* // Load and render glyph `layer_glyph_index', then
* // blend resulting pixmap with previously created pixmaps.
* // blend resulting pixmap (using color `layer_color')
* // with previously created pixmaps.
*
* } while ( ( layer_glyph_index =
* FT_Get_Color_Glyph_Layer( face,
* glyph_index,
* &layer_color_index,
* &iterator ) ) != 0 );
* } while ( FT_Get_Color_Glyph_Layer( face,
* glyph_index,
* &layer_glyph_index,
* &layer_color_index,
* &iterator ) );
* }
* }
*/
FT_EXPORT( FT_UInt )
FT_EXPORT( FT_Bool )
FT_Get_Color_Glyph_Layer( FT_Face face,
FT_UInt base_glyph,
FT_UInt *aglyph_index,
FT_UInt *acolor_index,
FT_LayerIterator* iterator );

View File

@ -514,6 +514,9 @@ FT_BEGIN_HEADER
* same object again.
*
* @output:
* aglyph_index ::
* The glyph index of the current layer.
*
* acolor_index ::
* The color index into the font face's color palette of the current
* layer. The value 0xFFFF is special; it doesn't reference a palette
@ -521,13 +524,14 @@ FT_BEGIN_HEADER
* instead (to be set up by the application outside of FreeType).
*
* @return:
* The glyph index of the current layer. If there are no more layers
* (or if there are no layers at all), value~0 gets returned. In case
* of an error, value~0 is returned also.
* Value~1 if everything is OK. If there are no more layers (or if
* there are no layers at all), value~0 gets returned. In case of an
* error, value~0 is returned also.
*/
typedef FT_UInt
typedef FT_Bool
(*TT_Get_Colr_Layer_Func)( TT_Face face,
FT_UInt base_glyph,
FT_UInt *aglyph_index,
FT_UInt *acolor_index,
FT_LayerIterator* iterator );

View File

@ -4517,17 +4517,19 @@
FT_UInt base_glyph = slot->glyph_index;
FT_Bool have_layers;
FT_UInt glyph_index;
FT_UInt color_index;
/* check whether we have colored glyph layers */
iterator.p = NULL;
glyph_index = FT_Get_Color_Glyph_Layer( face,
have_layers = FT_Get_Color_Glyph_Layer( face,
base_glyph,
&glyph_index,
&color_index,
&iterator );
if ( glyph_index )
if ( have_layers )
{
error = FT_New_GlyphSlot( face, NULL );
if ( !error )
@ -4546,7 +4548,7 @@
load_flags &= ~FT_LOAD_COLOR;
/* render into the new `face->glyph' glyph slot */
load_flags |= FT_LOAD_RENDER;
load_flags |= FT_LOAD_RENDER;
error = FT_Load_Glyph( face, glyph_index, load_flags );
if ( error )
@ -4561,11 +4563,11 @@
if ( error )
break;
} while ( ( glyph_index =
FT_Get_Color_Glyph_Layer( face,
base_glyph,
&color_index,
&iterator ) ) != 0 );
} while ( FT_Get_Color_Glyph_Layer( face,
base_glyph,
&glyph_index,
&color_index,
&iterator ) );
if ( !error )
slot->format = FT_GLYPH_FORMAT_BITMAP;
@ -5471,9 +5473,10 @@
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UInt )
FT_EXPORT_DEF( FT_Bool )
FT_Get_Color_Glyph_Layer( FT_Face face,
FT_UInt base_glyph,
FT_UInt *aglyph_index,
FT_UInt *acolor_index,
FT_LayerIterator* iterator )
{
@ -5482,6 +5485,7 @@
if ( !face ||
!aglyph_index ||
!acolor_index ||
!iterator ||
base_glyph >= (FT_UInt)face->num_glyphs )
@ -5496,14 +5500,11 @@
if ( sfnt->get_colr_layer )
return sfnt->get_colr_layer( ttface,
base_glyph,
aglyph_index,
acolor_index,
iterator );
else
{
*acolor_index = 0;
return 0;
}
}

View File

@ -209,15 +209,15 @@
}
FT_LOCAL_DEF( FT_UInt )
FT_LOCAL_DEF( FT_Bool )
tt_face_get_colr_layer( TT_Face face,
FT_UInt base_glyph,
FT_UInt *aglyph_index,
FT_UInt *acolor_index,
FT_LayerIterator* iterator )
{
Colr* colr = (Colr*)face->colr;
Colr* colr = (Colr*)face->colr;
BaseGlyphRecord glyph_record;
FT_UInt glyph_index;
if ( !colr )
@ -252,17 +252,17 @@
if ( iterator->layer >= iterator->num_layers )
return 0;
glyph_index = FT_NEXT_USHORT( iterator->p );
*aglyph_index = FT_NEXT_USHORT( iterator->p );
*acolor_index = FT_NEXT_USHORT( iterator->p );
if ( glyph_index >= FT_FACE( face )->num_glyphs ||
if ( *aglyph_index >= FT_FACE( face )->num_glyphs ||
( *acolor_index != 0xFFFF &&
*acolor_index >= face->palette_data.num_palette_entries ) )
return 0;
iterator->layer++;
return glyph_index;
return 1;
}

View File

@ -36,9 +36,10 @@ FT_BEGIN_HEADER
FT_LOCAL( void )
tt_face_free_colr( TT_Face face );
FT_LOCAL( FT_UInt )
FT_LOCAL( FT_Bool )
tt_face_get_colr_layer( TT_Face face,
FT_UInt base_glyph,
FT_UInt *aglyph_index,
FT_UInt *acolor_index,
FT_LayerIterator* iterator );