mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
split font into fontSize and fontFamily (#1635)
This commit is contained in:
parent
46b574283f
commit
63c10743fb
17 changed files with 240 additions and 116 deletions
|
@ -14,7 +14,7 @@ import { Drawable, Options } from "roughjs/bin/core";
|
|||
import { RoughSVG } from "roughjs/bin/svg";
|
||||
import { RoughGenerator } from "roughjs/bin/generator";
|
||||
import { SceneState } from "../scene/types";
|
||||
import { SVG_NS, distance } from "../utils";
|
||||
import { SVG_NS, distance, getFontString, getFontFamilyString } from "../utils";
|
||||
import { isPathALoop } from "../math";
|
||||
import rough from "roughjs/bin/rough";
|
||||
|
||||
|
@ -101,7 +101,7 @@ const drawElementOnCanvas = (
|
|||
default: {
|
||||
if (isTextElement(element)) {
|
||||
const font = context.font;
|
||||
context.font = element.font;
|
||||
context.font = getFontString(element);
|
||||
const fillStyle = context.fillStyle;
|
||||
context.fillStyle = element.strokeColor;
|
||||
const textAlign = context.textAlign;
|
||||
|
@ -492,13 +492,6 @@ export const renderElementToSvg = (
|
|||
: element.textAlign === "right"
|
||||
? element.width
|
||||
: 0;
|
||||
const fontSplit = element.font.split(" ").filter((d) => !!d.trim());
|
||||
let fontFamily = fontSplit[0];
|
||||
let fontSize = "20px";
|
||||
if (fontSplit.length > 1) {
|
||||
fontFamily = fontSplit[1];
|
||||
fontSize = fontSplit[0];
|
||||
}
|
||||
const textAnchor =
|
||||
element.textAlign === "center"
|
||||
? "middle"
|
||||
|
@ -510,8 +503,8 @@ export const renderElementToSvg = (
|
|||
text.textContent = lines[i];
|
||||
text.setAttribute("x", `${horizontalOffset}`);
|
||||
text.setAttribute("y", `${(i + 1) * lineHeight - verticalOffset}`);
|
||||
text.setAttribute("font-family", fontFamily);
|
||||
text.setAttribute("font-size", fontSize);
|
||||
text.setAttribute("font-family", getFontFamilyString(element));
|
||||
text.setAttribute("font-size", `${element.fontSize}px`);
|
||||
text.setAttribute("fill", element.strokeColor);
|
||||
text.setAttribute("text-anchor", textAnchor);
|
||||
text.setAttribute("style", "white-space: pre;");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue