Add color mode option

This commit is contained in:
Adrian Johnson 2022-06-17 21:54:30 +09:30
parent f408ae9269
commit 6bd549e8df
5 changed files with 94 additions and 3 deletions

View file

@ -57,6 +57,7 @@ static const cairo_font_options_t _cairo_font_options_nil = {
CAIRO_HINT_METRICS_DEFAULT,
CAIRO_ROUND_GLYPH_POS_DEFAULT,
NULL, /* variations */
CAIRO_COLOR_MODE_DEFAULT,
CAIRO_COLOR_PALETTE_DEFAULT
};
@ -76,6 +77,7 @@ _cairo_font_options_init_default (cairo_font_options_t *options)
options->hint_metrics = CAIRO_HINT_METRICS_DEFAULT;
options->round_glyph_positions = CAIRO_ROUND_GLYPH_POS_DEFAULT;
options->variations = NULL;
options->color_mode = CAIRO_COLOR_MODE_DEFAULT;
options->palette_index = CAIRO_COLOR_PALETTE_DEFAULT;
}
@ -90,6 +92,7 @@ _cairo_font_options_init_copy (cairo_font_options_t *options,
options->hint_metrics = other->hint_metrics;
options->round_glyph_positions = other->round_glyph_positions;
options->variations = other->variations ? strdup (other->variations) : NULL;
options->color_mode = other->color_mode;
options->palette_index = other->palette_index;
}
@ -259,6 +262,8 @@ cairo_font_options_merge (cairo_font_options_t *options,
}
}
if (other->color_mode != CAIRO_COLOR_MODE_DEFAULT)
options->color_mode = other->color_mode;
if (other->palette_index != CAIRO_COLOR_PALETTE_DEFAULT)
options->palette_index = other->palette_index;
}
@ -298,6 +303,7 @@ cairo_font_options_equal (const cairo_font_options_t *options,
((options->variations == NULL && other->variations == NULL) ||
(options->variations != NULL && other->variations != NULL &&
strcmp (options->variations, other->variations) == 0)) &&
options->color_mode == other->color_mode &&
options->palette_index == other->palette_index);
}
slim_hidden_def (cairo_font_options_equal);
@ -333,7 +339,8 @@ cairo_font_options_hash (const cairo_font_options_t *options)
(options->subpixel_order << 4) |
(options->lcd_filter << 8) |
(options->hint_style << 12) |
(options->hint_metrics << 16)) ^ hash;
(options->hint_metrics << 16) |
(options->color_mode << 20)) ^ hash;
}
slim_hidden_def (cairo_font_options_hash);
@ -631,6 +638,47 @@ cairo_font_options_get_variations (cairo_font_options_t *options)
return options->variations;
}
/**
* cairo_font_options_set_color_mode:
* @options: a #cairo_font_options_t
* @font_color: the new color mode
*
* Sets the color mode for the font options object. This controls
* whether color fonts are to be rendered in color or as outlines.
* See the documentation for #cairo_color_mode_t for full details.
*
* Since: 1.18
**/
cairo_public void
cairo_font_options_set_color_mode (cairo_font_options_t *options,
cairo_color_mode_t color_mode)
{
if (cairo_font_options_status (options))
return;
options->color_mode = color_mode;
}
/**
* cairo_font_options_get_color_mode:
* @options: a #cairo_font_options_t
*
* Gets the color mode for the font options object.
* See the documentation for #cairo_color_mode_t for full details.
*
* Return value: the color mode for the font options object
*
* Since: 1.18
**/
cairo_public cairo_color_mode_t
cairo_font_options_get_color_mode (const cairo_font_options_t *options)
{
if (cairo_font_options_status ((cairo_font_options_t *) options))
return CAIRO_COLOR_MODE_DEFAULT;
return options->color_mode;
}
/**
* cairo_font_options_set_color_palette:
* @options: a #cairo_font_options_t

View file

@ -2664,10 +2664,20 @@ _cairo_ft_scaled_glyph_init (void *abstract_font,
cairo_bool_t hint_metrics = scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF;
/* The font metrics for color glyphs should be the same as the
* outline glyphs. But just in case there aren't, request the
* color or outline metrics based on the font option and if
* the font has color.
*/
int color_flag = 0;
#ifdef FT_LOAD_COLOR
if (unscaled->have_color && scaled_font->base.options.color_mode != CAIRO_COLOR_MODE_NO_COLOR)
color_flag = FT_LOAD_COLOR;
#endif
status = _cairo_ft_scaled_glyph_load_glyph (scaled_font,
scaled_glyph,
face,
load_flags,
load_flags | color_flag,
!hint_metrics,
vertical_layout);
if (unlikely (status))

View file

@ -2901,7 +2901,9 @@ _cairo_surface_show_text_glyphs (cairo_surface_t *surface,
if (unlikely (status))
return status;
if (_cairo_scaled_font_has_color_glyphs (scaled_font)) {
if (_cairo_scaled_font_has_color_glyphs (scaled_font) &&
scaled_font->options.color_mode != CAIRO_COLOR_MODE_NO_COLOR)
{
utf8_copy = malloc (sizeof (char) * utf8_len);
memcpy (utf8_copy, utf8, sizeof (char) * utf8_len);
utf8 = utf8_copy;

View file

@ -195,6 +195,7 @@ struct _cairo_font_options {
cairo_hint_metrics_t hint_metrics;
cairo_round_glyph_positions_t round_glyph_positions;
char *variations;
cairo_color_mode_t color_mode;
unsigned int palette_index;
};

View file

@ -1369,6 +1369,29 @@ typedef enum _cairo_hint_metrics {
CAIRO_HINT_METRICS_ON
} cairo_hint_metrics_t;
/**
* cairo_color_mode_t:
* @CAIRO_COLOR_MODE_DEFAULT: Use the default color mode for
* font backend and target device, since 1.18.
* @CAIRO_COLOR_MODE_NO_COLOR: Disable rendering color glyphs. Glyphs are
* always rendered as outline glyphs, since 1.18.
* @CAIRO_COLOR_MODE_COLOR: Enable rendering color glyphs. If the font
* contains a color presentation for a glyph, and when supported by
* the font backend, the glyph will be rendered in color, since 1.18.
*
* Specifies if color fonts are to be rendered using the the color
* glyphs or outline glyphs. Glyphs that do not have a color
* presentation, and non-color fonts are not affected by this font
* option.
*
* Since: 1.18
**/
typedef enum _cairo_color_mode {
CAIRO_COLOR_MODE_DEFAULT,
CAIRO_COLOR_MODE_NO_COLOR,
CAIRO_COLOR_MODE_COLOR
} cairo_color_mode_t;
/**
* cairo_font_options_t:
*
@ -1448,6 +1471,13 @@ cairo_font_options_set_variations (cairo_font_options_t *options,
#define CAIRO_COLOR_PALETTE_DEFAULT 0
cairo_public void
cairo_font_options_set_color_mode (cairo_font_options_t *options,
cairo_color_mode_t color_mode);
cairo_public cairo_color_mode_t
cairo_font_options_get_color_mode (const cairo_font_options_t *options);
cairo_public unsigned int
cairo_font_options_get_color_palette (const cairo_font_options_t *options);