[instancer] command line support for partial instancing

-Also updated hb_subset_input_set_axis_range (), so user can define
default value as well
This commit is contained in:
Qunxin Liu committed 2023-08-07 14:37:13 -07:00
1 parent 0065658e96
commit 32cfa37e2e
3 files changed
+81 -23

No files matched your search

+13 -6
View File
@@ -478,16 +478,21 @@ hb_subset_input_pin_axis_location (hb_subset_input_t *input,
* @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
* @axis_def_value: Default value of the axis variation range to set, in case of
* null, it'll be determined automatically
*
* 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.
* New min/default/max values will be clamped if they're not within the fvar axis range.
* If the new default value is null:
* If the fvar axis default value is within the new range, then new default
* value is the same as original default value.
* 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
* Note: currently this API does not support changing axis limits yet.It'd be only
* used internally for setting axis limits in the internal data structures
* Note: input min value can not be bigger than input max value. If the input
* default value is not within the new min/max range, it'll be clamped.
* Note: currently it supports gvar and cvar tables only.
*
* Return value: `true` if success, `false` otherwise
*
@@ -498,7 +503,8 @@ 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)
float axis_max_value,
float *axis_def_value /* IN, maybe NULL */)
{
if (axis_min_value > axis_max_value)
return false;
@@ -509,7 +515,8 @@ hb_subset_input_set_axis_range (hb_subset_input_t *input,
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);
float new_default_val = axis_def_value ? *axis_def_value : axis_info.default_value;
new_default_val = hb_clamp(new_default_val, new_min_val, new_max_val);
return input->axes_location.set (axis_tag, Triple (new_min_val, new_default_val, new_max_val));
}
#endif
+2 -1
View File
@@ -181,7 +181,8 @@ 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);
float axis_max_value,
float *axis_def_value);
HB_EXTERN hb_bool_t
hb_subset_input_override_name_table (hb_subset_input_t *input,
+66 -16
View File
@@ -707,33 +707,83 @@ parse_instance (const char *name,
return false;
}
if (strcmp (s, "drop") == 0)
{
if (!hb_subset_input_pin_axis_to_default (subset_main->input, subset_main->face, axis_tag))
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Cannot pin axis: '%c%c%c%c', not present in fvar", HB_UNTAG (axis_tag));
return false;
}
}
else
char *pp = s;
pp = strpbrk (pp, ":");
if (pp) // partial instancing
{
errno = 0;
char *p;
float axis_value = strtof (s, &p);
if (errno || s == p)
char *pend;
float min_val = strtof (s, &pend);
if (errno || s == pend || pend != pp)
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Failed parsing axis value at: '%s'", s);
return false;
}
if (!hb_subset_input_pin_axis_location (subset_main->input, subset_main->face, axis_tag, axis_value))
pp++;
float max_val = strtof (pp, &pend);
/* we need to specify 2 values or 3 values for partial instancing:
* at least new min and max values, new default is optional */
if (errno || pp == pend || (*pend != ':' && *pend != '\0'))
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Cannot pin axis: '%c%c%c%c', not present in fvar", HB_UNTAG (axis_tag));
"Failed parsing axis value at: '%s'", s);
return false;
}
/* 3 values are specified */
float *def_val_p = nullptr;
float def_val;
if (*pend == ':')
{
def_val = max_val;
def_val_p = &def_val;
pp = pend + 1;
max_val = strtof (pp, &pend);
if (errno || pp == pend || *pend != '\0')
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Failed parsing axis value at: '%s'", s);
return false;
}
}
if (!hb_subset_input_set_axis_range (subset_main->input, subset_main->face, axis_tag, min_val, max_val, def_val_p))
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Error: axis: '%c%c%c%c', not present in fvar or invalid range with min:%.6f max:%.6f",
HB_UNTAG (axis_tag), min_val, max_val);
return false;
}
}
else
{
if (strcmp (s, "drop") == 0)
{
if (!hb_subset_input_pin_axis_to_default (subset_main->input, subset_main->face, axis_tag))
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Cannot pin axis: '%c%c%c%c', not present in fvar", HB_UNTAG (axis_tag));
return false;
}
}
else
{
errno = 0;
char *p;
float axis_value = strtof (s, &p);
if (errno || s == p)
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Failed parsing axis value at: '%s'", s);
return false;
}
if (!hb_subset_input_pin_axis_location (subset_main->input, subset_main->face, axis_tag, axis_value))
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Cannot pin axis: '%c%c%c%c', not present in fvar", HB_UNTAG (axis_tag));
return false;
}
}
}
s = strtok(nullptr, "=");
}