[hb-shape/view] Add --named-instance

This commit is contained in:
Behdad Esfahbod 2023-01-15 10:58:15 -07:00
parent 99838770ab
commit d769e8ae7c
2 changed files with 9 additions and 5 deletions

View File

@ -2536,15 +2536,16 @@ hb_font_set_variations (hb_font_t *font,
} }
/* Initialize design coords. */ /* Initialize design coords. */
if (font->instance_index == HB_FONT_NO_VAR_NAMED_INSTANCE) for (unsigned int i = 0; i < coords_length; i++)
for (unsigned int i = 0; i < coords_length; i++) design_coords[i] = axes[i].get_default ();
design_coords[i] = axes[i].get_default (); if (font->instance_index != HB_FONT_NO_VAR_NAMED_INSTANCE)
else
{ {
unsigned count = coords_length; unsigned count = coords_length;
/* This may fail if index is out-of-range;
* That's why we initialize design_coords from fvar above
* unconditionally. */
hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index, hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index,
&count, design_coords); &count, design_coords);
assert (count == coords_length);
} }
for (unsigned int i = 0; i < variations_length; i++) for (unsigned int i = 0; i < variations_length; i++)

View File

@ -71,6 +71,7 @@ struct font_options_t : face_options_t
char *font_funcs = nullptr; char *font_funcs = nullptr;
int ft_load_flags = 2; int ft_load_flags = 2;
unsigned int palette = 0; unsigned int palette = 0;
unsigned int named_instance = 0;
hb_font_t *font = nullptr; hb_font_t *font = nullptr;
}; };
@ -113,6 +114,7 @@ font_options_t::post_parse (GError **error)
hb_font_set_scale (font, scale_x, scale_y); hb_font_set_scale (font, scale_x, scale_y);
#ifndef HB_NO_VAR #ifndef HB_NO_VAR
hb_font_set_var_named_instance (font, named_instance);
hb_font_set_variations (font, variations, num_variations); hb_font_set_variations (font, variations, num_variations);
#endif #endif
@ -395,6 +397,7 @@ font_options_t::add_options (option_parser_t *parser)
GOptionEntry entries2[] = GOptionEntry entries2[] =
{ {
{"list-variations", 0, 0, G_OPTION_ARG_NONE, &this->list_variations, "List available font variations and quit", nullptr}, {"list-variations", 0, 0, G_OPTION_ARG_NONE, &this->list_variations, "List available font variations and quit", nullptr},
{"named-instance", 0, 0, G_OPTION_ARG_INT, &this->named_instance, "Set named-instance index (default: none)", "index"},
{"variations", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_variations, variations_help, "list"}, {"variations", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_variations, variations_help, "list"},
{nullptr} {nullptr}
}; };