[fix] text export placement (#1066)

* Fix text export placement

* remove console.log

* Update getTextSvgElement.ts
This commit is contained in:
Steve Ruiz 2022-12-03 13:48:56 +00:00 committed by GitHub
parent da0d617f0c
commit cfa7f6e357
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -398,7 +398,7 @@ export class TextUtil extends TDShapeUtil<T, E> {
const fontSize = getFontSize(shape.style.size, shape.style.font) * (shape.style.scale ?? 1) const fontSize = getFontSize(shape.style.size, shape.style.font) * (shape.style.scale ?? 1)
const fontFamily = getFontFace(shape.style.font).slice(1, -1) const fontFamily = getFontFace(shape.style.font).slice(1, -1)
const textAlign = shape.style.textAlign ?? AlignStyle.Start const textAlign = shape.style.textAlign ?? AlignStyle.Middle
const textElm = getTextSvgElement( const textElm = getTextSvgElement(
shape.text, shape.text,

View file

@ -58,19 +58,19 @@ export function getTextSvgElement(
case AlignStyle.Middle: { case AlignStyle.Middle: {
textElm.setAttribute('text-align', 'center') textElm.setAttribute('text-align', 'center')
textElm.setAttribute('text-anchor', 'middle') textElm.setAttribute('text-anchor', 'middle')
textLines.forEach((textElm) => textElm.setAttribute('x', 4 + width / 2 + '')) textLines.forEach((textElm) => textElm.setAttribute('x', width / 2 + ''))
break break
} }
case AlignStyle.End: { case AlignStyle.End: {
textElm.setAttribute('text-align', 'right') textElm.setAttribute('text-align', 'right')
textElm.setAttribute('text-anchor', 'end') textElm.setAttribute('text-anchor', 'end')
textLines.forEach((textElm) => textElm.setAttribute('x', 4 + width + '')) textLines.forEach((textElm) => textElm.setAttribute('x', -4 + width + ''))
break break
} }
default: { default: {
textElm.setAttribute('text-align', 'left') textElm.setAttribute('text-align', 'left')
textElm.setAttribute('text-anchor', 'start') textElm.setAttribute('text-anchor', 'start')
textLines.forEach((textElm) => textElm.setAttribute('x', '4')) textLines.forEach((textElm) => textElm.setAttribute('x', 4 + ''))
} }
} }