From 8bcf517fe59608d2247a8974445b3ff0f4b4b4ac Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 26 Sep 2016 12:12:41 +0100 Subject: [PATCH] [MATH] Clean up get_italics_correction() --- src/hb-ot-layout-math-table.hh | 16 ++++++++-------- src/hb-ot-layout.cc | 17 ++++++----------- src/hb-ot-layout.h | 4 ++-- test/api/test-ot-layout-math.c | 18 +++++++++--------- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/hb-ot-layout-math-table.hh b/src/hb-ot-layout-math-table.hh index 53038e3..3899b16 100644 --- a/src/hb-ot-layout-math-table.hh +++ b/src/hb-ot-layout-math-table.hh @@ -173,13 +173,11 @@ struct MathItalicsCorrectionInfo italicsCorrection.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+coverage).get_coverage (glyph); - if (likely (index == NOT_COVERED)) return false; - if (unlikely (index >= italicsCorrection.len)) return false; - value = italicsCorrection[index].get_x_value(font, this); + return italicsCorrection[index].get_x_value (font, this); return true; } @@ -367,9 +365,11 @@ struct MathGlyphInfo mathKernInfo.sanitize(c, this)); } - inline const MathItalicsCorrectionInfo& - get_math_italics_correction_info (void) const { - return this+mathItalicsCorrectionInfo; + inline hb_position_t + get_italics_correction (hb_codepoint_t glyph, + hb_font_t *font) const + { + return (this+mathItalicsCorrectionInfo).get_value (glyph, font); } inline const MathTopAccentAttachment& diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 6fa61a4..5f171ca 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1270,26 +1270,21 @@ hb_ot_layout_get_math_constant (hb_font_t *font, } /** - * hb_ot_layout_get_math_italic_correction: + * hb_ot_layout_get_math_italics_correction: * * @font: #hb_font_t from which to retrieve the value * @glyph: glyph index from which to retrieve the value * - * Return value: the italic correction of the glyph or 0 + * Return value: the italics correction of the glyph or 0 * * Since: 1.4 **/ HB_EXTERN hb_position_t -hb_ot_layout_get_math_italic_correction (hb_font_t *font, - hb_codepoint_t glyph) +hb_ot_layout_get_math_italics_correction (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_italics_correction_info().get_value(font, glyph, value)) - return value; - else - return 0; + return math.get_math_glyph_info().get_italics_correction (glyph, font); } /** @@ -1330,7 +1325,7 @@ hb_ot_layout_is_math_extended_shape (hb_face_t *face, hb_codepoint_t glyph) { const OT::MATH &math = _get_math (face); - return math.get_math_glyph_info().is_extended_shape(glyph); + return math.get_math_glyph_info().is_extended_shape (glyph); } /** diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index f9ed2d8..9c1c57b 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -311,8 +311,8 @@ hb_ot_layout_get_math_constant (hb_font_t *font, hb_ot_math_constant_t constant); HB_EXTERN hb_position_t -hb_ot_layout_get_math_italic_correction (hb_font_t *font, - hb_codepoint_t glyph); +hb_ot_layout_get_math_italics_correction (hb_font_t *font, + hb_codepoint_t glyph); HB_EXTERN hb_position_t hb_ot_layout_get_math_top_accent_attachment (hb_font_t *font, diff --git a/test/api/test-ot-layout-math.c b/test/api/test-ot-layout-math.c index 5ba583f..a6f4453 100644 --- a/test/api/test-ot-layout-math.c +++ b/test/api/test-ot-layout-math.c @@ -161,35 +161,35 @@ test_get_math_constant (void) } static void -test_get_math_italic_correction (void) +test_get_math_italics_correction (void) { hb_codepoint_t glyph; initFreeType(); 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_italic_correction (hb_font, glyph), ==, 0); // MathGlyphInfo not available + g_assert_cmpint(hb_ot_layout_get_math_italics_correction (hb_font, glyph), ==, 0); // 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_italic_correction (hb_font, glyph), ==, 0); // MathGlyphInfo empty + g_assert_cmpint(hb_ot_layout_get_math_italics_correction (hb_font, glyph), ==, 0); // 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_italic_correction (hb_font, glyph), ==, 0); // MathItalicsCorrectionInfo empty + g_assert_cmpint(hb_ot_layout_get_math_italics_correction (hb_font, glyph), ==, 0); // MathItalicsCorrectionInfo 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_italic_correction (hb_font, glyph), ==, 0); // Glyph without italic correction. + g_assert_cmpint(hb_ot_layout_get_math_italics_correction (hb_font, glyph), ==, 0); // Glyph without italic correction. g_assert(hb_font_get_glyph_from_name (hb_font, "A", -1, &glyph)); - g_assert_cmpint(hb_ot_layout_get_math_italic_correction (hb_font, glyph), ==, 197); + g_assert_cmpint(hb_ot_layout_get_math_italics_correction (hb_font, glyph), ==, 197); g_assert(hb_font_get_glyph_from_name (hb_font, "B", -1, &glyph)); - g_assert_cmpint(hb_ot_layout_get_math_italic_correction (hb_font, glyph), ==, 150); + g_assert_cmpint(hb_ot_layout_get_math_italics_correction (hb_font, glyph), ==, 150); g_assert(hb_font_get_glyph_from_name (hb_font, "C", -1, &glyph)); - g_assert_cmpint(hb_ot_layout_get_math_italic_correction (hb_font, glyph), ==, 452); + g_assert_cmpint(hb_ot_layout_get_math_italics_correction (hb_font, glyph), ==, 452); closeFont(); cleanupFreeType(); @@ -318,7 +318,7 @@ main (int argc, char **argv) hb_test_add (test_has_math_data); hb_test_add (test_get_math_constant); - hb_test_add (test_get_math_italic_correction); + hb_test_add (test_get_math_italics_correction); hb_test_add (test_get_math_top_accent_attachment); hb_test_add (test_is_math_extended_shape); hb_test_add (test_get_math_kerning); -- 2.7.4