fix text in viewer

This commit is contained in:
Hamid
2026-05-16 05:25:28 -07:00
parent 0628340a5d
commit f51c7c302c
5 changed files with 56 additions and 17 deletions
+27
View File
@@ -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;
};