Remove svgo dependency

This commit is contained in:
Drahoslav 2017-12-21 15:52:26 +01:00
parent 96883adea4
commit 295a8365b3
2 changed files with 10 additions and 14 deletions

View file

@ -3,22 +3,17 @@ package draw2dsvg
import (
"os"
"bytes"
"errors"
svgo "github.com/ajstarks/svgo/float"
_ "errors"
)
func SaveToSvgFile(filePath string, svg *svgo.SVG) error {
func SaveToSvgFile(filePath string, svg *SVG) error {
f, err := os.Create(filePath)
if err != nil {
return err
}
defer f.Close()
if b, ok := svg.Writer.(*bytes.Buffer); ok {
bytes.NewBuffer(b.Bytes()).WriteTo(f) // clone buffer to make multiple writes possible
} else {
return errors.New("Svg has not been not created from with NewSvg (dow not have byte.Buffer as its Writer)")
}
bytes.NewBuffer((*bytes.Buffer)(svg).Bytes()).WriteTo(f) // clone buffer to make multiple writes possible
return nil
}

View file

@ -9,7 +9,6 @@ import (
"image/color"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dbase"
svgo "github.com/ajstarks/svgo/float"
)
const (
@ -18,18 +17,20 @@ const (
var (
)
func NewSvg() *svgo.SVG {
return svgo.New(&bytes.Buffer{})
type SVG bytes.Buffer
func NewSvg() *SVG {
return &SVG{}
}
// GraphicContext implements the draw2d.GraphicContext interface
// It provides draw2d with a svg backend (based on svgo)
// It provides draw2d with a svg backend
type GraphicContext struct {
*draw2dbase.StackGraphicContext
svg *svgo.SVG
svg *SVG
}
func NewGraphicContext(svg *svgo.SVG) *GraphicContext {
func NewGraphicContext(svg *SVG) *GraphicContext {
gc := &GraphicContext{draw2dbase.NewStackGraphicContext(), svg}
return gc
}