DjDeveloperr / skia_canvas

Fast HTML Canvas API implementation for Deno using Google Skia
https://deno.land/x/skia_canvas
Apache License 2.0
124 stars 7 forks source link

SvgCanvas not generating <svg> close tag #56

Closed ornamentist closed 1 year ago

ornamentist commented 1 year ago

It's probably something I'm doing wrong, but is there something stopping SvgCanvas from writing the closing tag here:

import { SvgCanvas } from "https://deno.land/x/skia_canvas@0.5.2/mod.ts"

const canvas = new SvgCanvas(150, 150)
const ctx = canvas.getContext()

ctx.lineWidth = 2
ctx.strokeRect(10, 10, 120, 120)

canvas.save("./rectangles.svg") 
$ cat rectangles.svg

<?xml version="1.0" encoding="utf-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="150" height="150">
        <rect fill="none" stroke="black" stroke-width="2" stroke-miterlimit="4" x="10" y="10" width="120" height="120"/>

Any advice much appreciated. This is with Deno on macOS.

DjDeveloperr commented 1 year ago

This is a bug in implementation. Sorry for this. Seems like we need to delete SkCanvas object to complete the SVG stream. I'll land a fix for this in some time.

DjDeveloperr commented 1 year ago

From version 0.5.4, you must call canvas.complete before calling canvas.save. It should generate the SVG close tag that way.