[hb-view] Simplify palette format

This commit is contained in:
Behdad Esfahbod 2023-01-18 23:28:25 -07:00
parent 52b78d526b
commit 253b4cecae
2 changed files with 4 additions and 4 deletions

View File

@ -292,7 +292,7 @@ font_options_t::add_options (option_parser_t *parser)
{"font-slant", 0, 0, {"font-slant", 0, 0,
G_OPTION_ARG_DOUBLE, &this->slant, "Set synthetic slant (default: 0)", "slant ratio; eg. 0.2"}, 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-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"}, {"custom-palette", 0, 0, G_OPTION_ARG_STRING, &this->custom_palette, "Custom palette", "comma-separated colors"},
{"font-funcs", 0, 0, G_OPTION_ARG_STRING, &this->font_funcs, text, "impl"}, {"font-funcs", 0, 0, G_OPTION_ARG_STRING, &this->font_funcs, text, "impl"},
{"sub-font", 0, G_OPTION_FLAG_HIDDEN, {"sub-font", 0, G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_NONE, &this->sub_font, "Create a sub-font (default: false)", "boolean"}, G_OPTION_ARG_NONE, &this->sub_font, "Create a sub-font (default: false)", "boolean"},

View File

@ -131,9 +131,9 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts)
char **entries = g_strsplit (font_opts->custom_palette, ",", -1); char **entries = g_strsplit (font_opts->custom_palette, ",", -1);
for (unsigned int i = 0; entries[i]; i++) for (unsigned int i = 0; entries[i]; i++)
{ {
unsigned int idx, fr, fg, fb, fa; unsigned int fr, fg, fb, fa;
if (sscanf (entries[i], "%u:%2x%2x%2x%2x", &idx, &fr, &fg, &fb, &fa) == 5) if (sscanf (entries[i], "%2x%2x%2x%2x", &fr, &fg, &fb, &fa) == 4)
cairo_font_options_set_custom_palette_color (font_options, idx, fr / 255., fg / 255., fb / 255., fa / 255.); cairo_font_options_set_custom_palette_color (font_options, i, fr / 255., fg / 255., fb / 255., fa / 255.);
} }
g_strfreev (entries); g_strfreev (entries);
} }