fix: 4d6d6cf1 had a line-height regression for sufficiently short math symbols

This commit is contained in:
Daniel J. Geiger 2023-09-22 14:34:44 -05:00
parent 8eb3191b3f
commit 7225915b82
2 changed files with 27 additions and 1 deletions

View File

@ -668,7 +668,7 @@ const measureMarkup = (
} }
document.body.removeChild(container); document.body.removeChild(container);
let width = 0; let width = 0;
let height = 0; let height = measureText(" ", font, lineHeight).height;
childMetrics.forEach((metrics) => (width += metrics.width)); childMetrics.forEach((metrics) => (width += metrics.width));
childMetrics.forEach( childMetrics.forEach(
(metrics) => (height = Math.max(height, metrics.height)), (metrics) => (height = Math.max(height, metrics.height)),

View File

@ -18,4 +18,30 @@ describe("mathjax", () => {
const metrics2 = measureTextElement(elements[1]); const metrics2 = measureTextElement(elements[1]);
expect(metrics1).toStrictEqual(metrics2); expect(metrics1).toStrictEqual(metrics2);
}); });
it("minimum height remains", async () => {
await render(<ExcalidrawApp />);
await ensureSubtypesLoaded(["math"]);
const elements = [
API.createElement({ type: "text", id: "A", text: "a" }),
API.createElement({
type: "text",
id: "B",
text: "\\(\\alpha\\)",
subtype: "math",
customData: { useTex: true },
}),
API.createElement({
type: "text",
id: "C",
text: "`beta`",
subtype: "math",
customData: { useTex: false },
}),
];
const height = measureTextElement(elements[0]).height;
const height1 = measureTextElement(elements[1]).height;
const height2 = measureTextElement(elements[2]).height;
expect(height).toEqual(height1);
expect(height).toEqual(height2);
});
}); });