From 8d622f1114d6a0eca1786b94c7fc1a0bcd87f74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Tue, 27 Sep 2016 13:53:34 +0200 Subject: [PATCH] Add tests for get_mathvariant (#329) --- test/api/test-ot-math.c | 160 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/test/api/test-ot-math.c b/test/api/test-ot-math.c index 99993e063..4d6f67bcd 100644 --- a/test/api/test-ot-math.c +++ b/test/api/test-ot-math.c @@ -515,6 +515,165 @@ test_get_glyph_variants (void) cleanupFreeType(); } +static void +test_get_glyph_assembly (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_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0); + closeFont(); + + openFont("fonts/MathTestFontPartial1.otf"); + g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph)); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0); + closeFont(); + + openFont("fonts/MathTestFontPartial2.otf"); + g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph)); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0); + closeFont(); + + openFont("fonts/MathTestFontPartial3.otf"); + g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph)); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0); + closeFont(); + + openFont("fonts/MathTestFontPartial4.otf"); + g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph)); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0); + closeFont(); + + openFont("fonts/MathTestFontFull.otf"); + + g_assert(hb_font_get_glyph_from_name (hb_font, "arrowright", -1, &glyph)); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, + glyph, + HB_DIRECTION_BTT, + 0, + NULL, + NULL, + NULL), ==, 0); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, + glyph, + HB_DIRECTION_RTL, + 0, + NULL, + NULL, + NULL), ==, 3); + + g_assert(hb_font_get_glyph_from_name (hb_font, "arrowdown", -1, &glyph)); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, + glyph, + HB_DIRECTION_BTT, + 0, + NULL, + NULL, + NULL), ==, 5); + g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, + glyph, + HB_DIRECTION_RTL, + 0, + NULL, + NULL, + NULL), ==, 0); + + g_assert(hb_font_get_glyph_from_name (hb_font, "arrowright", -1, &glyph)); + hb_math_glyph_part_t parts[20]; + unsigned partsSize = sizeof (parts) / sizeof (parts[0]); + unsigned int count; + unsigned int offset = 0; + do { + count = partsSize; + hb_ot_math_get_glyph_assembly (hb_font, + glyph, + HB_DIRECTION_RTL, + offset, + &count, + parts, + NULL); + offset += count; + } while (count == partsSize); + g_assert_cmpint(offset, ==, 3); + g_assert(hb_font_get_glyph_from_name (hb_font, "left", -1, &glyph)); + g_assert_cmpint(parts[0].glyph, ==, glyph); + g_assert_cmpint(parts[0].start_connector_length, ==, 800); + g_assert_cmpint(parts[0].end_connector_length, ==, 384); + g_assert_cmpint(parts[0].full_advance, ==, 2000); + g_assert(!(parts[0].flags & HB_MATH_GLYPH_PART_FLAG_EXTENDER)); + g_assert(hb_font_get_glyph_from_name (hb_font, "horizontal", -1, &glyph)); + g_assert_cmpint(parts[1].glyph, ==, glyph); + g_assert_cmpint(parts[1].start_connector_length, ==, 524); + g_assert_cmpint(parts[1].end_connector_length, ==, 800); + g_assert_cmpint(parts[1].full_advance, ==, 2000); + g_assert(parts[1].flags & HB_MATH_GLYPH_PART_FLAG_EXTENDER); + g_assert(hb_font_get_glyph_from_name (hb_font, "right", -1, &glyph)); + g_assert_cmpint(parts[2].glyph, ==, glyph); + g_assert_cmpint(parts[2].start_connector_length, ==, 316); + g_assert_cmpint(parts[2].end_connector_length, ==, 454); + g_assert_cmpint(parts[2].full_advance, ==, 2000); + g_assert(!(parts[2].flags & HB_MATH_GLYPH_PART_FLAG_EXTENDER)); + + g_assert(hb_font_get_glyph_from_name (hb_font, "arrowdown", -1, &glyph)); + offset = 0; + do { + count = partsSize; + hb_ot_math_get_glyph_assembly (hb_font, + glyph, + HB_DIRECTION_BTT, + offset, + &count, + parts, + NULL); + offset += count; + } while (count == partsSize); + g_assert_cmpint(offset, ==, 5); + g_assert(hb_font_get_glyph_from_name (hb_font, "bottom", -1, &glyph)); + g_assert_cmpint(parts[0].glyph, ==, glyph); + g_assert_cmpint(parts[0].start_connector_length, ==, 365); + g_assert_cmpint(parts[0].end_connector_length, ==, 158); + g_assert_cmpint(parts[0].full_advance, ==, 1000); + g_assert(!(parts[0].flags & HB_MATH_GLYPH_PART_FLAG_EXTENDER)); + g_assert(hb_font_get_glyph_from_name (hb_font, "vertical", -1, &glyph)); + g_assert_cmpint(parts[1].glyph, ==, glyph); + g_assert_cmpint(parts[1].glyph, ==, glyph); + g_assert_cmpint(parts[1].start_connector_length, ==, 227); + g_assert_cmpint(parts[1].end_connector_length, ==, 365); + g_assert_cmpint(parts[1].full_advance, ==, 1000); + g_assert(parts[1].flags & HB_MATH_GLYPH_PART_FLAG_EXTENDER); + g_assert(hb_font_get_glyph_from_name (hb_font, "center", -1, &glyph)); + g_assert_cmpint(parts[2].glyph, ==, glyph); + g_assert_cmpint(parts[2].start_connector_length, ==, 54); + g_assert_cmpint(parts[2].end_connector_length, ==, 158); + g_assert_cmpint(parts[2].full_advance, ==, 1000); + g_assert(!(parts[2].flags & HB_MATH_GLYPH_PART_FLAG_EXTENDER)); + g_assert(hb_font_get_glyph_from_name (hb_font, "vertical", -1, &glyph)); + g_assert_cmpint(parts[3].glyph, ==, glyph); + g_assert_cmpint(parts[3].glyph, ==, glyph); + g_assert_cmpint(parts[3].glyph, ==, glyph); + g_assert_cmpint(parts[3].start_connector_length, ==, 400); + g_assert_cmpint(parts[3].end_connector_length, ==, 296); + g_assert_cmpint(parts[3].full_advance, ==, 1000); + g_assert(parts[1].flags & HB_MATH_GLYPH_PART_FLAG_EXTENDER); + g_assert(hb_font_get_glyph_from_name (hb_font, "top", -1, &glyph)); + g_assert_cmpint(parts[4].glyph, ==, glyph); + g_assert_cmpint(parts[4].start_connector_length, ==, 123); + g_assert_cmpint(parts[4].end_connector_length, ==, 192); + g_assert_cmpint(parts[4].full_advance, ==, 1000); + g_assert(!(parts[4].flags & HB_MATH_GLYPH_PART_FLAG_EXTENDER)); + + closeFont(); + + cleanupFreeType(); +} + int main (int argc, char **argv) { @@ -529,6 +688,7 @@ main (int argc, char **argv) hb_test_add (test_get_glyph_assembly_italics_correction); hb_test_add (test_get_min_connector_overlap); hb_test_add (test_get_glyph_variants); + hb_test_add (test_get_glyph_assembly); return hb_test_run(); }