fix(meme-generator): auto-sizer now checks line width, preventing text overflow

This commit is contained in:
SnapOtter
2026-05-08 17:44:48 +08:00
parent 0c1980c6db
commit a157af2ea9
+2 -1
View File
@@ -152,8 +152,9 @@ export function autoSizeFontToFit(
const mid = Math.floor((lo + hi) / 2);
const lines = wrapText(text, fontFamily, mid, boxWidth);
const totalHeight = lines.length * mid * LINE_HEIGHT_FACTOR;
const maxLineWidth = Math.max(...lines.map((l) => measureText(l, fontFamily, mid)));
if (totalHeight <= boxHeight) {
if (totalHeight <= boxHeight && maxLineWidth <= boxWidth) {
best = mid;
lo = mid + 1;
} else {