Skip to content

Commit

Permalink
Merge pull request #226 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
Fix getBoundingBoxes returning emptyList when the last line is empty
  • Loading branch information
MohamedRejeb authored Mar 30, 2024
2 parents 59e9b43 + 80b0987 commit ec09b91
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ fun TextLayoutResult.getBoundingBoxes(
if (multiParagraph.lineCount == 0)
return emptyList()

val lastLinePosition =
Offset(
x = multiParagraph.getLineRight(multiParagraph.lineCount - 1),
y = multiParagraph.getLineTop(multiParagraph.lineCount - 1)
)
var lastOffset = 0
var lastNonEmptyLineIndex = multiParagraph.lineCount - 1

while (lastOffset == 0 && lastNonEmptyLineIndex >= 0) {
val lastLinePosition =
Offset(
x = multiParagraph.getLineRight(lastNonEmptyLineIndex),
y = multiParagraph.getLineTop(lastNonEmptyLineIndex)
)

val lastOffset = multiParagraph.getOffsetForPosition(lastLinePosition)
lastOffset = multiParagraph.getOffsetForPosition(lastLinePosition)
lastNonEmptyLineIndex--
}

if (startOffset >= lastOffset)
return emptyList()
Expand Down

0 comments on commit ec09b91

Please sign in to comment.