From 0799afe2b6b9c1e06505a7e6a604cfb597b5c9ef Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Thu, 20 Apr 2023 14:02:20 -0700 Subject: [PATCH] [instancer] Add hb_subset_input_set_axis_range() API --- src/hb-subset-input.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/hb-subset.h | 7 +++++++ 2 files changed, 47 insertions(+) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 465af5081..16ce657a0 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -470,6 +470,46 @@ hb_subset_input_pin_axis_location (hb_subset_input_t *input, float val = hb_clamp(axis_value, axis_info.min_value, axis_info.max_value); return input->axes_location.set (axis_tag, val); } + +/** + * hb_subset_input_set_axis_range: (skip) + * @input: a #hb_subset_input_t object. + * @face: a #hb_face_t object. + * @axis_tag: Tag of the axis + * @axis_min_value: Minimum value of the axis variation range to set + * @axis_max_value: Maximum value of the axis variation range to set + * + * Restricting the range of variation on an axis in the given subset input object. + * New min/max values will be clamped if they're not within the fvar axis range. + * If the fvar axis default value is not within the new range, the new default + * value will be changed to the new min or max value, whichever is closer to the fvar + * axis default. + * + * Note: input min value can not be bigger than input max value + * + * Return value: `true` if success, `false` otherwise + * + * Since: REPLACEME + **/ +HB_EXTERN hb_bool_t +hb_subset_input_set_axis_range (hb_subset_input_t *input, + hb_face_t *face, + hb_tag_t axis_tag, + float axis_min_value, + float axis_max_value) +{ + if (axis_min_value > axis_max_value) + return false; + + hb_ot_var_axis_info_t axis_info; + if (!hb_ot_var_find_axis_info (face, axis_tag, &axis_info)) + return false; + + float new_min_val = hb_clamp(axis_min_value, axis_info.min_value, axis_info.max_value); + float new_max_val = hb_clamp(axis_max_value, axis_info.min_value, axis_info.max_value); + float new_default_val = hb_clamp(axis_info.default_value, new_min_val, new_max_val); + return input->axes_location.set (axis_tag, new_default_val); +} #endif /** diff --git a/src/hb-subset.h b/src/hb-subset.h index 6368ff93f..e2275631f 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -175,6 +175,13 @@ hb_subset_input_pin_axis_location (hb_subset_input_t *input, hb_tag_t axis_tag, float axis_value); +HB_EXTERN hb_bool_t +hb_subset_input_set_axis_range (hb_subset_input_t *input, + hb_face_t *face, + hb_tag_t axis_tag, + float axis_min_value, + float axis_max_value); + #ifdef HB_EXPERIMENTAL_API HB_EXTERN hb_bool_t hb_subset_input_override_name_table (hb_subset_input_t *input,