font 변경시 이벤트 수정
This commit is contained in:
parent
8b97fe0b31
commit
63a965d118
@ -112,21 +112,6 @@ export default function Roof2() {
|
|||||||
canvasSizeMode()
|
canvasSizeMode()
|
||||||
}, [verticalSize, horizontalSize])
|
}, [verticalSize, horizontalSize])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
canvas
|
|
||||||
?.getObjects()
|
|
||||||
.filter(
|
|
||||||
(obj) =>
|
|
||||||
obj.type === 'textbox' ||
|
|
||||||
obj.type === 'text' ||
|
|
||||||
obj.type === 'i-text',
|
|
||||||
)
|
|
||||||
.forEach((obj) => {
|
|
||||||
obj.set({ fontSize: fontSize })
|
|
||||||
})
|
|
||||||
canvas?.renderAll()
|
|
||||||
}, [fontSize])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{canvas && (
|
{canvas && (
|
||||||
|
|||||||
@ -61,6 +61,11 @@ export default class QLine extends fabric.Line {
|
|||||||
this.#addLengthText()
|
this.#addLengthText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFontSize(fontSize) {
|
||||||
|
this.#fontSize = fontSize
|
||||||
|
this.#addLengthText()
|
||||||
|
}
|
||||||
|
|
||||||
#addLengthText() {
|
#addLengthText() {
|
||||||
if (this.#text) {
|
if (this.#text) {
|
||||||
this.canvas.remove(this.#text)
|
this.canvas.remove(this.#text)
|
||||||
|
|||||||
@ -99,6 +99,11 @@ export default class QPolygon extends fabric.Polygon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFontSize(fontSize) {
|
||||||
|
this.#fontSize = fontSize
|
||||||
|
this.#addLengthText()
|
||||||
|
}
|
||||||
|
|
||||||
getCurrentPoints() {
|
getCurrentPoints() {
|
||||||
const scaleX = this.scaleX
|
const scaleX = this.scaleX
|
||||||
const scaleY = this.scaleY
|
const scaleY = this.scaleY
|
||||||
|
|||||||
@ -23,6 +23,11 @@ export default class QRect extends fabric.Rect {
|
|||||||
this.#addLengthText()
|
this.#addLengthText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFontSize(fontSize) {
|
||||||
|
this.#fontSize = fontSize
|
||||||
|
this.#addLengthText()
|
||||||
|
}
|
||||||
|
|
||||||
#addControl() {
|
#addControl() {
|
||||||
this.on('removed', () => {
|
this.on('removed', () => {
|
||||||
if (this.#text.length > 0) {
|
if (this.#text.length > 0) {
|
||||||
@ -83,7 +88,7 @@ export default class QRect extends fabric.Rect {
|
|||||||
const text = new fabric.Text(length.toFixed(0), {
|
const text = new fabric.Text(length.toFixed(0), {
|
||||||
left: (line.start.x + line.end.x) / 2,
|
left: (line.start.x + line.end.x) / 2,
|
||||||
top: (line.start.y + line.end.y) / 2,
|
top: (line.start.y + line.end.y) / 2,
|
||||||
fontSize: this.fontSize,
|
fontSize: this.#fontSize,
|
||||||
selectable: false,
|
selectable: false,
|
||||||
})
|
})
|
||||||
this.#text.push(text)
|
this.#text.push(text)
|
||||||
|
|||||||
@ -7,13 +7,14 @@ import {
|
|||||||
} from '@/util/canvas-util'
|
} from '@/util/canvas-util'
|
||||||
|
|
||||||
import { useRecoilState } from 'recoil'
|
import { useRecoilState } from 'recoil'
|
||||||
import { canvasSizeState } from '@/store/canvasAtom'
|
import { canvasSizeState, fontSizeState } from '@/store/canvasAtom'
|
||||||
|
|
||||||
export function useCanvas(id) {
|
export function useCanvas(id) {
|
||||||
const [canvas, setCanvas] = useState()
|
const [canvas, setCanvas] = useState()
|
||||||
const [isLocked, setIsLocked] = useState(false)
|
const [isLocked, setIsLocked] = useState(false)
|
||||||
const [history, setHistory] = useState([])
|
const [history, setHistory] = useState([])
|
||||||
const [canvasSize] = useRecoilState(canvasSizeState)
|
const [canvasSize] = useRecoilState(canvasSizeState)
|
||||||
|
const [fontSize] = useRecoilState(fontSizeState)
|
||||||
const points = useRef([])
|
const points = useRef([])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,6 +47,33 @@ export function useCanvas(id) {
|
|||||||
addEventOnCanvas()
|
addEventOnCanvas()
|
||||||
}, [canvasSize])
|
}, [canvasSize])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
canvas
|
||||||
|
?.getObjects()
|
||||||
|
.filter(
|
||||||
|
(obj) =>
|
||||||
|
obj.type === 'textbox' ||
|
||||||
|
obj.type === 'text' ||
|
||||||
|
obj.type === 'i-text',
|
||||||
|
)
|
||||||
|
.forEach((obj) => {
|
||||||
|
obj.set({ fontSize: fontSize })
|
||||||
|
})
|
||||||
|
|
||||||
|
canvas
|
||||||
|
?.getObjects()
|
||||||
|
.filter(
|
||||||
|
(obj) =>
|
||||||
|
obj.type === 'Qline' ||
|
||||||
|
obj.type === 'QPolygon' ||
|
||||||
|
obj.type === 'QRect',
|
||||||
|
)
|
||||||
|
.forEach((obj) => {
|
||||||
|
obj.setFontSize(fontSize)
|
||||||
|
})
|
||||||
|
canvas?.renderAll()
|
||||||
|
}, [fontSize])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 캔버스 초기화
|
* 캔버스 초기화
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import QLine from '@/components/fabric/QLine'
|
|||||||
import QRect from '@/components/fabric/QRect'
|
import QRect from '@/components/fabric/QRect'
|
||||||
import QPolygon from '@/components/fabric/QPolygon'
|
import QPolygon from '@/components/fabric/QPolygon'
|
||||||
import { getStartIndex, rearrangeArray } from '@/util/canvas-util'
|
import { getStartIndex, rearrangeArray } from '@/util/canvas-util'
|
||||||
|
import { useRecoilState } from 'recoil'
|
||||||
|
import { fontSizeState } from '@/store/canvasAtom'
|
||||||
|
|
||||||
export const Mode = {
|
export const Mode = {
|
||||||
DRAW_LINE: 'drawLine', // 기준선 긋기모드
|
DRAW_LINE: 'drawLine', // 기준선 긋기모드
|
||||||
@ -20,6 +22,7 @@ export function useMode() {
|
|||||||
const historyLines = useRef([])
|
const historyLines = useRef([])
|
||||||
const [canvas, setCanvas] = useState(null)
|
const [canvas, setCanvas] = useState(null)
|
||||||
const [zoom, setZoom] = useState(100)
|
const [zoom, setZoom] = useState(100)
|
||||||
|
const [fontSize] = useRecoilState(fontSizeState)
|
||||||
|
|
||||||
const addEvent = (mode) => {
|
const addEvent = (mode) => {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
@ -153,6 +156,7 @@ export function useMode() {
|
|||||||
selectable: false,
|
selectable: false,
|
||||||
viewLengthText: true,
|
viewLengthText: true,
|
||||||
direction: getDirection(points.current[0], points.current[1]),
|
direction: getDirection(points.current[0], points.current[1]),
|
||||||
|
fontSize: fontSize,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -237,6 +241,7 @@ export function useMode() {
|
|||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
viewLengthText: true,
|
viewLengthText: true,
|
||||||
selectable: false,
|
selectable: false,
|
||||||
|
fontSize: fontSize,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -295,6 +300,7 @@ export function useMode() {
|
|||||||
fill: 'transparent',
|
fill: 'transparent',
|
||||||
stroke: 'black',
|
stroke: 'black',
|
||||||
transparentCorners: false,
|
transparentCorners: false,
|
||||||
|
fontSize: fontSize,
|
||||||
})
|
})
|
||||||
canvas.remove(rect)
|
canvas.remove(rect)
|
||||||
canvas.add(qRect)
|
canvas.add(qRect)
|
||||||
@ -335,6 +341,7 @@ export function useMode() {
|
|||||||
selectable: false,
|
selectable: false,
|
||||||
viewLengthText: true,
|
viewLengthText: true,
|
||||||
direction: getDirection(a, b),
|
direction: getDirection(a, b),
|
||||||
|
fontSize: fontSize,
|
||||||
})
|
})
|
||||||
historyLines.current.push(line)
|
historyLines.current.push(line)
|
||||||
|
|
||||||
@ -365,6 +372,7 @@ export function useMode() {
|
|||||||
fill: 'transparent',
|
fill: 'transparent',
|
||||||
viewLengthText: true,
|
viewLengthText: true,
|
||||||
selectable: true,
|
selectable: true,
|
||||||
|
fontSize: fontSize,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 새로운 다각형 객체를 캔버스에 추가합니다.
|
// 새로운 다각형 객체를 캔버스에 추가합니다.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user