fix text location

This commit is contained in:
hamid zarghami
2026-05-06 15:06:55 +03:30
parent 8717afbced
commit ae7eae34d9
2 changed files with 12 additions and 1 deletions
+8 -1
View File
@@ -74,17 +74,24 @@ const BookPage = forwardRef<HTMLDivElement, BookPageProps>(
// برای text، opacity در رنگ اعمال می‌شود، پس باید opacity را از baseStyle حذف کنیم // برای text، opacity در رنگ اعمال می‌شود، پس باید opacity را از baseStyle حذف کنیم
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { opacity, ...textBaseStyle } = baseStyle; const { opacity, ...textBaseStyle } = baseStyle;
const textWidth = obj.width ? obj.width * scale : undefined;
const textLeft = ((obj.x || 0) - (obj.width || 0)) * scale;
return ( return (
<div <div
key={obj.id || index} key={obj.id || index}
style={{ style={{
...textBaseStyle, ...textBaseStyle,
left: `${textLeft}px`,
width: textWidth ? `${textWidth}px` : undefined,
fontSize: `${(obj.fontSize || 16) * scale}px`, fontSize: `${(obj.fontSize || 16) * scale}px`,
fontFamily: obj.fontFamily || 'irancell, sans-serif', fontFamily: obj.fontFamily || 'irancell, sans-serif',
fontWeight: obj.fontWeight || 'normal', fontWeight: obj.fontWeight || 'normal',
lineHeight: 1, lineHeight: obj.lineHeight ?? 1.2,
textAlign: obj.textAlign ?? 'right',
direction: 'rtl',
color: getColorWithOpacity(obj.fill, obj.opacity), color: getColorWithOpacity(obj.fill, obj.opacity),
whiteSpace: 'pre-wrap', whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
letterSpacing: obj.letterSpacing ? `${obj.letterSpacing * scale}px` : undefined, letterSpacing: obj.letterSpacing ? `${obj.letterSpacing * scale}px` : undefined,
}} }}
> >
@@ -15,6 +15,8 @@ type ViewerDataPage = {
fontSize?: number; fontSize?: number;
fontFamily?: string; fontFamily?: string;
fontWeight?: string; fontWeight?: string;
lineHeight?: number;
textAlign?: "left" | "center" | "right";
fill?: string; fill?: string;
stroke?: string; stroke?: string;
strokeWidth?: number; strokeWidth?: number;
@@ -89,6 +91,8 @@ export function transformViewerDataToPages(data: ViewerData): PageData[] {
if (obj.fontWeight !== undefined) baseObject.fontWeight = obj.fontWeight; if (obj.fontWeight !== undefined) baseObject.fontWeight = obj.fontWeight;
if (obj.letterSpacing !== undefined) if (obj.letterSpacing !== undefined)
baseObject.letterSpacing = obj.letterSpacing; baseObject.letterSpacing = obj.letterSpacing;
if (obj.lineHeight !== undefined) baseObject.lineHeight = obj.lineHeight;
if (obj.textAlign !== undefined) baseObject.textAlign = obj.textAlign;
// انواع خاص objectها // انواع خاص objectها
if (obj.type === "rectangle" && obj.shapeType) { if (obj.type === "rectangle" && obj.shapeType) {