From 032d56ff7d221c09ee34a7e0b66e9c1a85bea348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Jul 2024 12:43:28 +0200 Subject: [PATCH] MagnumFont: test with a UTF-8 char in the middle. So it's clear it doesn't corrupt the state or tries to render the next char from a weird position. Same for the shaper reuse. --- .../MagnumFont/Test/MagnumFontTest.cpp | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/MagnumPlugins/MagnumFont/Test/MagnumFontTest.cpp b/src/MagnumPlugins/MagnumFont/Test/MagnumFontTest.cpp index c483c06fe..e4842a26f 100644 --- a/src/MagnumPlugins/MagnumFont/Test/MagnumFontTest.cpp +++ b/src/MagnumPlugins/MagnumFont/Test/MagnumFontTest.cpp @@ -71,10 +71,10 @@ const struct { UnsignedInt eGlyphId; UnsignedInt begin, end; } ShapeData[]{ - {"", "Wave", 1, 0, ~UnsignedInt{}}, - {"substring", "haWavefefe", 1, 2, 6}, - {"UTF-8", "Wavě", 3, 0, ~UnsignedInt{}}, - {"UTF-8 substring", "haWavěfefe", 3, 2, 7}, + {"", "Weave", 1, 0, ~UnsignedInt{}}, + {"substring", "haWeavesfefe", 1, 2, 7}, + {"UTF-8", "Wěave", 3, 0, ~UnsignedInt{}}, + {"UTF-8 substring", "haWěavefefe", 3, 2, 8}, }; MagnumFontTest::MagnumFontTest() { @@ -147,28 +147,30 @@ void MagnumFontTest::shape() { Containers::Pointer shaper = font->createShaper(); - CORRADE_COMPARE(shaper->shape(data.string, data.begin, data.end), 4); + CORRADE_COMPARE(shaper->shape(data.string, data.begin, data.end), 5); - UnsignedInt ids[4]; - Vector2 offsets[4]; - Vector2 advances[4]; + UnsignedInt ids[5]; + Vector2 offsets[5]; + Vector2 advances[5]; shaper->glyphIdsInto(ids); shaper->glyphOffsetsAdvancesInto(offsets, advances); CORRADE_COMPARE_AS(Containers::arrayView(ids), Containers::arrayView({ 2u, /* 'W' */ + data.eGlyphId, /* 'e' or 'ě' */ 0u, /* 'a' (not found) */ 0u, /* 'v' (not found) */ - data.eGlyphId /* 'e' or 'ě' */ + 1u, /* 'e' */ }), TestSuite::Compare::Container); /* There are no glyph-specific offsets here */ CORRADE_COMPARE_AS(Containers::arrayView(offsets), Containers::arrayView({ - {}, {}, {}, {} + {}, {}, {}, {}, {} }), TestSuite::Compare::Container); CORRADE_COMPARE_AS(Containers::arrayView(advances), Containers::arrayView({ {23.0f, 0.0f}, + {12.f, 0.0f}, {8.0f, 0.0f}, {8.0f, 0.0f}, - {12.f, 0.0f} + {12.f, 0.0f}, }), TestSuite::Compare::Container); } @@ -214,23 +216,25 @@ void MagnumFontTest::shaperReuse() { /* Long text, same as in shape(), should enlarge the array for it */ } { - CORRADE_COMPARE(shaper->shape("Wave"), 4); - UnsignedInt ids[4]; - Vector2 offsets[4]; - Vector2 advances[4]; + CORRADE_COMPARE(shaper->shape("Wěave"), 5); + UnsignedInt ids[5]; + Vector2 offsets[5]; + Vector2 advances[5]; shaper->glyphIdsInto(ids); shaper->glyphOffsetsAdvancesInto(offsets, advances); CORRADE_COMPARE_AS(Containers::arrayView(ids), Containers::arrayView({ 2u, /* 'W' */ + 3u, /* 'ě' */ 0u, /* 'a' (not found) */ 0u, /* 'v' (not found) */ 1u /* 'e' */ }), TestSuite::Compare::Container); CORRADE_COMPARE_AS(Containers::arrayView(offsets), Containers::arrayView({ - {}, {}, {}, {} + {}, {}, {}, {}, {} }), TestSuite::Compare::Container); CORRADE_COMPARE_AS(Containers::arrayView(advances), Containers::arrayView({ {23.0f, 0.0f}, + {12.f, 0.0f}, {8.0f, 0.0f}, {8.0f, 0.0f}, {12.f, 0.0f} @@ -238,20 +242,24 @@ void MagnumFontTest::shaperReuse() { /* Short text again, should not leave the extra glyphs there */ } { - CORRADE_COMPARE(shaper->shape("a"), 1); - UnsignedInt ids[1]; - Vector2 offsets[1]; - Vector2 advances[1]; + CORRADE_COMPARE(shaper->shape("ave"), 3); + UnsignedInt ids[3]; + Vector2 offsets[3]; + Vector2 advances[3]; shaper->glyphIdsInto(ids); shaper->glyphOffsetsAdvancesInto(offsets, advances); CORRADE_COMPARE_AS(Containers::arrayView(ids), Containers::arrayView({ - 0u, + 0u, /* 'a' (not found) */ + 0u, /* 'v' (not found) */ + 1u /* 'e' */ }), TestSuite::Compare::Container); CORRADE_COMPARE_AS(Containers::arrayView(offsets), Containers::arrayView({ - {}, + {}, {}, {} }), TestSuite::Compare::Container); CORRADE_COMPARE_AS(Containers::arrayView(advances), Containers::arrayView({ - {8.0f, 0.0f} + {8.0f, 0.0f}, + {8.0f, 0.0f}, + {12.f, 0.0f} }), TestSuite::Compare::Container); } }