[instancer] Add hb_subset_input_set_axis_range() API

This commit is contained in:
Qunxin Liu 2023-04-20 14:02:20 -07:00 committed by Garret Rieger
parent 5d543d6422
commit 0799afe2b6
2 changed files with 47 additions and 0 deletions

View file

@ -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
/**

View file

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