Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12996283 authored by Roozbeh Pournader's avatar Roozbeh Pournader
Browse files

Implement getMinLineWidth for LineWidthDelegate

Minikin needs getMinLineWidth() implemented for supporting desperate
breaks in optimal line breaking. This CL implements it for
StaticLayout.

Bug: 68058572
Test: bit CtsTextTestCases:android.text.cts.StaticLayoutLineBreakingTest
Change-Id: I56f6a592c688d816c201279d35fad65e36dffd84
parent f8a6f1da
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -67,6 +67,18 @@ class JNILineBreakerLineWidth : public minikin::LineBreaker::LineWidthDelegate {
            return width - get(mIndents, lineNo);
        }

        float getMinLineWidth() override {
            // A simpler algorithm would have been simply looping until the larger of
            // mFirstLineCount and mIndents.size()-mOffset, but that does unnecessary calculations
            // when mFirstLineCount is large. Instead, we measure the first line, all the lines that
            // have an indent, and the first line after firstWidth ends and restWidth starts.
            float minWidth = std::min(getLineWidth(0), getLineWidth(mFirstLineCount));
            for (size_t lineNo = 1; lineNo + mOffset < mIndents.size(); lineNo++) {
                minWidth = std::min(minWidth, getLineWidth(lineNo));
            }
            return minWidth;
        }

        float getLeftPadding(size_t lineNo) override {
            return get(mLeftPaddings, lineNo);
        }