mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(meme-generator): auto-sizer now checks line width, preventing text overflow
This commit is contained in:
@@ -152,8 +152,9 @@ export function autoSizeFontToFit(
|
|||||||
const mid = Math.floor((lo + hi) / 2);
|
const mid = Math.floor((lo + hi) / 2);
|
||||||
const lines = wrapText(text, fontFamily, mid, boxWidth);
|
const lines = wrapText(text, fontFamily, mid, boxWidth);
|
||||||
const totalHeight = lines.length * mid * LINE_HEIGHT_FACTOR;
|
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;
|
best = mid;
|
||||||
lo = mid + 1;
|
lo = mid + 1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user