Merge pull request #3068 from harfbuzz/hoi

[variations] Support multiple axes with same tag, aka HOI
This commit is contained in:
Behdad Esfahbod 2021-07-26 11:31:54 -07:00 committed by GitHub
commit aeec278453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 44 deletions

View File

@ -2052,7 +2052,9 @@ hb_font_set_variations (hb_font_t *font,
return;
}
unsigned int coords_length = hb_ot_var_get_axis_count (font->face);
const OT::fvar &fvar = *font->face->table.fvar;
auto axes = fvar.get_axes ();
const unsigned coords_length = axes.length;
int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
@ -2064,17 +2066,16 @@ hb_font_set_variations (hb_font_t *font,
return;
}
const OT::fvar &fvar = *font->face->table.fvar;
for (unsigned int i = 0; i < variations_length; i++)
{
unsigned axis_index;
if (fvar.find_axis_index (variations[i].tag, &axis_index) &&
axis_index < coords_length)
{
float v = variations[i].value;
design_coords[axis_index] = v;
normalized[axis_index] = fvar.normalize_axis_value (axis_index, v);
}
const auto tag = variations[i].tag;
const auto v = variations[i].value;
for (unsigned axis_index = 0; axis_index < coords_length; axis_index++)
if (axes[axis_index].axisTag == tag)
{
design_coords[axis_index] = v;
normalized[axis_index] = fvar.normalize_axis_value (axis_index, v);
}
}
font->face->table.avar->map_coords (normalized, coords_length);

View File

@ -213,38 +213,15 @@ struct fvar
if (!axis_index) axis_index = &i;
*axis_index = HB_OT_VAR_NO_AXIS_INDEX;
auto axes = get_axes ();
return find_axis_index (tag, axis_index) && (axes[*axis_index].get_axis_deprecated (info), true);
return axes.lfind (tag, axis_index) && (axes[*axis_index].get_axis_deprecated (info), true);
}
#endif
bool
find_axis_index (hb_tag_t tag,
unsigned *axis_index_start,
unsigned *axis_index_end = nullptr) const
{
auto axes = get_axes ();
/* TODO bfind() for larger array? Should then look back to find first entry for tag. */
if (!axes.lfind (tag, axis_index_start))
return false;
if (axis_index_end)
{
unsigned end = *axis_index_start + 1;
unsigned count = axes.length;
while (end < count && axes[end].axisTag == tag)
end++;
*axis_index_end = end;
}
return true;
}
bool
find_axis_info (hb_tag_t tag, hb_ot_var_axis_info_t *info) const
{
unsigned i;
auto axes = get_axes ();
return find_axis_index (tag, &i) && (axes[i].get_axis_info (i, info), true);
return axes.lfind (tag, &i) && (axes[i].get_axis_info (i, info), true);
}
int normalize_axis_value (unsigned int axis_index, float v) const
@ -313,7 +290,7 @@ struct fvar
;
}
protected:
public:
hb_array_t<const AxisRecord> get_axes () const
{ return hb_array (&(this+firstAxis), axisCount); }

View File

@ -58,9 +58,8 @@ TESTS = \
tests/use-marchen.tests \
tests/use-syllable.tests \
tests/use.tests \
tests/variations-rounding.tests \
tests/variations.tests \
tests/variations-rvrn.tests \
tests/variations-space.tests \
tests/vertical.tests \
tests/zero-width-marks.tests \
$(NULL)

View File

@ -58,9 +58,8 @@ in_house_tests = [
'use-marchen.tests',
'use-syllable.tests',
'use.tests',
'variations-rounding.tests',
'variations.tests',
'variations-rvrn.tests',
'variations-space.tests',
'vertical.tests',
'zero-width-marks.tests',
]

View File

@ -1,2 +0,0 @@
../fonts/HBTest-VF.ttf:--variations=TEST=491:U+0041:[A=0+496]
../fonts/HBTest-VF.ttf:--variations=TEST=509:U+0041:[A=0+505]

View File

@ -1,2 +0,0 @@
../fonts/ab40c89624a6104e5d0a2308e448a989302f515b.ttf:--variations=wdth=60:U+0020:[space=0+266]
../fonts/ab40c89624a6104e5d0a2308e448a989302f515b.ttf:--variations=wdth=402:U+0020:[space=0+639]

View File

@ -0,0 +1,5 @@
../fonts/HBTest-VF.ttf:--variations=TEST=491:U+0041:[A=0+496]
../fonts/HBTest-VF.ttf:--variations=TEST=509:U+0041:[A=0+505]
../fonts/ab40c89624a6104e5d0a2308e448a989302f515b.ttf:--variations=wdth=60:U+0020:[space=0+266]
../fonts/ab40c89624a6104e5d0a2308e448a989302f515b.ttf:--variations=wdth=402:U+0020:[space=0+639]
../fonts/e8691822f6a705e3e9fb48a0405c645b1a036590.ttf:--variations=0001=500:U+002E,U+0065:[period=0+681|e=1+650]