@@ -25,6 +25,7 @@ const Canvas = React.forwardRef(({ canvasState }: CanvasProps, ref: any) => {
2525 fontColor,
2626 strokeColor,
2727 } = canvasState ;
28+
2829 const {
2930 dragAndDropTextData,
3031 handleCanvasMouseDown,
@@ -45,15 +46,15 @@ const Canvas = React.forwardRef(({ canvasState }: CanvasProps, ref: any) => {
4546 return strokeObj [ fontStrokeType ] ;
4647 } , [ fontStrokeType ] ) ;
4748
48- const getCenterX = useCallback (
49- ( lineMaxWidth : number ) => {
49+ const getCalculatedX = useCallback (
50+ ( originWidth : number , lineMaxWidth : number ) => {
5051 switch ( textAlign ) {
5152 case 'center' :
52- return + canvasWidth / 2 ;
53+ return originWidth ;
5354 case 'end' :
54- return + canvasWidth / 2 + lineMaxWidth / 2 ;
55+ return originWidth + lineMaxWidth / 2 ;
5556 default :
56- return + canvasWidth / 2 + ( lineMaxWidth / 2 ) * - 1 ;
57+ return originWidth + ( lineMaxWidth / 2 ) * - 1 ;
5758 }
5859 } ,
5960 [ textAlign , canvasWidth ]
@@ -68,16 +69,16 @@ const Canvas = React.forwardRef(({ canvasState }: CanvasProps, ref: any) => {
6869 ) => {
6970 const { offsetX, offsetY } = dragAndDropTextData ;
7071 const centerY = + canvasHeight / 2 ;
71- const centerX = getCenterX ( lineMaxWidth ) ;
72+ const centerX = getCalculatedX ( + canvasWidth / 2 , lineMaxWidth ) ;
7273
73- const x = offsetX ? offsetX : centerX ;
74+ const x = offsetX ? getCalculatedX ( offsetX , lineMaxWidth ) : centerX ;
7475 const y = offsetY
7576 ? offsetY - ( ( linesLength - 1 ) * lineHeight ) / 2 + idx * lineHeight
7677 : centerY - ( ( linesLength - 1 ) * lineHeight ) / 2 + idx * lineHeight ;
7778
7879 return { x, y } ;
7980 } ,
80- [ dragAndDropTextData , canvasHeight , getCenterX ]
81+ [ dragAndDropTextData , canvasHeight , getCalculatedX ]
8182 ) ;
8283
8384 const setFontStroke = useCallback (
0 commit comments