From 4882c717b5bc6f2cfe45c5c84bb5ddc060f8ee2e Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Wed, 27 Jul 2022 12:54:33 -0700 Subject: [PATCH] [instance] update OS/2.usWeightClass and OS/2.usWidthClass --- src/hb-ot-os2-table.hh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 3473afef5..780d9627c 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -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); }