WIP: scale font size in Safari

This commit is contained in:
Aakansha Doshi 2023-04-07 13:32:17 +05:30
parent ca5e246074
commit e69c626ead

View File

@ -37,6 +37,7 @@ import {
computeContainerDimensionForBoundText, computeContainerDimensionForBoundText,
getDOMMetrics, getDOMMetrics,
splitIntoLines, splitIntoLines,
detectLineHeight,
} from "./textElement"; } from "./textElement";
import { import {
actionDecreaseFontSize, actionDecreaseFontSize,
@ -280,30 +281,31 @@ export const textWysiwyg = ({
); );
let lineHeight = element.lineHeight; let lineHeight = element.lineHeight;
if (isSafari && domHeight > textElementHeight) { const fontSize = Math.floor(updatedTextElement.fontSize);
lineHeight = (Math.floor(element.lineHeight * element.fontSize) /
element.fontSize) as ExcalidrawTextElement["lineHeight"]; if (isSafari) {
//@ts-ignore
lineHeight =
updatedTextElement.height /
splitIntoLines(updatedTextElement.text).length /
fontSize;
} }
// Make sure text editor height doesn't go beyond viewport // Make sure text editor height doesn't go beyond viewport
const editorMaxHeight = const editorMaxHeight =
(appState.height - viewportY) / appState.zoom.value; (appState.height - viewportY) / appState.zoom.value;
Object.assign(editable.style, { Object.assign(editable.style, {
font: getFontString(updatedTextElement), font: getFontString({
fontSize,
fontFamily: updatedTextElement.fontFamily,
}),
// must be defined *after* font ¯\_(ツ)_/¯ // must be defined *after* font ¯\_(ツ)_/¯
lineHeight, lineHeight,
width: `${textElementWidth}px`, width: `${textElementWidth}px`,
height: `${textElementHeight}px`, height: `${textElementHeight}px`,
left: `${viewportX}px`, left: `${viewportX}px`,
top: `${viewportY}px`, top: `${viewportY}px`,
transform: getTransform( transform: `scale(${updatedTextElement.fontSize / fontSize})`,
textElementWidth,
textElementHeight,
getTextElementAngle(updatedTextElement),
appState,
maxWidth,
editorMaxHeight,
),
textAlign, textAlign,
verticalAlign, verticalAlign,
color: updatedTextElement.strokeColor, color: updatedTextElement.strokeColor,