Disable implicit text wrapping
This commit is contained in:
+4
-18
@@ -102,22 +102,8 @@ function clamp(value, min, max) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
function wrapCanvasText(text, maxWidthPx) {
|
||||
const lines = [];
|
||||
for (const rawLine of String(text || "").split("\n")) {
|
||||
let current = "";
|
||||
for (const word of rawLine.split(" ")) {
|
||||
const candidate = current ? `${current} ${word}` : word;
|
||||
if (ctx.measureText(candidate).width <= maxWidthPx) {
|
||||
current = candidate;
|
||||
continue;
|
||||
}
|
||||
if (current) lines.push(current);
|
||||
current = word;
|
||||
}
|
||||
lines.push(current);
|
||||
}
|
||||
return lines.length ? lines : [""];
|
||||
function canvasTextLines(text) {
|
||||
return String(text || "").split("\n");
|
||||
}
|
||||
|
||||
function textNaturalWidthMm(obj) {
|
||||
@@ -149,7 +135,7 @@ function objectContentEndMm(obj) {
|
||||
const { value } = objectFont(obj);
|
||||
ctx.save();
|
||||
ctx.font = value;
|
||||
const lines = wrapCanvasText(obj.text || "", mmToPx(obj.w));
|
||||
const lines = canvasTextLines(obj.text || "");
|
||||
const textWidthMm = Math.max(...lines.map((line) => pxToMm(ctx.measureText(line).width)), 0);
|
||||
ctx.restore();
|
||||
|
||||
@@ -255,7 +241,7 @@ function drawTextObject(obj) {
|
||||
ctx.font = font;
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.textAlign = obj.align || "left";
|
||||
const lines = wrapCanvasText(obj.text || "", w);
|
||||
const lines = canvasTextLines(obj.text || "");
|
||||
const lineHeight = fontPx * 1.15;
|
||||
const total = lineHeight * lines.length;
|
||||
let cy = y + h / 2 - total / 2 + lineHeight / 2;
|
||||
|
||||
Reference in New Issue
Block a user