diff options
author | Seigo Nonaka <nona@google.com> | 2021-04-04 20:13:13 -0700 |
---|---|---|
committer | Seigo Nonaka <nona@google.com> | 2021-04-04 20:16:08 -0700 |
commit | 55702506cd11b2fb091334933be9ac7f98def4fe (patch) | |
tree | e6f1c5c8ca49199807598d738050563254da11fc | |
parent | 306e9b332133b92c5704efba23c3584687e4b0f7 (diff) | |
download | minikin-55702506cd11b2fb091334933be9ac7f98def4fe.tar.gz |
Fix rounding error for line break.
Bug: 183128727
Test: minikin_test
Change-Id: Ie36562e805d9844bdba1c16ecc7aab8a51c04ab4
-rw-r--r-- | libs/minikin/GreedyLineBreaker.cpp | 2 | ||||
-rw-r--r-- | tests/unittest/GreedyLineBreakerTest.cpp | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/libs/minikin/GreedyLineBreaker.cpp b/libs/minikin/GreedyLineBreaker.cpp index f6952a9..9bcb22d 100644 --- a/libs/minikin/GreedyLineBreaker.cpp +++ b/libs/minikin/GreedyLineBreaker.cpp @@ -255,7 +255,7 @@ bool GreedyLineBreaker::tryLineBreakWithHyphenation(const Range& range, WordBrea // TODO: Respect trailing line end spaces. bool GreedyLineBreaker::doLineBreakWithGraphemeBounds(const Range& range) { - double width = mMeasuredText.widths[range.getStart()]; + float width = mMeasuredText.widths[range.getStart()]; // Starting from + 1 since at least one character needs to be assigned to a line. for (uint32_t i = range.getStart() + 1; i < range.getEnd(); ++i) { diff --git a/tests/unittest/GreedyLineBreakerTest.cpp b/tests/unittest/GreedyLineBreakerTest.cpp index 13cc03c..e9da1a1 100644 --- a/tests/unittest/GreedyLineBreakerTest.cpp +++ b/tests/unittest/GreedyLineBreakerTest.cpp @@ -93,6 +93,33 @@ private: std::vector<uint8_t> mHyphenationPattern; }; +TEST_F(GreedyLineBreakerTest, 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 = breakLineGreedy(textBuffer, *measuredText, rectangleLineWidth, tabStops, + false /* do hyphenation */); + + EXPECT_EQ(1u, r.breakPoints.size()); +} + TEST_F(GreedyLineBreakerTest, testBreakWithoutHyphenation) { constexpr bool NO_HYPHEN = false; // No hyphenation in this test case. const std::vector<uint16_t> textBuf = utf8ToUtf16("This is an example text."); |