FreeType » Docs » Extended API » Glyph Color Management
Glyph Color Management¶
Synopsis¶
The functions described here allow access and manipulation of color palette entries in OpenType's ‘CPAL’ tables.
FT_Color¶
Defined in FT_COLOR_H (freetype/ftcolor.h).
This structure models a BGRA color value of a ‘CPAL’ palette entry.
The used color space is sRGB; the colors are not pre-multiplied, and alpha values must be explicitly set.
fields
blue |
Blue value. |
green |
Green value. |
red |
Red value. |
alpha |
Alpha value, giving the red, green, and blue color's opacity. |
since
2.10
FT_PALETTE_XXX¶
Defined in FT_COLOR_H (freetype/ftcolor.h).
#define FT_PALETTE_FOR_LIGHT_BACKGROUND 0x01
#define FT_PALETTE_FOR_DARK_BACKGROUND 0x02
A list of bit field constants used in the palette_flags
array of the FT_Palette_Data
structure to indicate for which background a palette with a given index is usable.
values
FT_PALETTE_FOR_LIGHT_BACKGROUND |
The palette is appropriate to use when displaying the font on a light background such as white. |
FT_PALETTE_FOR_DARK_BACKGROUND |
The palette is appropriate to use when displaying the font on a dark background such as black. |
since
2.10
FT_Palette_Data¶
Defined in FT_COLOR_H (freetype/ftcolor.h).
typedef struct FT_Palette_Data_ {
FT_UShort num_palettes;
const FT_UShort* palette_name_ids;
const FT_UShort* palette_flags;
FT_UShort num_palette_entries;
const FT_UShort* palette_entry_name_ids;
} FT_Palette_Data;
This structure holds the data of the ‘CPAL’ table.
fields
num_palettes |
The number of palettes. |
palette_name_ids |
An optional read-only array of palette name IDs with An empty name ID in the ‘CPAL’ table gets represented as value 0xFFFF.
|
palette_flags |
An optional read-only array of palette flags with
|
num_palette_entries |
The number of entries in a single palette. All palettes have the same size. |
palette_entry_name_ids |
An optional read-only array of palette entry name IDs with An empty entry name ID in the ‘CPAL’ table gets represented as value 0xFFFF.
|
note
Use function FT_Get_Sfnt_Name
to map name IDs and entry name IDs to name strings.
Use function FT_Palette_Select
to get the colors associated with a palette entry.
since
2.10
FT_Palette_Data_Get¶
Defined in FT_COLOR_H (freetype/ftcolor.h).
FT_EXPORT( FT_Error )
FT_Palette_Data_Get( FT_Face face,
FT_Palette_Data *apalette );
Retrieve the face's color palette data.
input
face |
The source face handle. |
output
apalette |
A pointer to an |
return
FreeType error code. 0 means success.
note
All arrays in the returned FT_Palette_Data
structure are read-only.
This function always returns an error if the config macro TT_CONFIG_OPTION_COLOR_LAYERS
is not defined in ftoption.h
.
since
2.10
FT_Palette_Select¶
Defined in FT_COLOR_H (freetype/ftcolor.h).
FT_EXPORT( FT_Error )
FT_Palette_Select( FT_Face face,
FT_UShort palette_index,
FT_Color* *apalette );
This function has two purposes.
(1) It activates a palette for rendering color glyphs, and
(2) it retrieves all (unmodified) color entries of this palette. This function returns a read-write array, which means that a calling application can modify the palette entries on demand.
A corollary of (2) is that calling the function, then modifying some values, then calling the function again with the same arguments resets all color entries to the original ‘CPAL’ values; all user modifications are lost.
input
face |
The source face handle. |
palette_index |
The palette index. |
output
apalette |
An array of color entries for a palette with index In case the font doesn't support color palettes, |
return
FreeType error code. 0 means success.
note
The array pointed to by apalette_entries
is owned and managed by FreeType.
This function always returns an error if the config macro TT_CONFIG_OPTION_COLOR_LAYERS
is not defined in ftoption.h
.
since
2.10
FT_Palette_Set_Foreground_Color¶
Defined in FT_COLOR_H (freetype/ftcolor.h).
‘COLR’ uses palette index 0xFFFF to indicate a ‘text foreground color’. This function sets this value.
input
face |
The source face handle. |
foreground_color |
An |
return
FreeType error code. 0 means success.
note
If this function isn't called, the text foreground color is set to white opaque (BGRA value 0xFFFFFFFF) if FT_PALETTE_FOR_DARK_BACKGROUND
is present for the current palette, and black opaque (BGRA value 0x000000FF) otherwise, including the case that no palette types are available in the ‘CPAL’ table.
This function always returns an error if the config macro TT_CONFIG_OPTION_COLOR_LAYERS
is not defined in ftoption.h
.
since
2.10