summaryrefslogtreecommitdiff
path: root/tests/unittest/MeasuredTextTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittest/MeasuredTextTest.cpp')
-rw-r--r--tests/unittest/MeasuredTextTest.cpp105
1 files changed, 87 insertions, 18 deletions
diff --git a/tests/unittest/MeasuredTextTest.cpp b/tests/unittest/MeasuredTextTest.cpp
index 1934ed8..e5766a1 100644
--- a/tests/unittest/MeasuredTextTest.cpp
+++ b/tests/unittest/MeasuredTextTest.cpp
@@ -19,6 +19,7 @@
#include <gtest/gtest.h>
#include "minikin/LineBreaker.h"
+#include "minikin/Measurement.h"
#include "FontTestUtils.h"
#include "UnicodeUtils.h"
@@ -75,6 +76,34 @@ TEST(MeasuredTextTest, getBoundsTest) {
EXPECT_EQ(MinikinRect(0.0f, 10.0f, 130.0f, 0.0f), mt->getBounds(text, Range(0, text.size())));
}
+TEST(MeasuredTextTest, getBoundsTest_LTR) {
+ auto text = utf8ToUtf16("\u0028"); // U+0028 has 1em in LTR, 3em in RTL.
+ auto font = buildFontCollection("Bbox.ttf");
+
+ MeasuredTextBuilder builder;
+ MinikinPaint paint(font);
+ paint.size = 10.0f;
+ builder.addStyleRun(0, text.size(), std::move(paint), false /* is RTL */);
+ auto mt = builder.build(text, true /* hyphenation */, true /* full layout */,
+ nullptr /* no hint */);
+
+ EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), mt->getBounds(text, Range(0, 1)));
+}
+
+TEST(MeasuredTextTest, getBoundsTest_RTL) {
+ auto text = utf8ToUtf16("\u0028"); // U+0028 has 1em in LTR, 3em in RTL.
+ auto font = buildFontCollection("Bbox.ttf");
+
+ MeasuredTextBuilder builder;
+ MinikinPaint paint(font);
+ paint.size = 10.0f;
+ builder.addStyleRun(0, text.size(), std::move(paint), true /* is RTL */);
+ auto mt = builder.build(text, true /* hyphenation */, true /* full layout */,
+ nullptr /* no hint */);
+
+ EXPECT_EQ(MinikinRect(0.0f, 30.0f, 30.0f, 0.0f), mt->getBounds(text, Range(0, 2)));
+}
+
TEST(MeasuredTextTest, getBoundsTest_multiStyle) {
auto text = utf8ToUtf16("Hello, World!");
auto font = buildFontCollection("Ascii.ttf");
@@ -155,6 +184,7 @@ TEST(MeasuredTextTest, buildLayoutTest) {
auto mt = builder.build(text, true /* hyphenation */, true /* full layout */,
nullptr /* no hint */);
+ MinikinRect rect;
MinikinPaint samePaint(font);
samePaint.size = 10.0f;
@@ -171,7 +201,9 @@ TEST(MeasuredTextTest, buildLayoutTest) {
EXPECT_EQ(10.0f, layout.getAdvance());
EXPECT_EQ(10.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, 1), Bidi::LTR, samePaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(0, 2), fullContext, samePaint, StartHyphenEdit::NO_EDIT,
EndHyphenEdit::NO_EDIT);
@@ -185,7 +217,9 @@ TEST(MeasuredTextTest, buildLayoutTest) {
EXPECT_EQ(10.0f, layout.getCharAdvance(0));
EXPECT_EQ(10.0f, layout.getCharAdvance(1));
EXPECT_EQ(2u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 10.0f, 20.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, 2), Bidi::LTR, samePaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 10.0f, 20.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(1, 2), fullContext, samePaint, StartHyphenEdit::NO_EDIT,
EndHyphenEdit::NO_EDIT);
@@ -196,7 +230,9 @@ TEST(MeasuredTextTest, buildLayoutTest) {
EXPECT_EQ(10.0f, layout.getAdvance());
EXPECT_EQ(10.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(1, 2), Bidi::LTR, samePaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(0, text.size()), fullContext, samePaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -210,7 +246,9 @@ TEST(MeasuredTextTest, buildLayoutTest) {
}
EXPECT_EQ(130.0f, layout.getAdvance());
EXPECT_EQ(text.size(), layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 10.0f, 130.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, text.size()), Bidi::LTR, samePaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 10.0f, 130.0f, 0.0f), rect);
}
TEST(MeasuredTextTest, buildLayoutTest_multiStyle) {
@@ -229,6 +267,7 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle) {
auto mt = builder.build(text, true /* hyphenation */, true /* full layout */,
nullptr /* no hint */);
+ MinikinRect rect;
MinikinPaint samePaint(font);
samePaint.size = 10.0f;
@@ -245,7 +284,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle) {
EXPECT_EQ(10.0f, layout.getAdvance());
EXPECT_EQ(10.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, 1), Bidi::LTR, samePaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(0, 2), fullContext, samePaint, StartHyphenEdit::NO_EDIT,
EndHyphenEdit::NO_EDIT);
@@ -259,7 +300,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle) {
EXPECT_EQ(10.0f, layout.getCharAdvance(0));
EXPECT_EQ(10.0f, layout.getCharAdvance(1));
EXPECT_EQ(2u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 10.0f, 20.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, 2), Bidi::LTR, samePaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 10.0f, 20.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(1, 2), fullContext, samePaint, StartHyphenEdit::NO_EDIT,
EndHyphenEdit::NO_EDIT);
@@ -270,7 +313,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle) {
EXPECT_EQ(10.0f, layout.getAdvance());
EXPECT_EQ(10.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(1, 2), Bidi::LTR, samePaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 10.0f, 10.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(7, 7), fullContext, samePaint, StartHyphenEdit::NO_EDIT,
EndHyphenEdit::NO_EDIT);
@@ -287,7 +332,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle) {
EXPECT_EQ(20.0f, layout.getAdvance());
EXPECT_EQ(20.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 20.0f, 20.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(7, 8), Bidi::LTR, samePaint2, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 20.0f, 20.0f, 0.0f), rect);
}
TEST(MeasuredTextTest, buildLayoutTest_differentPaint) {
@@ -302,6 +349,7 @@ TEST(MeasuredTextTest, buildLayoutTest_differentPaint) {
auto mt = builder.build(text, true /* hyphenation */, true /* full layout */,
nullptr /* no hint */);
+ MinikinRect rect;
MinikinPaint differentPaint(font);
differentPaint.size = 20.0f;
@@ -318,7 +366,9 @@ TEST(MeasuredTextTest, buildLayoutTest_differentPaint) {
EXPECT_EQ(20.0f, layout.getAdvance());
EXPECT_EQ(20.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 20.0f, 20.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, 1), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 20.0f, 20.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(0, 2), fullContext, differentPaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -332,7 +382,9 @@ TEST(MeasuredTextTest, buildLayoutTest_differentPaint) {
EXPECT_EQ(20.0f, layout.getCharAdvance(0));
EXPECT_EQ(20.0f, layout.getCharAdvance(1));
EXPECT_EQ(2u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 20.0f, 40.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, 2), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 20.0f, 40.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(1, 2), fullContext, differentPaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -343,7 +395,9 @@ TEST(MeasuredTextTest, buildLayoutTest_differentPaint) {
EXPECT_EQ(20.0f, layout.getAdvance());
EXPECT_EQ(20.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 20.0f, 20.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(1, 2), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 20.0f, 20.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(0, text.size()), fullContext, differentPaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -357,7 +411,9 @@ TEST(MeasuredTextTest, buildLayoutTest_differentPaint) {
}
EXPECT_EQ(260.0f, layout.getAdvance());
EXPECT_EQ(text.size(), layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 20.0f, 260.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, text.size()), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 20.0f, 260.0f, 0.0f), rect);
}
TEST(MeasuredTextTest, buildLayoutTest_multiStyle_differentPaint) {
@@ -376,6 +432,7 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle_differentPaint) {
auto mt = builder.build(text, true /* hyphenation */, true /* full layout */,
nullptr /* no hint */);
+ MinikinRect rect;
MinikinPaint differentPaint(font);
differentPaint.size = 30.0f;
@@ -392,7 +449,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle_differentPaint) {
EXPECT_EQ(30.0f, layout.getAdvance());
EXPECT_EQ(30.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 30.0f, 30.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, 1), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 30.0f, 30.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(0, 2), fullContext, differentPaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -406,7 +465,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle_differentPaint) {
EXPECT_EQ(30.0f, layout.getCharAdvance(0));
EXPECT_EQ(30.0f, layout.getCharAdvance(1));
EXPECT_EQ(2u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 30.0f, 60.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, 2), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 30.0f, 60.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(1, 2), fullContext, differentPaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -417,7 +478,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle_differentPaint) {
EXPECT_EQ(30.0f, layout.getAdvance());
EXPECT_EQ(30.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 30.0f, 30.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(1, 2), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 30.0f, 30.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(7, 7), fullContext, differentPaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -432,7 +495,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle_differentPaint) {
EXPECT_EQ(30.0f, layout.getAdvance());
EXPECT_EQ(30.0f, layout.getCharAdvance(0));
EXPECT_EQ(1u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 30.0f, 30.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(7, 8), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 30.0f, 30.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(6, 8), fullContext, differentPaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -446,7 +511,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle_differentPaint) {
EXPECT_EQ(30.0f, layout.getCharAdvance(0));
EXPECT_EQ(30.0f, layout.getCharAdvance(1));
EXPECT_EQ(2u, layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 30.0f, 60.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(6, 8), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 30.0f, 60.0f, 0.0f), rect);
layout = mt->buildLayout(text, Range(0, text.size()), fullContext, differentPaint,
StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT);
@@ -460,7 +527,9 @@ TEST(MeasuredTextTest, buildLayoutTest_multiStyle_differentPaint) {
}
EXPECT_EQ(390.0f, layout.getAdvance());
EXPECT_EQ(text.size(), layout.getAdvances().size());
- EXPECT_EQ(MinikinRect(0.0f, 30.0f, 390.0f, 0.0f), layout.getBounds());
+ getBounds(text, Range(0, text.size()), Bidi::LTR, differentPaint, StartHyphenEdit::NO_EDIT,
+ EndHyphenEdit::NO_EDIT, &rect);
+ EXPECT_EQ(MinikinRect(0.0f, 30.0f, 390.0f, 0.0f), rect);
}
} // namespace minikin