From 749044f1b084b7172bd0ac93b0a450599f246f56 Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Wed, 22 May 2019 12:02:47 +0300 Subject: [core] Add unit test for zero width space line breaking --- test/test-files.json | 1 + test/text/shaping.test.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/text/shaping.test.cpp diff --git a/test/test-files.json b/test/test-files.json index 034bf29b90..6ed78d4e61 100644 --- a/test/test-files.json +++ b/test/test-files.json @@ -70,6 +70,7 @@ "test/text/language_tag.test.cpp", "test/text/local_glyph_rasterizer.test.cpp", "test/text/quads.test.cpp", + "test/text/shaping.test.cpp", "test/text/tagged_string.test.cpp", "test/tile/custom_geometry_tile.test.cpp", "test/tile/geojson_tile.test.cpp", diff --git a/test/text/shaping.test.cpp b/test/text/shaping.test.cpp new file mode 100644 index 0000000000..547c85e5ba --- /dev/null +++ b/test/text/shaping.test.cpp @@ -0,0 +1,95 @@ + +#include + +#include +#include +#include +#include + +using namespace mbgl; +using namespace util; + +TEST(Shaping, ZWSP) { + Glyph glyph; + glyph.id = u'中'; + glyph.metrics.width = 18; + glyph.metrics.height = 18; + glyph.metrics.left = 2; + glyph.metrics.top = -8; + glyph.metrics.advance = 21; + + BiDi bidi; + auto immutableGlyph = Immutable(makeMutable(std::move(glyph))); + const std::vector fontStack{{"font-stack"}}; + const SectionOptions sectionOptions(1.0f, fontStack); + GlyphMap glyphs = { + { FontStackHasher()(fontStack), {{u'中', std::move(immutableGlyph)}} } + }; + + const auto testGetShaping = [&] (const TaggedString& string, unsigned maxWidthInChars) { + return getShaping(string, + maxWidthInChars * ONE_EM, + ONE_EM, // lineHeight + style::SymbolAnchorType::Center, + style::TextJustifyType::Center, + 0, // spacing + {0.0f, 0.0f}, // translate + WritingModeType::Horizontal, + bidi, + glyphs); + }; + + // 3 lines + // 中中中中中中 + // 中中中中中中 + // 中中 + { + TaggedString string(u"中中\u200b中中\u200b中中\u200b中中中中中中\u200b中中", sectionOptions); + auto shaping = testGetShaping(string, 5); + ASSERT_EQ(shaping.lineCount, 3); + ASSERT_EQ(shaping.top, -36); + ASSERT_EQ(shaping.bottom, 36); + ASSERT_EQ(shaping.left, -63); + ASSERT_EQ(shaping.right, 63); + ASSERT_EQ(shaping.writingMode, WritingModeType::Horizontal); + } + + // 2 lines + // 中中 + // 中 + { + TaggedString string(u"中中\u200b中", sectionOptions); + auto shaping = testGetShaping(string, 1); + ASSERT_EQ(shaping.lineCount, 2); + ASSERT_EQ(shaping.top, -24); + ASSERT_EQ(shaping.bottom, 24); + ASSERT_EQ(shaping.left, -21); + ASSERT_EQ(shaping.right, 21); + ASSERT_EQ(shaping.writingMode, WritingModeType::Horizontal); + } + + // 1 line + // 中中 + { + TaggedString string(u"中中\u200b", sectionOptions); + auto shaping = testGetShaping(string, 2); + ASSERT_EQ(shaping.lineCount, 1); + ASSERT_EQ(shaping.top, -12); + ASSERT_EQ(shaping.bottom, 12); + ASSERT_EQ(shaping.left, -21); + ASSERT_EQ(shaping.right, 21); + ASSERT_EQ(shaping.writingMode, WritingModeType::Horizontal); + } + + // 5 'new' lines. + { + TaggedString string(u"\u200b\u200b\u200b\u200b\u200b", sectionOptions); + auto shaping = testGetShaping(string, 1); + ASSERT_EQ(shaping.lineCount, 5); + ASSERT_EQ(shaping.top, -60); + ASSERT_EQ(shaping.bottom, 60); + ASSERT_EQ(shaping.left, 0); + ASSERT_EQ(shaping.right, 0); + ASSERT_EQ(shaping.writingMode, WritingModeType::Horizontal); + } +} -- cgit v1.2.1