From 295a8365b3ca762bf86e98737c07dc35967bc463 Mon Sep 17 00:00:00 2001 From: Drahoslav Date: Thu, 21 Dec 2017 15:52:26 +0100 Subject: [PATCH] Remove svgo dependency --- draw2dsvg/fileutil.go | 11 +++-------- draw2dsvg/gc.go | 13 +++++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/draw2dsvg/fileutil.go b/draw2dsvg/fileutil.go index e243b62..e864c83 100644 --- a/draw2dsvg/fileutil.go +++ b/draw2dsvg/fileutil.go @@ -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 } \ No newline at end of file diff --git a/draw2dsvg/gc.go b/draw2dsvg/gc.go index ffcb4b7..c3596d8 100644 --- a/draw2dsvg/gc.go +++ b/draw2dsvg/gc.go @@ -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 }