Compare commits

...

1 Commits

Author SHA1 Message Date
Ryan Di
292aa1cddb fix: to support wrapping with autoResize and given dimensions 2025-12-29 17:35:00 +11:00
2 changed files with 31 additions and 13 deletions

View File

@@ -252,12 +252,24 @@ export const newTextElement = (
const fontFamily = opts.fontFamily || DEFAULT_FONT_FAMILY;
const fontSize = opts.fontSize || DEFAULT_FONT_SIZE;
const lineHeight = opts.lineHeight || getLineHeight(fontFamily);
const text = normalizeText(opts.text);
const metrics = measureText(
text,
getFontString({ fontFamily, fontSize }),
lineHeight,
);
const normalizedText = normalizeText(opts.text);
const originalText = opts.originalText ?? normalizedText;
const shouldUseProvidedDimensions =
opts.autoResize === false && opts.width && opts.height;
const text = shouldUseProvidedDimensions
? wrapText(
normalizedText,
getFontString({ fontFamily, fontSize }),
opts.width,
)
: normalizedText;
const metrics = shouldUseProvidedDimensions
? {
width: opts.width,
height: opts.height,
}
: measureText(text, getFontString({ fontFamily, fontSize }), lineHeight);
const textAlign = opts.textAlign || DEFAULT_TEXT_ALIGN;
const verticalAlign = opts.verticalAlign || DEFAULT_VERTICAL_ALIGN;
const offsets = getTextElementPositionOffsets(
@@ -277,7 +289,7 @@ export const newTextElement = (
width: metrics.width,
height: metrics.height,
containerId: opts.containerId || null,
originalText: opts.originalText ?? text,
originalText,
autoResize: opts.autoResize ?? true,
lineHeight,
};

View File

@@ -581,12 +581,18 @@ export const convertToExcalidrawElements = (
const fontSize = element?.fontSize || DEFAULT_FONT_SIZE;
const lineHeight = element?.lineHeight || getLineHeight(fontFamily);
const text = element.text ?? "";
const normalizedText = normalizeText(text);
const metrics = measureText(
normalizedText,
getFontString({ fontFamily, fontSize }),
lineHeight,
);
const shouldUseProvidedDimensions =
element.autoResize === false && element.width && element.height;
const metrics = shouldUseProvidedDimensions
? {
width: element.width,
height: element.height,
}
: measureText(
normalizeText(text),
getFontString({ fontFamily, fontSize }),
lineHeight,
);
excalidrawElement = newTextElement({
width: metrics.width,