Skip to content

Commit

Permalink
更新text横纵切换
Browse files Browse the repository at this point in the history
  • Loading branch information
more-strive committed Aug 13, 2024
1 parent 38da9a6 commit d36e7c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/extension/object/VerticalText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class VerticalText extends IText {
chars += this._textLines[lineIndex][i];
drawWidth += this.__charBounds[lineIndex][i].width;
}
// const widthFactor = (drawWidth + localLineHeight / this.lineHeight);
const widthFactor = (localLineHeight / this.lineHeight);
const heightFactor = drawWidth / 2 - charBox.height;
drawLeft = drawLeft - widthFactor / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@
<el-row class="mt-10">
<el-button-group class="full-group">
<el-tooltip placement="top" content="横向" :hide-after="0">
<el-button @click="handleElementArrange(false)" :type="!elementGrapheme ? 'primary': ''">
<el-button @click="handleElementArrange(false)" :type="elementGrapheme ? 'primary': ''">
<IconTextRotationNone />
</el-button>
</el-tooltip>
<el-tooltip placement="top" content="纵向" :hide-after="0">
<el-button @click="handleElementArrange(true)" :type="elementGrapheme ? 'primary': ''">
<el-button @click="handleElementArrange(true)" :type="!elementGrapheme ? 'primary': ''">
<IconTextRotationDown />
</el-button>
</el-tooltip>
Expand Down Expand Up @@ -250,7 +250,7 @@ const { canvasObject, systemFonts, onlineFonts } = storeToRefs(mainStore)
const { createPathElement } = useHandleCreate()
const [ canvas ] = useCanvas()
const handleElement = computed(() => canvasObject.value as Textbox | ArcText)
const elementGrapheme = computed(() => handleElement.value.type !== ElementNames.ARCTEXT)
const elementGrapheme = computed(() => handleElement.value.type.toLowerCase() !== ElementNames.VERTICALTEXT)
const elementBackgrounColor = computed(() => {
if (handleElement.value.type.toLowerCase() === ElementNames.ARCTEXT) {
return handleElement.value.textBackgroundColor
Expand Down Expand Up @@ -469,16 +469,21 @@ const changeCharSpacing = (charSpacing: number) => {
const handleElementArrange = (status: boolean) => {
// handleElement.value.set({splitByGrapheme: status, width: handleElement.value.fontSize})
console.log('status:', status)
const options = (handleElement.value as any).toObject(propertiesToInclude as any[])
options.lineHeight = 12
delete options.type
options.id = nanoid(10)
const verticalText = new VerticalText(handleElement.value.text, options)
let textElement = new Textbox(handleElement.value.text, options)
if (status) {
textElement = new VerticalText(handleElement.value.text, options)
}
canvas.remove(canvas.getActiveObject())
canvas.discardActiveObject()
canvas.add(verticalText)
canvas.add(textElement)
templatesStore.modifedElement()
canvas.setActiveObject(verticalText)
canvas.setActiveObject(textElement)
mainStore.setCanvasObject(textElement)
canvas.renderAll()
}
Expand Down

0 comments on commit d36e7c4

Please sign in to comment.