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 ( import (
"os" "os"
"bytes" "bytes"
"errors" _ "errors"
svgo "github.com/ajstarks/svgo/float"
) )
func SaveToSvgFile(filePath string, svg *svgo.SVG) error { func SaveToSvgFile(filePath string, svg *SVG) error {
f, err := os.Create(filePath) f, err := os.Create(filePath)
if err != nil { if err != nil {
return err return err
} }
defer f.Close() defer f.Close()
if b, ok := svg.Writer.(*bytes.Buffer); ok { bytes.NewBuffer((*bytes.Buffer)(svg).Bytes()).WriteTo(f) // clone buffer to make multiple writes possible
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)")
}
return nil return nil
} }

View File

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