Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to convert the circle #24

Open
ZiluoLiu-LXKJ opened this issue Sep 23, 2022 · 0 comments
Open

failed to convert the circle #24

ZiluoLiu-LXKJ opened this issue Sep 23, 2022 · 0 comments

Comments

@ZiluoLiu-LXKJ
Copy link

I tried to convert Canvas to SVG, but failed to convert circles. Circles do not appear in the new SVG.

Here is the API I wrote to implement the transformation:

`import {Context} from 'svgcanvas'
handle_saveSvg() {
let width = this.canvas.canvas.width
let height = this.canvas.canvas.height
console.log(width,height,"rect")
// let C2S = window.C2S
let ctx = new Context(width + 500, height + 500)
console.log(ctx, "ctx")
for (let pen of this.canvas.store.data.pens) {
console.log(pen, "pen")
if (pen.type) {
let line = pen
line.from = {}
line.to = {}
}
this.canvas.renderPenRaw(ctx, pen)
}
console.log(ctx, "ctx1")

  let mySerializedSVG = ctx.getSerializedSvg()
  console.log(mySerializedSVG, "svg")
  mySerializedSVG = mySerializedSVG.replace(
    "<defs/>",
    `<defs>
<style type="text/css"> @font-face { font-family: 'topology'; src: url('https://at.alicdn.com/t/font_1331132_h688rvffmbc.ttf') format('truetype'); } @font-face { font-family: 'ltee'; src: url('https://at.alicdn.com/t/font_2052340_ceohsubmal7.ttf') format('truetype'); } @font-face { font-family: 'ltdx'; src: url('https://at.alicdn.com/t/font_2073009_5ilnjxypv6l.ttf') format('truetype'); } @font-face { font-family: 'ticon'; src: url('https://at.alicdn.com/t/font_1331132_g7tv7fmj6c9.ttf') format('truetype'); } </style>

`
)
mySerializedSVG = mySerializedSVG.replace(/--le5le--/g, '&#x')

  const urlObject = window.URL || window
  const export_blob = new Blob([mySerializedSVG])
  const url = urlObject.createObjectURL(export_blob)

  const a = document.createElement('a')
  let name = sessionStorage.getItem("areaName")
  a.setAttribute('download', name + '.svg')
  a.setAttribute('href', url)
  const evt = document.createEvent('MouseEvents')
  evt.initEvent('click', true, true)
  a.dispatchEvent(evt)
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant