Fix multi-line breaks in a few commands

This commit is contained in:
Dragon Fire
2024-05-03 10:46:51 -04:00
parent 30c098916b
commit 7916e61bdc
4 changed files with 36 additions and 10 deletions
+17 -2
View File
@@ -197,11 +197,11 @@ module.exports = class CanvasUtil {
return ctx;
}
static fillTextWithBreaks(ctx, text, x, y, maxLen) {
static fillTextWithBreaks(ctx, text, x, y, maxLen, drawMultiBreaks = false) {
const lines = text.split('\n');
let currentY = y;
for (const line of lines) {
if (line === '') {
if (line === '' && drawMultiBreaks) {
const metrics = ctx.measureText('a');
currentY += metrics.emHeightAscent + metrics.emHeightDescent;
} else {
@@ -213,6 +213,21 @@ module.exports = class CanvasUtil {
return ctx;
}
measureTextHeightWithBreaks(ctx, text, parseMultiBreaks = false) {
const lines = text.split('\n');
let result = 0;
for (const line of lines) {
if (line === '' && parseMultiBreaks) {
const metrics = ctx.measureText('a');
result += metrics.emHeightAscent + metrics.emHeightDescent;
} else {
const metrics = ctx.measureText(line);
result += metrics.emHeightAscent + metrics.emHeightDescent;
}
}
return result;
}
static shortenText(ctx, text, maxWidth) {
let shorten = false;
while (ctx.measureText(`${text}...`).width > maxWidth) {