From c41892a01229404d4d0c31b8056fd7b72ac3a58a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 18 Jan 2023 23:45:53 -0500 Subject: [PATCH] hb-view: Add a --custom-palette option --- util/font-options.hh | 3 +++ util/helper-cairo.hh | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/util/font-options.hh b/util/font-options.hh index b1a0169c6..5f99a37ef 100644 --- a/util/font-options.hh +++ b/util/font-options.hh @@ -49,6 +49,7 @@ struct font_options_t : face_options_t #endif g_free (font_funcs); hb_font_destroy (font); + free (custom_palette); } void add_options (option_parser_t *parser); @@ -70,6 +71,7 @@ struct font_options_t : face_options_t char *font_funcs = nullptr; int ft_load_flags = 2; unsigned int palette = 0; + char *custom_palette = nullptr; unsigned int named_instance = HB_FONT_NO_VAR_NAMED_INSTANCE; hb_font_t *font = nullptr; @@ -290,6 +292,7 @@ font_options_t::add_options (option_parser_t *parser) {"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"}, + {"custom-palette", 0, 0, G_OPTION_ARG_STRING, &this->custom_palette, "Custom palette", "palette"}, {"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.hh b/util/helper-cairo.hh index c0ce5955f..114d79e86 100644 --- a/util/helper-cairo.hh +++ b/util/helper-cairo.hh @@ -125,6 +125,18 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts) #ifdef CAIRO_COLOR_PALETTE_DEFAULT cairo_font_options_set_color_palette (font_options, font_opts->palette); #endif +#ifdef CAIRO_COLOR_PALETTE_CUSTOM + if (font_opts->custom_palette) + { + char **entries = g_strsplit (font_opts->custom_palette, ",", -1); + for (unsigned int i = 0; entries[i]; i++) + { + unsigned int idx, fr, fg, fb, fa; + if (sscanf (entries[i], "%u:%2x%2x%2x%2x", &idx, &fr, &fg, &fb, &fa) == 5) + cairo_font_options_set_custom_palette_color (font_options, idx, fr / 255., fg / 255., fb / 255., fa / 255.); + } + } +#endif cairo_scaled_font_t *scaled_font = cairo_scaled_font_create (cairo_face, &font_matrix,