diff --git a/ChangeLog b/ChangeLog index 1d4602946..3d8fc5ced 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2018-05-30 Werner Lemberg + + Various minor color fixes. + + * include/freetype/config/ftheader.h (FT_COLOR_H): New macro. + + * include/freetype/internal/ftobjs.h (FT_Colr_Internal): Change + type of `load_flags' to `FT_Int32'. + + * include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func): Change + type of `idx' to `FT_UInt'. + (TT_Blend_Colr_Func): Change type of `color_index' to `FT_UInt'. + + * src/base/ftobjs.c (FT_Render_Glyph_Internal): Change type of + `load_flags' to `FT_Int32'. + + * src/sfnt/ttcolr.c (find_base_glyph_record, + tt_face_load_colr_layers): Change type of `glyph_id' to `FT_UInt'. + (tt_face_find_color, tt_face_colr_blend_layer): Change type of + `color_index' to `FT_UInt'. + Fix signedness and type issues. + + * src/sfnt/ttcolr.h: Updated. + 2018-05-25 Nikhil Ramakrishnan [docmaker] Fix missing `Defined in (...)' under Windows/Cygwin. diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h index 702f77cc4..13e5de7d6 100644 --- a/include/freetype/config/ftheader.h +++ b/include/freetype/config/ftheader.h @@ -760,6 +760,18 @@ #define FT_ADVANCES_H + /************************************************************************* + * + * @macro: + * FT_COLOR_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which handles the OpenType CPAL table. + */ +#define FT_COLOR_H + + /* */ /* These header files don't need to be included by the user. */ diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index 4151b0645..322680a5e 100644 --- a/include/freetype/freetype.h +++ b/include/freetype/freetype.h @@ -1226,8 +1226,8 @@ FT_BEGIN_HEADER /* tricky fonts; they are hard-coded in file `ttobjs.c'. */ /* */ /* FT_FACE_FLAG_COLOR :: */ - /* [Since 2.5.1] The face has color glyph tables. To access color */ - /* glyphs use @FT_LOAD_COLOR. */ + /* [Since 2.5.1] The face has color glyph tables. See */ + /* @FT_LOAD_COLOR for more information. */ /* */ /* FT_FACE_FLAG_VARIATION :: */ /* [Since 2.9] Set if the current face (or named instance) has been */ @@ -2959,11 +2959,24 @@ FT_BEGIN_HEADER * Disable the auto-hinter. See also the note below. * * FT_LOAD_COLOR :: + * Load colored glyphs. There are slight differences depending on the + * font format. + * * [Since 2.5] Load embedded color bitmap images. The resulting color - * bitmaps, if available, will have the @FT_PIXEL_MODE_BGRA format. - * If the flag is not set and color bitmaps are found, they are - * converted to 256-level gray bitmaps transparently, using the - * @FT_PIXEL_MODE_GRAY format. + * bitmaps, if available, will have the @FT_PIXEL_MODE_BGRA format, + * with pre-multiplied color channels. If the flag is not set and + * color bitmaps are found, they are converted to 256-level gray + * bitmaps, using the @FT_PIXEL_MODE_GRAY format. + * + * [Since 2.10] If the glyph index contains an entry in the face's + * `COLR' table with a `CPAL' palette table (as defined in the + * OpenType specification), make @FT_Render_Glyph provide a default + * blending of the color glyph layers associated with the glyph index, + * using the same bitmap format as embedded color bitmap images. This + * is mainly for convenience; for full control of color layers use + * @FT_Get_GlyphLayers and FreeType's color functions like + * @FT_Palette_Select instead of setting FT_LOAD_COLOR for rendering + * so that the client application can handle blending by itself. * * FT_LOAD_COMPUTE_METRICS :: * [Since 2.6.1] Compute glyph metrics from the glyph data, without @@ -3272,6 +3285,14 @@ FT_BEGIN_HEADER /* a bitmap. See @FT_Render_Mode for a list of */ /* possible values. */ /* */ + /* If @FT_RENDER_MODE_NORMAL is used, the flag */ + /* @FT_LOAD_COLOR can be additionally set to make the */ + /* function provide a default blending of colored */ + /* glyph layers associated with the current glyph slot */ + /* (provided the font contains such layers) instead of */ + /* rendering the glyph slot's outline. See */ + /* @FT_LOAD_COLOR for more information. */ + /* */ /* */ /* FreeType error code. 0~means success. */ /* */ @@ -4073,7 +4094,7 @@ FT_BEGIN_HEADER * to this information. * * @FT_Render_Glyph, however, handles colored glyph layers - * automatically. + * automatically if the @FT_LOAD_COLOR flag is passed to it. */ FT_EXPORT( FT_Error ) FT_Get_GlyphLayers( FT_GlyphSlot glyph, diff --git a/include/freetype/ftcolor.h b/include/freetype/ftcolor.h index 91183b8e4..4a2e11d96 100644 --- a/include/freetype/ftcolor.h +++ b/include/freetype/ftcolor.h @@ -74,7 +74,7 @@ FT_BEGIN_HEADER * Alpha value, giving the red, green, and blue color's opacity. * * @since: - * 2.10.0 + * 2.10 */ typedef struct FT_Color_ { @@ -114,7 +114,7 @@ FT_BEGIN_HEADER * `TT_CONFIG_OPTION_COLOR_LAYERS' is not defined in `ftoption.h'. * * @since: - * 2.10.0 + * 2.10 */ FT_EXPORT( FT_Error ) FT_Palette_Get_Size( FT_Face face, @@ -153,7 +153,7 @@ FT_BEGIN_HEADER * `TT_CONFIG_OPTION_COLOR_LAYERS' is not defined in `ftoption.h'. * * @since: - * 2.10.0 + * 2.10 */ FT_EXPORT( FT_Error ) FT_Palette_Get_Names( FT_Face face, @@ -184,7 +184,7 @@ FT_BEGIN_HEADER * @FT_Palette_Get_Size. * * @since: - * 2.10.0 + * 2.10 */ #define FT_PALETTE_USABLE_WITH_LIGHT_BACKGROUND 0x01 #define FT_PALETTE_USABLE_WITH_DARK_BACKGROUND 0x02 @@ -220,7 +220,7 @@ FT_BEGIN_HEADER * `TT_CONFIG_OPTION_COLOR_LAYERS' is not defined in `ftoption.h'. * * @since: - * 2.10.0 + * 2.10 */ FT_EXPORT( FT_Error ) FT_Palette_Get_Types( FT_Face face, @@ -263,7 +263,7 @@ FT_BEGIN_HEADER * `TT_CONFIG_OPTION_COLOR_LAYERS' is not defined in `ftoption.h'. * * @since: - * 2.10.0 + * 2.10 */ FT_EXPORT( FT_Error ) FT_Palette_Get_Entry_Names( FT_Face face, @@ -316,7 +316,7 @@ FT_BEGIN_HEADER * `TT_CONFIG_OPTION_COLOR_LAYERS' is not defined in `ftoption.h'. * * @since: - * 2.10.0 + * 2.10 */ FT_EXPORT( FT_Error ) FT_Palette_Select( FT_Face face, @@ -348,7 +348,7 @@ FT_BEGIN_HEADER * `TT_CONFIG_OPTION_COLOR_LAYERS' is not defined in `ftoption.h'. * * @since: - * 2.10.0 + * 2.10 */ FT_EXPORT( FT_Error ) FT_Palette_Set_Foreground_COlor( FT_Face face, diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index 77f5dc463..b49c78de9 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -388,7 +388,7 @@ FT_BEGIN_HEADER { FT_Glyph_Layer layers; FT_UShort num_layers; - FT_Int load_flags; + FT_Int32 load_flags; } FT_Colr_InternalRec, *FT_Colr_Internal; diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h index d28b6825a..dceb8974c 100644 --- a/include/freetype/internal/sfnt.h +++ b/include/freetype/internal/sfnt.h @@ -453,7 +453,7 @@ FT_BEGIN_HEADER /* */ typedef FT_Error (*TT_Load_Colr_Layer_Func)( TT_Face face, - FT_Int idx, + FT_UInt idx, FT_Glyph_Layer *layers, FT_UShort* num_layers ); @@ -485,7 +485,7 @@ FT_BEGIN_HEADER /* */ typedef FT_Error (*TT_Blend_Colr_Func)( TT_Face face, - FT_Int color_index, + FT_UInt color_index, FT_GlyphSlot base_glyph, FT_GlyphSlot new_glyph ); diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index 2cd0c9293..4770007df 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -4541,7 +4541,7 @@ idx < slot->internal->color_layers->num_layers; idx++ ) { - FT_Int load_flags; + FT_Int32 load_flags; load_flags = slot->internal->color_layers->load_flags diff --git a/src/sfnt/ttcolr.c b/src/sfnt/ttcolr.c index 24d350e6c..395c8c9bf 100644 --- a/src/sfnt/ttcolr.c +++ b/src/sfnt/ttcolr.c @@ -256,7 +256,7 @@ static FT_Bool find_base_glyph_record( FT_Byte* base_glyph_begin, FT_Int num_base_glyph, - FT_UShort glyph_id, + FT_UInt glyph_id, BaseGlyphRecord* record ) { FT_Int min = 0; @@ -291,7 +291,7 @@ FT_LOCAL_DEF( FT_Error ) tt_face_load_colr_layers( TT_Face face, - FT_Int glyph_id, + FT_UInt glyph_id, FT_Glyph_Layer *ret_layers, FT_UShort* ret_num_layers ) { @@ -360,12 +360,12 @@ static FT_Bool - tt_face_find_color( TT_Face face, - FT_UShort color_index, - FT_Byte* blue, - FT_Byte* green, - FT_Byte* red, - FT_Byte* alpha ) + tt_face_find_color( TT_Face face, + FT_UInt color_index, + FT_Byte* blue, + FT_Byte* green, + FT_Byte* red, + FT_Byte* alpha ) { ColrCpal* colr_and_cpal = (ColrCpal *)face->colr_and_cpal; Cpal* cpal = &colr_and_cpal->cpal; @@ -378,7 +378,7 @@ if ( color_index >= cpal->num_palettes_entries ) return 0; - p = cpal->color_indices + palette_index * sizeof ( FT_UShort ); + p = cpal->color_indices + palette_index * (int)sizeof ( FT_UShort ); color_offset = FT_NEXT_USHORT( p ); @@ -395,7 +395,7 @@ FT_LOCAL_DEF( FT_Error ) tt_face_colr_blend_layer( TT_Face face, - FT_Int color_index, + FT_UInt color_index, FT_GlyphSlot dstSlot, FT_GlyphSlot srcSlot ) { @@ -404,7 +404,7 @@ FT_UInt x, y; FT_Byte b, g, r, alpha; - FT_Long size; + FT_ULong size; FT_Byte* src; FT_Byte* dst; @@ -419,10 +419,10 @@ dstSlot->bitmap.width = srcSlot->bitmap.width; dstSlot->bitmap.rows = srcSlot->bitmap.rows; dstSlot->bitmap.pixel_mode = FT_PIXEL_MODE_BGRA; - dstSlot->bitmap.pitch = dstSlot->bitmap.width * 4; + dstSlot->bitmap.pitch = (int)dstSlot->bitmap.width * 4; dstSlot->bitmap.num_grays = 256; - size = dstSlot->bitmap.rows * dstSlot->bitmap.pitch; + size = dstSlot->bitmap.rows * (unsigned int)dstSlot->bitmap.pitch; error = ft_glyphslot_alloc_bitmap( dstSlot, size ); if ( error ) @@ -451,8 +451,8 @@ { FT_Memory memory = face->root.memory; - FT_UInt width = x_max - x_min; - FT_UInt rows = y_max - y_min; + FT_UInt width = (FT_UInt)( x_max - x_min ); + FT_UInt rows = (FT_UInt)( y_max - y_min ); FT_UInt pitch = width * 4; FT_Byte* buf; @@ -466,7 +466,7 @@ p = dstSlot->bitmap.buffer; q = buf + - pitch * ( y_max - dstSlot->bitmap_top ) + + (int)pitch * ( y_max - dstSlot->bitmap_top ) + 4 * ( dstSlot->bitmap_left - x_min ); for ( y = 0; y < dstSlot->bitmap.rows; y++ ) @@ -484,7 +484,7 @@ dstSlot->bitmap.width = width; dstSlot->bitmap.rows = rows; - dstSlot->bitmap.pitch = pitch; + dstSlot->bitmap.pitch = (int)pitch; dstSlot->internal->flags |= FT_GLYPH_OWN_BITMAP; dstSlot->format = FT_GLYPH_FORMAT_BITMAP; @@ -528,10 +528,10 @@ int ba = dst[4 * x + 3]; - dst[4 * x + 0] = bb * ba2 / 255 + fb; - dst[4 * x + 1] = bg * ba2 / 255 + fg; - dst[4 * x + 2] = br * ba2 / 255 + fr; - dst[4 * x + 3] = ba * ba2 / 255 + fa; + dst[4 * x + 0] = (FT_Byte)( bb * ba2 / 255 + fb ); + dst[4 * x + 1] = (FT_Byte)( bg * ba2 / 255 + fg ); + dst[4 * x + 2] = (FT_Byte)( br * ba2 / 255 + fr ); + dst[4 * x + 3] = (FT_Byte)( ba * ba2 / 255 + fa ); } src += srcSlot->bitmap.pitch; diff --git a/src/sfnt/ttcolr.h b/src/sfnt/ttcolr.h index 1c58153a5..bd33f6925 100644 --- a/src/sfnt/ttcolr.h +++ b/src/sfnt/ttcolr.h @@ -38,13 +38,13 @@ FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_load_colr_layers( TT_Face face, - FT_Int glyph_id, + FT_UInt glyph_id, FT_Glyph_Layer *ret_layers, FT_UShort* ret_num_layers ); FT_LOCAL( FT_Error ) tt_face_colr_blend_layer( TT_Face face, - FT_Int color_index, + FT_UInt color_index, FT_GlyphSlot dstSlot, FT_GlyphSlot srcSlot );