From b71afc04925648d9321209ff8b7ad67eecf3a540 Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Mon, 28 Oct 2024 14:56:51 +0900 Subject: [PATCH] =?UTF-8?q?lengthText=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20?= =?UTF-8?q?=EA=B8=80=EA=BC=B4=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/fabric/QLine.js | 2 +- src/components/fabric/QPolygon.js | 2 +- src/hooks/useCanvasEvent.js | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/fabric/QLine.js b/src/components/fabric/QLine.js index 37c9a75f..4ee9535a 100644 --- a/src/components/fabric/QLine.js +++ b/src/components/fabric/QLine.js @@ -152,7 +152,7 @@ export const QLine = fabric.util.createClass(fabric.Line, { getLength() { //10배 곱해진 값 return - return Number(this.length.toFixed(2) * 10) + return Number(this.length.toFixed(1)) * 10 }, setViewLengthText(bool) { diff --git a/src/components/fabric/QPolygon.js b/src/components/fabric/QPolygon.js index 31076b69..8068a772 100644 --- a/src/components/fabric/QPolygon.js +++ b/src/components/fabric/QPolygon.js @@ -183,7 +183,7 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, { const end = points[(i + 1) % points.length] const dx = end.x - start.x const dy = end.y - start.y - const length = Number(Math.sqrt(dx * dx + dy * dy).toFixed(2)) * 10 + const length = Number(Math.sqrt(dx * dx + dy * dy).toFixed(1)) * 10 let midPoint diff --git a/src/hooks/useCanvasEvent.js b/src/hooks/useCanvasEvent.js index 0df650c0..ab283a08 100644 --- a/src/hooks/useCanvasEvent.js +++ b/src/hooks/useCanvasEvent.js @@ -11,6 +11,7 @@ import { modifiedPlanFlagState, } from '@/store/canvasAtom' import { QPolygon } from '@/components/fabric/QPolygon' +import { fontSelector } from '@/store/fontAtom' // 캔버스에 필요한 이벤트 export function useCanvasEvent() { @@ -22,6 +23,7 @@ export function useCanvasEvent() { const fontFamily = useRecoilValue(fontFamilyState) const [canvasZoom, setCanvasZoom] = useRecoilState(canvasZoomState) const [modifiedPlanFlag, setModifiedPlanFlag] = useRecoilState(modifiedPlanFlagState) + const lengthTextOption = useRecoilValue(fontSelector('lengthText')) // 기본적인 이벤트 필요시 추가 const attachDefaultEventOnCanvas = () => { @@ -108,16 +110,17 @@ export function useCanvasEvent() { }) } - if (target.type.toLowerCase().includes('text')) { - target.set({ fontSize }) - target.set({ fontFamily }) - } - - if (target.name === 'lengthText') { + if (target.name === 'lengthText' && target.type.toLowerCase().includes('text') > 0) { const x = target.left const y = target.top target.lockMovementX = false target.lockMovementY = false + + target.fill = lengthTextOption.fontColor.value + target.fontFamily = lengthTextOption.fontFamily.value + target.fontSize = lengthTextOption.fontSize.value + target.fontWeight = lengthTextOption.fontWeight.value + // Add a property to store the previous value const previousValue = target.text target.on('selected', (e) => {