diff --git a/src/pages/viewer/components/BookPage.tsx b/src/pages/viewer/components/BookPage.tsx index dd0e53f..ccde0cb 100644 --- a/src/pages/viewer/components/BookPage.tsx +++ b/src/pages/viewer/components/BookPage.tsx @@ -169,31 +169,61 @@ const BookPage = forwardRef(({ page, scale = 1 }, if (obj.shapeType === 'triangle') { // در editor، triangle با مرکز در x + width/2, y + height/2 رندر می‌شود - const width = (obj.width || 100) * scale; - const height = (obj.height || 100) * scale; - const radius = Math.min(width, height) / 2; - const centerX = (obj.x || 0) * scale + width / 2; - const centerY = (obj.y || 0) * scale + height / 2; + // RegularPolygon در Konva یک مثلث متساوی‌الاضلاع است با radius از مرکز تا رأس + // radius باید بر اساس ابعاد اصلی (قبل از scale) محاسبه شود + const baseWidth = obj.width || 100; + const baseHeight = obj.height || 100; + const baseRadius = Math.min(baseWidth, baseHeight) / 2; + const radius = baseRadius * scale; + + // محاسبه مرکز مثلث (مثل editor) + const centerX = ((obj.x || 0) + baseWidth / 2) * scale; + const centerY = ((obj.y || 0) + baseHeight / 2) * scale; + + // برای مثلث متساوی‌الاضلاع، size = radius * 2 + const size = radius * 2; + const halfSize = size / 2; + + // نقاط مثلث متساوی‌الاضلاع: رأس بالا (50%, 0%), پایین چپ (0%, 100%), پایین راست (100%, 100%) + // اما برای مثلث متساوی‌الاضلاع واقعی، باید ارتفاع را محاسبه کنیم + // ارتفاع مثلث متساوی‌الاضلاع = size * sqrt(3) / 2 ≈ size * 0.866 + const triangleHeight = size * 0.8660254; // sqrt(3) / 2 + const topY = (size - triangleHeight) / 2; + const bottomY = size - topY; + const halfWidth = triangleHeight * 0.5773503; // tan(30°) = 1/sqrt(3) + + const topX = halfSize; + const bottomLeftX = halfSize - halfWidth; + const bottomRightX = halfSize + halfWidth; + + const strokeWidth = obj.stroke ? (obj.strokeWidth || 1) * scale : 0; + const fillColor = obj.fill || '#000000'; + const strokeColor = obj.stroke || 'transparent'; return ( -
+ viewBox={`0 0 ${size} ${size}`} + > + + ); }