Skip to content

Commit

Permalink
Revert "Merge pull request #225 from Bowen-0x00/master"
Browse files Browse the repository at this point in the history
This reverts commit e1768de, reversing
changes made to 452fa1c.
  • Loading branch information
zsviczian committed Jun 18, 2024
1 parent e1768de commit 36e266e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 60 deletions.
60 changes: 1 addition & 59 deletions packages/excalidraw/element/textElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
FONT_FAMILY,
TEXT_ALIGN,
VERTICAL_ALIGN,
isSafari,
} from "../constants";
import type { MaybeTransformHandleType } from "./transformHandles";
import { isTextElement } from ".";
Expand All @@ -32,7 +31,6 @@ import {
updateOriginalContainerCache,
} from "./containerCache";
import type { ExtractSetType, MakeBrand } from "../utility-types";
import { hostPlugin } from "../components/App";

export const normalizeText = (text: string) => {
return (
Expand Down Expand Up @@ -300,63 +298,7 @@ export const measureText = (
const fontSize = parseFloat(font);
const height = getTextHeight(text, fontSize, lineHeight);
const width = getTextWidth(text, font);
const baseline = measureBaseline(text, font, lineHeight);

return { width, height, baseline };
};

export const measureBaseline = (
text: string,
font: FontString,
lineHeight: ExcalidrawTextElement["lineHeight"],
wrapInContainer?: boolean,
) => {
//zsviczian - avoiding frequent dom event at the top level of the document
//addressess slow performance when scaling sticky notes in Obsidian popout windows
const textMeasureDiv = hostPlugin?.textMeasureDiv ?? document.body; //zsviczian
const container = document.createElement("div");
container.style.position = "absolute";
container.style.whiteSpace = "pre";
container.style.font = font;
container.style.minHeight = "1em";
if (wrapInContainer) {
container.style.overflow = "hidden";
container.style.wordBreak = "break-word";
container.style.whiteSpace = "pre-wrap";
}

container.style.lineHeight = String(lineHeight);

container.innerText = text;

// Baseline is important for positioning text on canvas
textMeasureDiv.appendChild(container); //zsviczian

const span = document.createElement("span");
span.style.display = "inline-block";
span.style.overflow = "hidden";
span.style.width = "1px";
span.style.height = "1px";
container.appendChild(span);
let baseline = span.offsetTop + span.offsetHeight;
const height = container.offsetHeight;

if (isSafari) {
const canvasHeight = getTextHeight(text, parseFloat(font), lineHeight);
const fontSize = parseFloat(font);
// In Safari the font size gets rounded off when rendering hence calculating the safari height and shifting the baseline if it differs
// from the actual canvas height
const domHeight = getTextHeight(text, Math.round(fontSize), lineHeight);
if (canvasHeight > height) {
baseline += canvasHeight - domHeight;
}

if (height > canvasHeight) {
baseline -= domHeight - canvasHeight;
}
}
textMeasureDiv.removeChild(container); //zsviczian
return baseline;
return { width, height };
};

/**
Expand Down
1 change: 0 additions & 1 deletion packages/utils/geometry/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ export const getClosedCurveShape = (
}

const polygonPoints = pointsOnBezierCurves(points, 10, 5).map((p) =>
// @ts-ignore
transform(p),
);

Expand Down

0 comments on commit 36e266e

Please sign in to comment.