From f8ddb9998b1b6390b415bcfa549156baeef48b65 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Tue, 30 Aug 2022 09:08:09 -0700 Subject: [PATCH] [instance] Fix os/2 table width to widthclass mapping --- src/hb-ot-os2-table.hh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 780d9627c..c6e8fad6f 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -175,10 +175,36 @@ struct OS2 int a = (int) floorf (ratio); int b = (int) ceilf (ratio); + /* follow this maping: + * https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswidthclass + */ + if (b <= 6) // 50-125 + { + if (a == b) return a + 1.0f; + } + else if (b == 7) // no mapping for 137.5 + { + a = 6; + b = 8; + } + else if (b == 8) + { + if (a == b) return 8.0f; // 150 + a = 6; + } + else + { + if (a == b && a == 12) return 9.0f; //200 + b = 12; + a = 8; + } + float va = 50 + a * 12.5f; float vb = 50 + b * 12.5f; - return a + 1.0f + (float) (b - a) * (width - va) / (vb - va); + float ret = a + (width - va) / (vb - va); + if (a <= 6) ret += 1.0f; + return ret; } bool subset (hb_subset_context_t *c) const