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

View File

@ -204,22 +204,22 @@ test_get_math_top_accent_attachment (void)
openFont("fonts/MathTestFontEmpty.otf");
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();
openFont("fonts/MathTestFontPartial1.otf");
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();
openFont("fonts/MathTestFontPartial2.otf");
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();
openFont("fonts/MathTestFontFull.otf");
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_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));