set text line height

This commit is contained in:
hamid zarghami
2026-05-06 09:22:06 +03:30
parent 793ae82914
commit 5de205a84f
5 changed files with 35 additions and 1 deletions
@@ -70,6 +70,7 @@ export const useDrawingHandlers = () => {
y: realPos.y,
text: "متن جدید",
fontSize: defaults.fontSize,
lineHeight: 1.2,
fontFamily: defaults.fontFamily,
fontWeight: defaults.fontWeight,
fill: defaults.fill,
@@ -2,6 +2,7 @@ import { Trash } from "iconsax-react";
import type { EditorObject } from "../../store/editorStore";
import {
ShapeSettings,
TextSettings,
LineSettings,
SizeSettings,
LinkSettings,
@@ -50,6 +51,9 @@ const ObjectSettings = ({
<MaskSettings objectId={selectedObject.id} />
{selectedObject.type === "text" && <TextInstruction />}
{selectedObject.type === "text" && (
<TextSettings selectedObject={selectedObject} onUpdate={onUpdate} />
)}
{selectedObject.type === "rectangle" && (
<ShapeSettings selectedObject={selectedObject} onUpdate={onUpdate} />
@@ -7,6 +7,19 @@ type TextSettingsProps = {
onUpdate: (id: string, updates: Partial<EditorObject>) => void;
};
const normalizeNumericInput = (value: string): string => {
const persianDigits = "۰۱۲۳۴۵۶۷۸۹";
const arabicDigits = "٠١٢٣٤٥٦٧٨٩";
return value
.replace(/[۰-۹]/g, (d) => String(persianDigits.indexOf(d)))
.replace(/[٠-٩]/g, (d) => String(arabicDigits.indexOf(d)))
.replace("٫", ".")
.replace(",", ".");
};
const parseNumber = (value: string): number => Number(normalizeNumericInput(value));
const TextSettings = ({ selectedObject, onUpdate }: TextSettingsProps) => {
return (
<>
@@ -19,9 +32,22 @@ const TextSettings = ({ selectedObject, onUpdate }: TextSettingsProps) => {
label="اندازه فونت"
type="number"
value={selectedObject.fontSize || 24}
step="1"
onChange={(e) =>
onUpdate(selectedObject.id, {
fontSize: parseInt(e.target.value) || 24,
fontSize: parseNumber(e.target.value) || 24,
})
}
/>
<Input
label="فاصله خطوط"
type="number"
value={selectedObject.lineHeight ?? 1.2}
step="0.1"
min="0.5"
onChange={(e) =>
onUpdate(selectedObject.id, {
lineHeight: parseNumber(e.target.value) || 1.2,
})
}
/>
@@ -147,6 +147,7 @@ const TextShape = ({
obj.fontFamily,
obj.fontWeight,
obj.letterSpacing,
obj.lineHeight,
obj.width,
obj.height,
onUpdate,
@@ -313,6 +314,7 @@ const TextShape = ({
fontFamily={fontFamily}
fontStyle={konvaFontStyle}
letterSpacing={obj.letterSpacing ?? 0}
lineHeight={obj.lineHeight ?? 1.2}
align="right"
/>
</Group>
@@ -45,6 +45,7 @@ export type EditorObject = {
strokeWidth?: number;
text?: string;
fontSize?: number;
lineHeight?: number;
fontFamily?: string;
fontWeight?: string;
letterSpacing?: number;