view: Add a --font-palette option

This commit is contained in:
Matthias Clasen 2022-12-21 15:18:02 -05:00 committed by Behdad Esfahbod
parent d094e76cbc
commit 5d7553d38f
3 changed files with 14 additions and 1 deletions

View File

@ -69,6 +69,7 @@ struct font_options_t : face_options_t
mutable double font_size_y = DEFAULT_FONT_SIZE;
char *font_funcs = nullptr;
int ft_load_flags = 2;
unsigned int palette = 0;
hb_font_t *font = nullptr;
};
@ -287,6 +288,7 @@ font_options_t::add_options (option_parser_t *parser)
G_OPTION_ARG_DOUBLE, &this->ptem, "Set font point-size (default: 0; disabled)", "point-size"},
{"font-slant", 0, 0,
G_OPTION_ARG_DOUBLE, &this->slant, "Set synthetic slant (default: 0)", "slant ratio; eg. 0.2"},
{"font-palette", 0, 0, G_OPTION_ARG_INT, &this->palette, "Set font palette (default: 0)", "index"},
{"font-funcs", 0, 0, G_OPTION_ARG_STRING, &this->font_funcs, text, "impl"},
{"sub-font", 0, G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_NONE, &this->sub_font, "Create a sub-font (default: false)", "boolean"},

View File

@ -350,6 +350,14 @@ render_color_glyph (cairo_scaled_font_t *scaled_font,
{
hb_font_t *font = (hb_font_t *) (cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
&_hb_font_cairo_user_data_key));
unsigned int palette = 0;
#ifdef CAIRO_COLOR_PALETTE_DEFAULT
cairo_font_options_t *options = cairo_font_options_create ();
cairo_scaled_font_get_font_options (scaled_font, options);
palette = cairo_font_options_get_color_palette (options);
cairo_font_options_destroy (options);
#endif
hb_color_t color = HB_COLOR (0, 0, 0, 255);
cairo_pattern_t *pattern = cairo_get_source (cr);
@ -364,7 +372,7 @@ render_color_glyph (cairo_scaled_font_t *scaled_font,
hb_font_get_scale (font, &x_scale, &y_scale);
cairo_scale (cr, +1./x_scale, -1./y_scale);
hb_font_paint_glyph (font, glyph, get_cairo_paint_funcs (), cr, 0, color);
hb_font_paint_glyph (font, glyph, get_cairo_paint_funcs (), cr, palette, color);
hb_glyph_extents_t hb_extents;
hb_font_get_glyph_extents (font, glyph, &hb_extents);

View File

@ -118,6 +118,9 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts)
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
#ifdef CAIRO_COLOR_PALETTE_DEFAULT
cairo_font_options_set_color_palette (font_options, font_opts->palette);
#endif
cairo_scaled_font_t *scaled_font = cairo_scaled_font_create (cairo_face,
&font_matrix,