Skip to content

Commit

Permalink
Fix bug when last word of current line is reached in wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddykasp committed Oct 21, 2024
1 parent 0e47264 commit 5585a8f
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,24 @@ public Result doResizeLabel(final ElkLabel label, final double targetWidth) {

// Check whether next line would be below the fuzzy threshold
int previewWordIndex = currWordIndex;
String previewLineText = words[previewWordIndex];
testText = previewLineText;
do {
previewLineText = testText;
if (previewWordIndex < words.length - 1) {
testText = previewLineText + " " + words[++previewWordIndex];
} else {
testText = " ";
previewWordIndex++;
if (previewWordIndex < words.length) {
String previewLineText = words[previewWordIndex];
testText = previewLineText;
do {
previewLineText = testText;
if (previewWordIndex < words.length - 1) {
testText = previewLineText + " " + words[++previewWordIndex];
} else {
testText = " ";
previewWordIndex++;
}
lineWidth = PlacementUtil.estimateTextSize(font, testText).getWidth();
} while (lineWidth < effectiveTargetWidth && previewWordIndex < words.length);
if (lineWidth < effectiveTargetWidth * getFuzzyness(label)) {
// next line would contain too much whitespace so append it to this line
currWordIndex = previewWordIndex;
currentLineText += " " + previewLineText;
}
lineWidth = PlacementUtil.estimateTextSize(font, testText).getWidth();
} while (lineWidth < effectiveTargetWidth && previewWordIndex < words.length);
if (lineWidth < effectiveTargetWidth * getFuzzyness(label)) {
// next line would contain too much whitespace so append it to this line
currWordIndex = previewWordIndex;
currentLineText += " " + previewLineText;
}

// No more words fit so the line is added to the result
Expand Down

0 comments on commit 5585a8f

Please sign in to comment.