mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 07:21:06 +01:00
[instancer] support *=drop, which would pin all axis to default location
This commit is contained in:
1 parent
06749fa481
commit
d6431dc7e6
5 files changed
+76
No files matched your search
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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, ", ");
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user