fix: to support wrapping with autoResize and given dimensions
This commit is contained in:
@@ -252,12 +252,24 @@ export const newTextElement = (
|
|||||||
const fontFamily = opts.fontFamily || DEFAULT_FONT_FAMILY;
|
const fontFamily = opts.fontFamily || DEFAULT_FONT_FAMILY;
|
||||||
const fontSize = opts.fontSize || DEFAULT_FONT_SIZE;
|
const fontSize = opts.fontSize || DEFAULT_FONT_SIZE;
|
||||||
const lineHeight = opts.lineHeight || getLineHeight(fontFamily);
|
const lineHeight = opts.lineHeight || getLineHeight(fontFamily);
|
||||||
const text = normalizeText(opts.text);
|
const normalizedText = normalizeText(opts.text);
|
||||||
const metrics = measureText(
|
const originalText = opts.originalText ?? normalizedText;
|
||||||
text,
|
const shouldUseProvidedDimensions =
|
||||||
getFontString({ fontFamily, fontSize }),
|
opts.autoResize === false && opts.width && opts.height;
|
||||||
lineHeight,
|
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 textAlign = opts.textAlign || DEFAULT_TEXT_ALIGN;
|
||||||
const verticalAlign = opts.verticalAlign || DEFAULT_VERTICAL_ALIGN;
|
const verticalAlign = opts.verticalAlign || DEFAULT_VERTICAL_ALIGN;
|
||||||
const offsets = getTextElementPositionOffsets(
|
const offsets = getTextElementPositionOffsets(
|
||||||
@@ -277,7 +289,7 @@ export const newTextElement = (
|
|||||||
width: metrics.width,
|
width: metrics.width,
|
||||||
height: metrics.height,
|
height: metrics.height,
|
||||||
containerId: opts.containerId || null,
|
containerId: opts.containerId || null,
|
||||||
originalText: opts.originalText ?? text,
|
originalText,
|
||||||
autoResize: opts.autoResize ?? true,
|
autoResize: opts.autoResize ?? true,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -581,12 +581,18 @@ export const convertToExcalidrawElements = (
|
|||||||
const fontSize = element?.fontSize || DEFAULT_FONT_SIZE;
|
const fontSize = element?.fontSize || DEFAULT_FONT_SIZE;
|
||||||
const lineHeight = element?.lineHeight || getLineHeight(fontFamily);
|
const lineHeight = element?.lineHeight || getLineHeight(fontFamily);
|
||||||
const text = element.text ?? "";
|
const text = element.text ?? "";
|
||||||
const normalizedText = normalizeText(text);
|
const shouldUseProvidedDimensions =
|
||||||
const metrics = measureText(
|
element.autoResize === false && element.width && element.height;
|
||||||
normalizedText,
|
const metrics = shouldUseProvidedDimensions
|
||||||
getFontString({ fontFamily, fontSize }),
|
? {
|
||||||
lineHeight,
|
width: element.width,
|
||||||
);
|
height: element.height,
|
||||||
|
}
|
||||||
|
: measureText(
|
||||||
|
normalizeText(text),
|
||||||
|
getFontString({ fontFamily, fontSize }),
|
||||||
|
lineHeight,
|
||||||
|
);
|
||||||
|
|
||||||
excalidrawElement = newTextElement({
|
excalidrawElement = newTextElement({
|
||||||
width: metrics.width,
|
width: metrics.width,
|
||||||
|
|||||||
Reference in New Issue
Block a user