summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-05-22 12:02:47 +0300
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-05-24 05:59:07 -0700
commit749044f1b084b7172bd0ac93b0a450599f246f56 (patch)
treec2976b437eca9ff3489063b94f5ed9b1538cb90f /test
parent0333f3fe448e18511060db81f430ef11f0e710df (diff)
downloadqtlocation-mapboxgl-749044f1b084b7172bd0ac93b0a450599f246f56.tar.gz
[core] Add unit test for zero width space line breaking
Diffstat (limited to 'test')
-rw-r--r--test/test-files.json1
-rw-r--r--test/text/shaping.test.cpp95
2 files changed, 96 insertions, 0 deletions
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 <mbgl/test/util.hpp>
+
+#include <mbgl/text/bidi.hpp>
+#include <mbgl/text/tagged_string.hpp>
+#include <mbgl/text/shaping.hpp>
+#include <mbgl/util/constants.hpp>
+
+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<Glyph>(makeMutable<Glyph>(std::move(glyph)));
+ const std::vector<std::string> 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);
+ }
+}