fix(createCharacterComparison): change line break logic to ensure correct text wrap
This commit is contained in:
@@ -150,6 +150,26 @@ export function createCharacterComparison<
|
|||||||
currentLineWords = [];
|
currentLineWords = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wordWidthA = measureText(
|
||||||
|
ctx,
|
||||||
|
word,
|
||||||
|
Math.min(fontSize, controlledFontSize),
|
||||||
|
currentWeight,
|
||||||
|
fontA()?.name,
|
||||||
|
);
|
||||||
|
const wordWidthB = measureText(
|
||||||
|
ctx,
|
||||||
|
word,
|
||||||
|
Math.min(fontSize, controlledFontSize),
|
||||||
|
currentWeight,
|
||||||
|
fontB()?.name,
|
||||||
|
);
|
||||||
|
const wordAloneWidth = Math.max(wordWidthA, wordWidthB);
|
||||||
|
|
||||||
|
if (wordAloneWidth <= availableWidth) {
|
||||||
|
// If word fits start new line with it
|
||||||
|
currentLineWords = [word];
|
||||||
|
} else {
|
||||||
let remainingWord = word;
|
let remainingWord = word;
|
||||||
while (remainingWord.length > 0) {
|
while (remainingWord.length > 0) {
|
||||||
let low = 1;
|
let low = 1;
|
||||||
@@ -187,6 +207,7 @@ export function createCharacterComparison<
|
|||||||
pushLine([remainingWord.slice(0, bestBreak)]);
|
pushLine([remainingWord.slice(0, bestBreak)]);
|
||||||
remainingWord = remainingWord.slice(bestBreak);
|
remainingWord = remainingWord.slice(bestBreak);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (maxWidth > availableWidth && currentLineWords.length > 0) {
|
} else if (maxWidth > availableWidth && currentLineWords.length > 0) {
|
||||||
pushLine(currentLineWords);
|
pushLine(currentLineWords);
|
||||||
currentLineWords = [word];
|
currentLineWords = [word];
|
||||||
|
|||||||
Reference in New Issue
Block a user