From 5d7553d38f178c1c071f356f98bbf43d21b4ce29 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 21 Dec 2022 15:18:02 -0500 Subject: [PATCH] view: Add a --font-palette option --- util/font-options.hh | 2 ++ util/helper-cairo-user.hh | 10 +++++++++- util/helper-cairo.hh | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/util/font-options.hh b/util/font-options.hh index 331efd7da..6dd8e3b12 100644 --- a/util/font-options.hh +++ b/util/font-options.hh @@ -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"}, diff --git a/util/helper-cairo-user.hh b/util/helper-cairo-user.hh index f115d7be1..00ca3cc90 100644 --- a/util/helper-cairo-user.hh +++ b/util/helper-cairo-user.hh @@ -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); diff --git a/util/helper-cairo.hh b/util/helper-cairo.hh index a8463de4d..a877ed394 100644 --- a/util/helper-cairo.hh +++ b/util/helper-cairo.hh @@ -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,