[instance] update OS/2.usWeightClass and OS/2.usWidthClass

This commit is contained in:
Qunxin Liu 2022-07-27 12:54:33 -07:00
parent ac0e22fa8e
commit 4882c717b5
1 changed files with 35 additions and 0 deletions

View File

@ -166,6 +166,21 @@ struct OS2
}
}
float map_wdth_to_widthclass(float width) const
{
if (width < 50) return 1.0f;
if (width > 200) return 9.0f;
float ratio = (width - 50) / 12.5f;
int a = (int) floorf (ratio);
int b = (int) ceilf (ratio);
float va = 50 + a * 12.5f;
float vb = 50 + b * 12.5f;
return a + 1.0f + (float) (b - a) * (width - va) / (vb - va);
}
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
@ -183,6 +198,26 @@ struct OS2
_update_unicode_ranges (c->plan->unicodes, os2_prime->ulUnicodeRange);
if (c->plan->user_axes_location->has (HB_TAG ('w','g','h','t')) &&
!c->plan->pinned_at_default)
{
float weight_class = c->plan->user_axes_location->get (HB_TAG ('w','g','h','t'));
if (!c->serializer->check_assign (os2_prime->usWeightClass,
roundf (hb_clamp (weight_class, 1.0f, 1000.0f)),
HB_SERIALIZE_ERROR_INT_OVERFLOW))
return_trace (false);
}
if (c->plan->user_axes_location->has (HB_TAG ('w','d','t','h')) &&
!c->plan->pinned_at_default)
{
float width = c->plan->user_axes_location->get (HB_TAG ('w','d','t','h'));
if (!c->serializer->check_assign (os2_prime->usWidthClass,
roundf (map_wdth_to_widthclass (width)),
HB_SERIALIZE_ERROR_INT_OVERFLOW))
return_trace (false);
}
return_trace (true);
}