summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeigo Nonaka <nona@google.com>2021-04-30 12:35:30 -0700
committerSeigo Nonaka <nona@google.com>2021-04-30 12:35:30 -0700
commita03dbd008006a7f9440266b0b5e3fa2d6cfe64e8 (patch)
tree081199d33bc00399a2dce5f34c00e399e970cb36
parent50d666ec9e7dad52f7170378bde629827f59e446 (diff)
downloadminikin-a03dbd008006a7f9440266b0b5e3fa2d6cfe64e8.tar.gz
Update paragraph width size to float
Bug: 183128727 Test: minikin_test Change-Id: I043131a352674fec8caa705c001ceeb348869d46
-rw-r--r--libs/minikin/LineBreakerUtil.h2
-rw-r--r--tests/unittest/OptimalLineBreakerTest.cpp28
2 files changed, 29 insertions, 1 deletions
diff --git a/libs/minikin/LineBreakerUtil.h b/libs/minikin/LineBreakerUtil.h
index eb058cc..8b383a4 100644
--- a/libs/minikin/LineBreakerUtil.h
+++ b/libs/minikin/LineBreakerUtil.h
@@ -36,7 +36,7 @@ namespace minikin {
// paragraphs, accuracy could degrade using only 32-bit float. Note however that float is used
// extensively on the Java side for this. This is a typedef so that we can easily change it based
// on performance/accuracy tradeoff.
-typedef double ParaWidth;
+typedef float ParaWidth;
// Hyphenates a string potentially containing non-breaking spaces.
std::vector<HyphenationType> hyphenate(const U16StringPiece& string, const Hyphenator& hypenator);
diff --git a/tests/unittest/OptimalLineBreakerTest.cpp b/tests/unittest/OptimalLineBreakerTest.cpp
index 51aab60..d6801cc 100644
--- a/tests/unittest/OptimalLineBreakerTest.cpp
+++ b/tests/unittest/OptimalLineBreakerTest.cpp
@@ -2080,5 +2080,33 @@ TEST_F(OptimalLineBreakerTest, testControllCharAfterSpace) {
<< toString(textBuf, actual);
}
}
+
+TEST_F(OptimalLineBreakerTest, roundingError) {
+ MeasuredTextBuilder builder;
+ auto family1 = buildFontFamily("Ascii.ttf");
+ std::vector<std::shared_ptr<FontFamily>> families = {family1};
+ auto fc = std::make_shared<FontCollection>(families);
+ MinikinPaint paint(fc);
+ paint.size = 56.0f; // Make 1em=56px
+ paint.scaleX = 1;
+ paint.letterSpacing = -0.093f;
+ paint.localeListId = LocaleListCache::getId("en-US");
+ const std::vector<uint16_t> textBuffer = utf8ToUtf16("8888888888888888888");
+
+ float measured = Layout::measureText(textBuffer, Range(0, textBuffer.size()), Bidi::LTR, paint,
+ StartHyphenEdit::NO_EDIT, EndHyphenEdit::NO_EDIT, nullptr);
+
+ builder.addStyleRun(0, textBuffer.size(), std::move(paint), false);
+ std::unique_ptr<MeasuredText> measuredText =
+ builder.build(textBuffer, false /* compute hyphenation */,
+ false /* compute full layout */, nullptr /* no hint */);
+ RectangleLineWidth rectangleLineWidth(measured);
+ TabStops tabStops(nullptr, 0, 10);
+ LineBreakResult r = doLineBreak(textBuffer, *measuredText, BreakStrategy::Balanced,
+ HyphenationFrequency::None, measured);
+
+ EXPECT_EQ(1u, r.breakPoints.size());
+}
+
} // namespace
} // namespace minikin