[MATH] Clean up get_top_accent_attachment()

Note, the function now returns "half of horizontal advance width"
if top accent attachment for glyph is not explicitly defined.
This is what the spec requires.  Updated tests.
This commit is contained in:
Behdad Esfahbod 2016-09-26 12:18:32 +01:00
parent 8bcf517fe5
commit 17ff30e9af
3 changed files with 16 additions and 30 deletions

View File

@ -178,7 +178,6 @@ struct MathItalicsCorrectionInfo
{ {
unsigned int index = (this+coverage).get_coverage (glyph); unsigned int index = (this+coverage).get_coverage (glyph);
return italicsCorrection[index].get_x_value (font, this); return italicsCorrection[index].get_x_value (font, this);
return true;
} }
protected: protected:
@ -205,14 +204,13 @@ struct MathTopAccentAttachment
topAccentAttachment.sanitize (c, this)); topAccentAttachment.sanitize (c, this));
} }
inline bool get_value (hb_font_t *font, hb_codepoint_t glyph, inline hb_position_t get_value (hb_codepoint_t glyph,
hb_position_t &value) const hb_font_t *font) const
{ {
unsigned int index = (this+topAccentCoverage).get_coverage (glyph); unsigned int index = (this+topAccentCoverage).get_coverage (glyph);
if (likely (index == NOT_COVERED)) return false; if (index == NOT_COVERED)
if (unlikely (index >= topAccentAttachment.len)) return false; return font->get_glyph_h_advance (glyph) / 2;
value = topAccentAttachment[index].get_x_value(font, this); return topAccentAttachment[index].get_x_value(font, this);
return true;
} }
protected: protected:
@ -366,22 +364,15 @@ struct MathGlyphInfo
} }
inline hb_position_t inline hb_position_t
get_italics_correction (hb_codepoint_t glyph, get_italics_correction (hb_codepoint_t glyph, hb_font_t *font) const
hb_font_t *font) const { return (this+mathItalicsCorrectionInfo).get_value (glyph, font); }
{
return (this+mathItalicsCorrectionInfo).get_value (glyph, font);
}
inline const MathTopAccentAttachment& inline hb_position_t
get_math_top_accent_attachment (void) const { get_top_accent_attachment (hb_codepoint_t glyph, hb_font_t *font) const
return this+mathTopAccentAttachment; { return (this+mathTopAccentAttachment).get_value (glyph, font); }
}
inline bool is_extended_shape (hb_codepoint_t glyph) const inline bool is_extended_shape (hb_codepoint_t glyph) const
{ { return (this+extendedShapeCoverage).get_coverage (glyph) != NOT_COVERED; }
unsigned int index = (this+extendedShapeCoverage).get_coverage (glyph);
return index != NOT_COVERED;
}
inline const MathKernInfo &get_math_kern_info (void) const { inline const MathKernInfo &get_math_kern_info (void) const {
return this+mathKernInfo; return this+mathKernInfo;

View File

@ -1302,12 +1302,7 @@ hb_ot_layout_get_math_top_accent_attachment (hb_font_t *font,
hb_codepoint_t glyph) hb_codepoint_t glyph)
{ {
const OT::MATH &math = _get_math (font->face); const OT::MATH &math = _get_math (font->face);
const OT::MathGlyphInfo &glyphInfo = math.get_math_glyph_info(); return math.get_math_glyph_info().get_top_accent_attachment (glyph, font);
hb_position_t value;
if (glyphInfo.get_math_top_accent_attachment().get_value(font, glyph, value))
return value;
else
return 0; // XXX font->get_glyph_h_advance (glyph) / 2;
} }
/** /**

View File

@ -204,22 +204,22 @@ test_get_math_top_accent_attachment (void)
openFont("fonts/MathTestFontEmpty.otf"); openFont("fonts/MathTestFontEmpty.otf");
g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph)); g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 0); // MathGlyphInfo not available g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 500); // MathGlyphInfo not available
closeFont(); closeFont();
openFont("fonts/MathTestFontPartial1.otf"); openFont("fonts/MathTestFontPartial1.otf");
g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph)); g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 0); // MathGlyphInfo empty g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 500); // MathGlyphInfo empty
closeFont(); closeFont();
openFont("fonts/MathTestFontPartial2.otf"); openFont("fonts/MathTestFontPartial2.otf");
g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph)); g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 0); // MathTopAccentAttachment empty g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 500); // MathTopAccentAttachment empty
closeFont(); closeFont();
openFont("fonts/MathTestFontFull.otf"); openFont("fonts/MathTestFontFull.otf");
g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph)); g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 0); // Glyph without top accent attachment. g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 500); // Glyph without top accent attachment.
g_assert(hb_font_get_glyph_from_name (hb_font, "D", -1, &glyph)); g_assert(hb_font_get_glyph_from_name (hb_font, "D", -1, &glyph));
g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 374); g_assert_cmpint(hb_ot_layout_get_math_top_accent_attachment (hb_font, glyph), ==, 374);
g_assert(hb_font_get_glyph_from_name (hb_font, "E", -1, &glyph)); g_assert(hb_font_get_glyph_from_name (hb_font, "E", -1, &glyph));