fix text in viewer
This commit is contained in:
@@ -2,14 +2,7 @@ import { useEffect, useLayoutEffect, useRef, useMemo, useState } from "react";
|
||||
import { Text, Group } from "react-konva";
|
||||
import Konva from "konva";
|
||||
import type { TextShapeProps } from "./types";
|
||||
|
||||
const getFontFamily = (fontFamily?: string): string => {
|
||||
const fontMap: Record<string, string> = {
|
||||
"1": "irancell",
|
||||
"2": "irancell",
|
||||
};
|
||||
return fontMap[fontFamily || "1"] || "irancell";
|
||||
};
|
||||
import { getFontFamily } from "@/pages/editor/utils/fontFamily";
|
||||
|
||||
const getFontWeight = (fontWeight?: string): string => {
|
||||
if (!fontWeight) return "normal";
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
const FONT_FAMILY_MAP: Record<string, string> = {
|
||||
"1": "irancell",
|
||||
"2": "irancell",
|
||||
};
|
||||
|
||||
/** Maps editor font option ids to CSS font-family names. */
|
||||
export const getFontFamily = (fontFamily?: string): string => {
|
||||
return FONT_FAMILY_MAP[fontFamily || "1"] || fontFamily || "irancell";
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
/** CSS font-weight values that match irancell @font-face declarations. */
|
||||
export const getCssFontWeight = (fontWeight?: string): number => {
|
||||
if (!fontWeight || fontWeight === "normal") return 300;
|
||||
if (fontWeight === "bold" || fontWeight === "bolder") return 600;
|
||||
|
||||
const n = parseInt(fontWeight, 10);
|
||||
if (!Number.isNaN(n)) {
|
||||
if (n >= 600) return 600;
|
||||
if (n <= 200) return 200;
|
||||
return 300;
|
||||
}
|
||||
|
||||
return 300;
|
||||
};
|
||||
|
||||
export const isSingleLineText = (text?: string): boolean => !text?.includes("\n");
|
||||
|
||||
/** Scaled width for viewer text; adds slack so CSS does not wrap tighter than Konva. */
|
||||
export const getScaledTextWidth = (
|
||||
width: number | undefined,
|
||||
scale: number,
|
||||
singleLine: boolean,
|
||||
): number | undefined => {
|
||||
if (!width) return undefined;
|
||||
const scaled = Math.ceil(width * scale);
|
||||
return singleLine ? scaled + 2 : scaled;
|
||||
};
|
||||
Reference in New Issue
Block a user