mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-04-14 16:40:58 -04:00
fix safari backward compat
This commit is contained in:
parent
c0e88fbc54
commit
3a68f0ae7b
2 changed files with 15 additions and 2 deletions
|
@ -14,6 +14,7 @@ import {
|
||||||
DEFAULT_FONT_FAMILY,
|
DEFAULT_FONT_FAMILY,
|
||||||
DEFAULT_FONT_SIZE,
|
DEFAULT_FONT_SIZE,
|
||||||
FONT_FAMILY,
|
FONT_FAMILY,
|
||||||
|
isSafari,
|
||||||
TEXT_ALIGN,
|
TEXT_ALIGN,
|
||||||
VERTICAL_ALIGN,
|
VERTICAL_ALIGN,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
|
@ -312,6 +313,7 @@ export const measureBaseline = (
|
||||||
}
|
}
|
||||||
|
|
||||||
container.style.lineHeight = String(lineHeight);
|
container.style.lineHeight = String(lineHeight);
|
||||||
|
const canvasHeight = getTextHeight(text, parseFloat(font), lineHeight);
|
||||||
|
|
||||||
container.innerText = text;
|
container.innerText = text;
|
||||||
|
|
||||||
|
@ -324,7 +326,17 @@ export const measureBaseline = (
|
||||||
span.style.width = "1px";
|
span.style.width = "1px";
|
||||||
span.style.height = "1px";
|
span.style.height = "1px";
|
||||||
container.appendChild(span);
|
container.appendChild(span);
|
||||||
const baseline = span.offsetTop + span.offsetHeight;
|
let baseline = span.offsetTop + span.offsetHeight;
|
||||||
|
const domHeight = container.offsetHeight;
|
||||||
|
|
||||||
|
// In Safari sometimes DOM height could be less than canvas height due to
|
||||||
|
// which text could go out of the bounding box hence shifting the baseline
|
||||||
|
// to make sure text is rendered correctly
|
||||||
|
if (isSafari) {
|
||||||
|
if (canvasHeight > domHeight) {
|
||||||
|
baseline += canvasHeight - domHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
document.body.removeChild(container);
|
document.body.removeChild(container);
|
||||||
return baseline;
|
return baseline;
|
||||||
};
|
};
|
||||||
|
|
|
@ -290,8 +290,9 @@ const drawElementOnCanvas = (
|
||||||
element.lineHeight,
|
element.lineHeight,
|
||||||
);
|
);
|
||||||
const verticalOffset = element.height - element.baseline;
|
const verticalOffset = element.height - element.baseline;
|
||||||
|
console.log(verticalOffset);
|
||||||
for (let index = 0; index < lines.length; index++) {
|
for (let index = 0; index < lines.length; index++) {
|
||||||
|
console.log("FACTOR", verticalOffset);
|
||||||
context.fillText(
|
context.fillText(
|
||||||
lines[index],
|
lines[index],
|
||||||
horizontalOffset,
|
horizontalOffset,
|
||||||
|
|
Loading…
Add table
Reference in a new issue