mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: compute container height from bound text correctly (#6273)
* fix: compute container height from bound text correctly * fix specs * Add tests
This commit is contained in:
parent
9659254fd6
commit
0e95e2b386
3 changed files with 78 additions and 4 deletions
|
@ -233,7 +233,7 @@ describe("Test measureText", () => {
|
|||
type: "ellipse",
|
||||
...params,
|
||||
});
|
||||
expect(computeContainerHeightForBoundText(element, 150)).toEqual(212);
|
||||
expect(computeContainerHeightForBoundText(element, 150)).toEqual(226);
|
||||
});
|
||||
|
||||
it("should compute container height correctly for diamond", () => {
|
||||
|
@ -241,7 +241,7 @@ describe("Test measureText", () => {
|
|||
type: "diamond",
|
||||
...params,
|
||||
});
|
||||
expect(computeContainerHeightForBoundText(element, 150)).toEqual(300);
|
||||
expect(computeContainerHeightForBoundText(element, 150)).toEqual(320);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -280,6 +280,8 @@ export const getApproxLineHeight = (font: FontString) => {
|
|||
return cacheApproxLineHeight[font];
|
||||
}
|
||||
const fontSize = parseInt(font);
|
||||
|
||||
// Calculate line height relative to font size
|
||||
cacheApproxLineHeight[font] = fontSize * 1.2;
|
||||
return cacheApproxLineHeight[font];
|
||||
};
|
||||
|
@ -727,13 +729,15 @@ export const computeContainerHeightForBoundText = (
|
|||
boundTextElementHeight: number,
|
||||
) => {
|
||||
if (container.type === "ellipse") {
|
||||
return Math.round((boundTextElementHeight / Math.sqrt(2)) * 2);
|
||||
return Math.round(
|
||||
((boundTextElementHeight + BOUND_TEXT_PADDING * 2) / Math.sqrt(2)) * 2,
|
||||
);
|
||||
}
|
||||
if (isArrowElement(container)) {
|
||||
return boundTextElementHeight + BOUND_TEXT_PADDING * 8 * 2;
|
||||
}
|
||||
if (container.type === "diamond") {
|
||||
return 2 * boundTextElementHeight;
|
||||
return 2 * (boundTextElementHeight + BOUND_TEXT_PADDING * 2);
|
||||
}
|
||||
return boundTextElementHeight + BOUND_TEXT_PADDING * 2;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue