폰트 셋팅 및 uuid 추가

This commit is contained in:
hyojun.choi 2024-10-23 17:01:06 +09:00
parent 914bf93197
commit 0de81807bd
9 changed files with 101 additions and 44 deletions

View File

@ -1,8 +1,10 @@
import WithDraggable from '@/components/common/draggable/WithDraggable' import WithDraggable from '@/components/common/draggable/WithDraggable'
import QSelectBox from '@/components/common/select/QSelectBox' import QSelectBox from '@/components/common/select/QSelectBox'
import { usePopup } from '@/hooks/usePopup' import { usePopup } from '@/hooks/usePopup'
import { useState } from 'react' import { useEffect, useState } from 'react'
import { useMessage } from '@/hooks/useMessage' import { useMessage } from '@/hooks/useMessage'
import { useRecoilState, useRecoilValue } from 'recoil'
import { fontSelector, globalFontAtom } from '@/store/fontAtom'
const fonts = [ const fonts = [
{ name: 'MS PGothic', value: 'MS PGothic' }, { name: 'MS PGothic', value: 'MS PGothic' },
@ -43,19 +45,38 @@ const fontColors = [
{ name: '남색', value: 'darkblue' }, { name: '남색', value: 'darkblue' },
] ]
export default function FontSetting(props) { export default function FontSetting(props) {
const { id, setIsShow, font, setFont, fontSize, setFontSize, pos = { x: 455, y: 180 } } = props const { id, setIsShow, pos = { x: 455, y: 180 }, type } = props
const { getMessage } = useMessage() const { getMessage } = useMessage()
const { closePopup } = usePopup() const { closePopup } = usePopup()
const [originFont, setOriginFont] = useState(font) const [globalFont, setGlobalFont] = useRecoilState(globalFontAtom)
const [originFontSize, setOriginFontSize] = useState(fontSize) const currentFont = useRecoilValue(fontSelector(type))
const [selectedFont, setSelectedFont] = useState(font ? font : fonts[0])
const [selectedFontSize, setSelectedFontSize] = useState(fontSize ? fontSize : fontSizes[0]) const [selectedFont, setSelectedFont] = useState(currentFont.fontFamily)
const [selectedFontColor, setSelectedFontColor] = useState(null) const [selectedFontWeight, setSelectedFontWeight] = useState(currentFont.fontWeight)
const [selectedFontSize, setSelectedFontSize] = useState(currentFont.fontSize)
const [selectedFontColor, setSelectedFontColor] = useState(currentFont.fontColor)
const handleSaveBtn = () => {
setGlobalFont((prev) => {
return {
...prev,
[type]: {
fontFamily: selectedFont,
fontSize: selectedFontSize,
fontColor: selectedFontColor,
fontWeight: selectedFontWeight,
},
}
})
setIsShow(false)
closePopup(id)
}
return ( return (
<WithDraggable isShow={true} pos={pos}> <WithDraggable isShow={true} pos={pos}>
<div className={`modal-pop-wrap lrr mount`}> <div className={`modal-pop-wrap lrr mount`}>
<div className="modal-head"> <div className="modal-head">
<h1 className="title">{getMessage('modal.font')} </h1> <h1 className="title">{getMessage('modal.font')}</h1>
<button <button
className="modal-close" className="modal-close"
onClick={() => { onClick={() => {
@ -78,7 +99,7 @@ export default function FontSetting(props) {
<div className="font-option-item"> <div className="font-option-item">
<div className="option-item-tit">{getMessage('modal.font.style')}(Y)</div> <div className="option-item-tit">{getMessage('modal.font.style')}(Y)</div>
<div className="grid-select"> <div className="grid-select">
<QSelectBox options={fontOptions} onChange={(e) => setSelectedFont(e)} /> <QSelectBox options={fontOptions} value={selectedFontWeight} onChange={(e) => setSelectedFontWeight(e)} />
</div> </div>
</div> </div>
<div className="font-option-item"> <div className="font-option-item">
@ -112,15 +133,7 @@ export default function FontSetting(props) {
<div className="normal-font">{getMessage('modal.font.setting.info')}</div> <div className="normal-font">{getMessage('modal.font.setting.info')}</div>
</div> </div>
<div className="grid-btn-wrap"> <div className="grid-btn-wrap">
<button <button className="btn-frame modal act" onClick={handleSaveBtn}>
className="btn-frame modal act"
onClick={() => {
setIsShow(false)
setFont(selectedFont)
setFontSize(selectedFontSize)
closePopup(id)
}}
>
{getMessage('modal.common.save')} {getMessage('modal.common.save')}
</button> </button>
</div> </div>

View File

@ -57,11 +57,10 @@ export const QLine = fabric.util.createClass(fabric.Line, {
}) })
this.on('removed', () => { this.on('removed', () => {
const thisText = this.canvas.getObjects().find((obj) => obj.name === 'lengthText' && obj.parentId === this.id) const children = this.canvas.getObjects().filter((obj) => obj.parentId === this.id)
if (thisText) { children.forEach((child) => {
this.canvas.remove(thisText) this.canvas.remove(child)
} })
this.text = null
}) })
}, },

View File

@ -132,22 +132,10 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
}) })
this.on('removed', () => { this.on('removed', () => {
const thisText = this.canvas.getObjects().filter((obj) => obj.name === 'lengthText' && obj.parentId === this.id) const children = this.canvas.getObjects().filter((obj) => obj.parentId === this.id)
thisText.forEach((text) => { children.forEach((child) => {
this.canvas.remove(text) this.canvas.remove(child)
}) })
this.texts = null
if (this.arrow) {
this.canvas.remove(this.arrow)
this.canvas
.getObjects()
.filter((obj) => obj.name === 'directionText' && obj.parent === this.arrow)
.forEach((text) => {
this.canvas.remove(text)
})
this.arrow = null
}
}) })
// polygon.fillCell({ width: 50, height: 30, padding: 10 }) // polygon.fillCell({ width: 50, height: 30, padding: 10 })

View File

@ -203,12 +203,34 @@ export default function SecondOption() {
} }
break break
case 'font1': // case 'font1': {
case 'font2': // //
case 'font3': // setShowFontSettingModal(true)
fontProps.type = 'commonText'
fontProps.id = fontId + 1
addPopup(fontId + 1, 2, <FontSetting {...fontProps} />)
break
}
case 'font2': {
//
setShowFontSettingModal(true)
fontProps.type = 'flowText'
fontProps.id = fontId + 2
addPopup(fontId + 2, 2, <FontSetting {...fontProps} />)
break
}
case 'font3': {
//
setShowFontSettingModal(true)
fontProps.type = 'lengthText'
fontProps.id = fontId + 3
addPopup(fontId + 3, 2, <FontSetting {...fontProps} />)
break
}
case 'font4': // case 'font4': //
setShowFontSettingModal(true) setShowFontSettingModal(true)
fontProps.type = 'circuitNumberText'
fontProps.id = fontId
addPopup(fontId, 2, <FontSetting {...fontProps} />) addPopup(fontId, 2, <FontSetting {...fontProps} />)
break break
case 'planSize': case 'planSize':

View File

@ -92,6 +92,7 @@ export default function DimensionLineSetting(props) {
x: 455, x: 455,
y: 180, y: 180,
}, },
type: 'dimensionLineText',
} }
const popupHandle = (type) => { const popupHandle = (type) => {
switch (type) { switch (type) {

View File

@ -241,7 +241,8 @@ export function useAuxiliaryDrawing(id) {
const x = lastPoint.x + length * Math.cos(radian) const x = lastPoint.x + length * Math.cos(radian)
const y = lastPoint.y - length * Math.sin(radian) const y = lastPoint.y - length * Math.sin(radian)
return [...prev, { x, y }] mousePointerArr.current.push({ x, y })
drawLine()
} }
} }
}, },

View File

@ -92,6 +92,7 @@ export function useCanvas(id) {
// settings for all canvas in the app // settings for all canvas in the app
fabric.Object.prototype.transparentCorners = false fabric.Object.prototype.transparentCorners = false
fabric.Object.prototype.id = uuidv4() fabric.Object.prototype.id = uuidv4()
fabric.Object.prototype.uuid = uuidv4()
fabric.Object.prototype.selectable = true fabric.Object.prototype.selectable = true
fabric.Object.prototype.lockMovementX = true fabric.Object.prototype.lockMovementX = true
fabric.Object.prototype.lockMovementY = true fabric.Object.prototype.lockMovementY = true

View File

@ -190,7 +190,7 @@ export const usePolygon = () => {
break break
} }
arrow = new fabric.Polygon(points, { arrow = new QPolygon(points, {
selectable: false, selectable: false,
name: 'arrow', name: 'arrow',
fill: 'transparent', fill: 'transparent',
@ -200,8 +200,10 @@ export const usePolygon = () => {
stickeyPoint: stickeyPoint, stickeyPoint: stickeyPoint,
visible: isFlowDisplay, visible: isFlowDisplay,
pitch: polygon.pitch, pitch: polygon.pitch,
parentId: polygon.id,
}) })
arrow.setViewLengthText(false)
polygon.arrow = arrow polygon.arrow = arrow
polygon.canvas.add(arrow) polygon.canvas.add(arrow)
polygon.canvas.renderAll() polygon.canvas.renderAll()
@ -410,6 +412,7 @@ export const usePolygon = () => {
left: arrow.stickeyPoint.x, left: arrow.stickeyPoint.x,
top: arrow.stickeyPoint.y, top: arrow.stickeyPoint.y,
parent: arrow, parent: arrow,
parentId: arrow.id,
visible: isFlowDisplay, visible: isFlowDisplay,
}) })
canvas.add(text) canvas.add(text)

29
src/store/fontAtom.js Normal file
View File

@ -0,0 +1,29 @@
import { atom, selectorFamily } from 'recoil'
const defaultFont = {
fontFamily: { name: 'MS PGothic', value: 'MS PGothic' },
fontWeight: { name: '보통', value: 'normal' },
fontSize: { name: '16', value: '16' },
fontColor: { name: '검정색', value: 'black' },
}
export const globalFontAtom = atom({
key: 'fontAtom',
default: {
commonText: defaultFont,
dimensionLineText: defaultFont,
flowText: defaultFont,
lengthText: defaultFont,
circuitNumberText: defaultFont,
},
})
export const fontSelector = selectorFamily({
key: 'fontSelector',
get:
(type) =>
({ get }) => {
const fontAtom = get(globalFontAtom)
return fontAtom[type]
},
})