diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index a52284389..4bf08ae24 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -884,6 +884,7 @@ hb_subset_input_unicode_set hb_subset_input_glyph_set hb_subset_input_set hb_subset_input_old_to_new_glyph_mapping +hb_subset_input_pin_all_axes_to_default hb_subset_input_pin_axis_location hb_subset_input_pin_axis_to_default hb_subset_or_fail diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 56ce10fc1..ad5bbf856 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -418,6 +418,46 @@ hb_subset_input_keep_everything (hb_subset_input_t *input) } #ifndef HB_NO_VAR +/** + * hb_subset_input_pin_all_axes_to_default: (skip) + * @input: a #hb_subset_input_t object. + * @face: a #hb_face_t object. + * + * Pin all axes to default locations in the given subset input object. + * + * All axes in a font must be pinned. Additionally, `CFF2` table, if present, + * will be de-subroutinized. + * + * Return value: `true` if success, `false` otherwise + * + * XSince: REPLACEME + **/ +HB_EXTERN hb_bool_t +hb_subset_input_pin_all_axes_to_default (hb_subset_input_t *input, + hb_face_t *face) +{ + unsigned axis_count = hb_ot_var_get_axis_count (face); + if (!axis_count) return false; + + hb_ot_var_axis_info_t *axis_infos = (hb_ot_var_axis_info_t *) hb_calloc (axis_count, sizeof (hb_ot_var_axis_info_t)); + if (unlikely (!axis_infos)) return false; + + (void) hb_ot_var_get_axis_infos (face, 0, &axis_count, axis_infos); + + for (unsigned i = 0; i < axis_count; i++) + { + hb_tag_t axis_tag = axis_infos[i].tag; + float default_val = axis_infos[i].default_value; + if (!input->axes_location.set (axis_tag, Triple (default_val, default_val, default_val))) + { + hb_free (axis_infos); + return false; + } + } + hb_free (axis_infos); + return true; +} + /** * hb_subset_input_pin_axis_to_default: (skip) * @input: a #hb_subset_input_t object. diff --git a/src/hb-subset.h b/src/hb-subset.h index 00b6beae0..73dcae466 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -173,6 +173,10 @@ HB_EXTERN void hb_subset_input_set_flags (hb_subset_input_t *input, unsigned value); +HB_EXTERN hb_bool_t +hb_subset_input_pin_all_axes_to_default (hb_subset_input_t *input, + hb_face_t *face); + HB_EXTERN hb_bool_t hb_subset_input_pin_axis_to_default (hb_subset_input_t *input, hb_face_t *face, diff --git a/util/helper-subset.hh b/util/helper-subset.hh index f0357f2e8..15acf7d28 100644 --- a/util/helper-subset.hh +++ b/util/helper-subset.hh @@ -138,6 +138,26 @@ parse_instancing_spec (const char *arg, return false; } + /* support *=drop */ + if (0 == strcmp (s, "*")) + { + s = strtok(NULL, ", "); + if (0 != strcmp (s, "drop")) + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + "Failed parsing axis position at: '%s'", s); + return false; + } + + if (!hb_subset_input_pin_all_axes_to_default (input, face)) + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + "Failed pinning all axes to default."); + return false; + } + continue; + } + hb_tag_t axis_tag = hb_tag_from_string (s, len); s = strtok(NULL, ", "); diff --git a/util/test-hb-subset-parsing.c b/util/test-hb-subset-parsing.c index eb5c05f8e..b6b923a79 100644 --- a/util/test-hb-subset-parsing.c +++ b/util/test-hb-subset-parsing.c @@ -75,6 +75,17 @@ test_parse_instancing_spec (void) g_assert(check_parsing(face, "wght=200:,xxxx=50", wght, 200, 1000, 1000)); g_assert(check_parsing(face, "wght=200:,xxxx=50", xxxx, 50, 50, 50)); + g_assert(check_parsing(face, "wght=200,*=drop", wght, 1000, 1000, 1000)); + g_assert(check_parsing(face, "wght=200,*=drop", xxxx, 0, 0, 0)); + g_assert(check_parsing(face, "*=drop,wght=200", wght, 200, 200, 200)); + g_assert(check_parsing(face, "*=drop,wght=200", xxxx, 0, 0, 0)); + g_assert(check_parsing(face, "*=drop,wght=200,xxxx=50", wght, 200, 200, 200)); + g_assert(check_parsing(face, "*=drop,wght=200,xxxx=50", xxxx, 50, 50, 50)); + g_assert(check_parsing(face, "xxxx=50,*=drop,wght=200", wght, 200, 200, 200)); + g_assert(check_parsing(face, "xxxx=50,*=drop,wght=200", xxxx, 0, 0, 0)); + g_assert(check_parsing(face, "*=drop", wght, 1000, 1000, 1000)); + g_assert(check_parsing(face, "*=drop", xxxx, 0, 0, 0)); + g_assert(check_parsing(roboto, "wght=300", wght, 300, 300, 300)); g_assert(check_parsing(roboto, "wght=100:200:300", wght, 100, 200, 300)); g_assert(check_parsing(roboto, "wght=:500:", wght, 100, 500, 900));