hb-view: Add a --custom-palette option

This commit is contained in:
Matthias Clasen 2023-01-18 23:45:53 -05:00 committed by Behdad Esfahbod
parent ab37ade7e4
commit c41892a012
2 changed files with 15 additions and 0 deletions

View File

@ -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"},

View File

@ -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,