[ot-math] Workaround bad displayOperatorMinHeight in Cambria Math

See https://github.com/harfbuzz/harfbuzz/issues/4653 for details
This commit is contained in:
Khaled Hosny 2025-04-05 14:54:11 +02:00
parent 52a4bea109
commit f57b43c980
2 changed files with 30 additions and 0 deletions

View file

@ -1104,6 +1104,22 @@ struct MATH
mathVariants.sanitize (c, this));
}
// https://github.com/harfbuzz/harfbuzz/issues/4653
HB_INTERNAL bool is_bad_cambria (hb_font_t *font) const
{
switch HB_CODEPOINT_ENCODE3 (font->face->table.MATH.get_blob ()->length,
get_constant (HB_OT_MATH_CONSTANT_DISPLAY_OPERATOR_MIN_HEIGHT, font),
get_constant (HB_OT_MATH_CONSTANT_DELIMITED_SUB_FORMULA_MIN_HEIGHT, font))
{
/* sha1sum:ab4a4fe054d23061f3c039493d6f665cfda2ecf5 cambria.ttc
* sha1sum:086855301bff644f9d8827b88491fcf73a6d4cb9 cambria.ttc
* sha1sum:b1e5a3feaca2ea3dfcf79ccb377de749ecf60343 cambria.ttc */
case HB_CODEPOINT_ENCODE3 (25722, 2500, 3000):
return true;
}
return false;
}
hb_position_t get_constant (hb_ot_math_constant_t constant,
hb_font_t *font) const
{ return (this+mathConstants).get_value (constant, font); }

View file

@ -87,6 +87,20 @@ hb_position_t
hb_ot_math_get_constant (hb_font_t *font,
hb_ot_math_constant_t constant)
{
/* https://github.com/harfbuzz/harfbuzz/issues/4653
* Cambria Math has incorrect value for displayOperatorMinHeight, and
* apparently Microsoft implementation swaps displayOperatorMinHeight and
* delimitedSubFormulaMinHeight, so we do the same if we detect Cambria Math
* with the swapped values. */
if ((constant == HB_OT_MATH_CONSTANT_DISPLAY_OPERATOR_MIN_HEIGHT ||
constant == HB_OT_MATH_CONSTANT_DELIMITED_SUB_FORMULA_MIN_HEIGHT) &&
font->face->table.MATH->is_bad_cambria (font))
{
if (constant == HB_OT_MATH_CONSTANT_DISPLAY_OPERATOR_MIN_HEIGHT)
constant = HB_OT_MATH_CONSTANT_DELIMITED_SUB_FORMULA_MIN_HEIGHT;
else
constant = HB_OT_MATH_CONSTANT_DISPLAY_OPERATOR_MIN_HEIGHT;
}
return font->face->table.MATH->get_constant(constant, font);
}