Skip to content

Commit

Permalink
更新居中设置
Browse files Browse the repository at this point in the history
  • Loading branch information
more-strive committed Aug 10, 2024
1 parent da95e76 commit 452d66d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/extension/object/VerticalText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,12 @@ export class VerticalText extends IText {
ctx.fillStyle = originalFill;
this._removeShadow(ctx);
}


toSVG(reviver?: TSVGReviver): string {
const imageData = this.toDataURL()
return `<image xlink:href="${imageData}" width="${this.width * this.scaleX}" height="${this.height * this.scaleY}" x="${this.left}" y="${this.top}"/>`
}

getLocalPointer(e: TPointerEvent, pointer?: Point) {
pointer = pointer || this.canvas!.getPointer(e);
let pClicked = new Point(pointer.x, pointer.y)
Expand Down
18 changes: 10 additions & 8 deletions src/hooks/useHandleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default () => {
const handleElement = canvas.getActiveObject()
const templatesStore = useTemplatesStore()
if (!handleElement) return
canvas.discardActiveObject()
if (handleElement.type === ElementNames.ACTIVE) {
const activeObject = handleElement as Group
const activeObjectLeft = activeObject.left - activeObject.width / 2, activeObjectTop = activeObject.top - activeObject.height / 2
Expand Down Expand Up @@ -44,30 +45,31 @@ export default () => {
} else {
switch (command) {
case AlignCommand.LEFT:
handleElement.set({left: left + handleElement.width / 2 })
handleElement.set({left: left })
break
case AlignCommand.RIGHT:
handleElement.set({left: left + width - handleElement.width / 2})
handleElement.set({left: left + width - handleElement.width})
break
case AlignCommand.TOP:
handleElement.set({top: top + handleElement.height / 2 })
handleElement.set({top: top })
break
case AlignCommand.BOTTOM:
handleElement.set({top: top + height - handleElement.height / 2})
handleElement.set({top: top + height - handleElement.height})
break
case AlignCommand.HORIZONTAL:
handleElement.set({left : centerPoint.x})
handleElement.set({left : centerPoint.x - handleElement.width / 2})
break
case AlignCommand.VERTICAL:
handleElement.set({top: centerPoint.y})
handleElement.set({top: centerPoint.y - handleElement.height / 2})
break
case AlignCommand.CENTER:
handleElement.set({left : centerPoint.x})
handleElement.set({top: centerPoint.y})
handleElement.set({left : centerPoint.x - handleElement.width / 2})
handleElement.set({top: centerPoint.y - handleElement.height / 2})
break
default: break
}
}
canvas.setActiveObject(handleElement)
canvas.renderAll()
templatesStore.modifedElement()
}
Expand Down

0 comments on commit 452d66d

Please sign in to comment.