diff --git a/draw2dgl/gc.go b/draw2dgl/gc.go index 2833dcc..66e25cb 100644 --- a/draw2dgl/gc.go +++ b/draw2dgl/gc.go @@ -199,7 +199,7 @@ func (gc *GraphicContext) Stroke(paths ...*draw2d.PathStorage) { pathConverter.Convert(paths...) gc.paint(gc.strokeRasterizer, gc.Current.StrokeColor) - gc.Current.Path.Clear() + gc.Current.Path = draw2d.NewPathStorage() } func (gc *GraphicContext) Fill(paths ...*draw2d.PathStorage) { @@ -211,7 +211,7 @@ func (gc *GraphicContext) Fill(paths ...*draw2d.PathStorage) { pathConverter.Convert(paths...) gc.paint(gc.fillRasterizer, gc.Current.FillColor) - gc.Current.Path.Clear() + gc.Current.Path = draw2d.NewPathStorage() } func (gc *GraphicContext) FillStroke(paths ...*draw2d.PathStorage) { diff --git a/draw2dpdf/gc.go b/draw2dpdf/gc.go index 50a7137..fd9563a 100644 --- a/draw2dpdf/gc.go +++ b/draw2dpdf/gc.go @@ -44,8 +44,13 @@ var ( // a page and set fill color to white. func NewPdf(orientationStr, unitStr, sizeStr string) *gofpdf.Fpdf { pdf := gofpdf.New(orientationStr, unitStr, sizeStr, draw2d.GetFontFolder()) + // to be compatible with draw2d + pdf.SetDrawColor(0, 0, 0) + pdf.SetFillColor(255, 255, 255) + pdf.SetLineCapStyle("round") + pdf.SetLineJoinStyle("round") + pdf.SetLineWidth(1) pdf.AddPage() - pdf.SetFillColor(255, 255, 255) // to be compatible with draw2d return pdf } @@ -176,12 +181,20 @@ func (gc *GraphicContext) Stroke(paths ...*draw2d.PathStorage) { // Fill fills the paths with the color specified by SetFillColor func (gc *GraphicContext) Fill(paths ...*draw2d.PathStorage) { - gc.draw("F", paths...) + style := "F" + if !gc.Current.FillRule.UseNonZeroWinding() { + style += "*" + } + gc.draw(style, paths...) } // FillStroke first fills the paths and than strokes them func (gc *GraphicContext) FillStroke(paths ...*draw2d.PathStorage) { - gc.draw("FD", paths...) + style := "FD" + if !gc.Current.FillRule.UseNonZeroWinding() { + style += "*" + } + gc.draw(style, paths...) } var logger = log.New(os.Stdout, "", log.Lshortfile) @@ -190,12 +203,9 @@ var logger = log.New(os.Stdout, "", log.Lshortfile) func (gc *GraphicContext) draw(style string, paths ...*draw2d.PathStorage) { paths = append(paths, gc.Current.Path) pathConverter := NewPathConverter(gc.pdf) - // pathConverter := NewPathConverter(NewPathLogger(logger, gc.pdf)) pathConverter.Convert(paths...) - if gc.Current.FillRule.UseNonZeroWinding() { - style += "*" - } gc.pdf.DrawPath(style) + gc.Current.Path = draw2d.NewPathStorage() } // overwrite StackGraphicContext methods diff --git a/image.go b/image.go index bc4d403..8e5fa72 100644 --- a/image.go +++ b/image.go @@ -269,7 +269,7 @@ func (gc *ImageGraphicContext) paint(rasterizer *raster.Rasterizer, color color. gc.painter.SetColor(color) rasterizer.Rasterize(gc.painter) rasterizer.Clear() - gc.Current.Path.Clear() + gc.Current.Path = NewPathStorage() } // Stroke strokes the paths with the color specified by SetStrokeColor diff --git a/path_storage.go b/path_storage.go index a7e1662..b19ea3d 100644 --- a/path_storage.go +++ b/path_storage.go @@ -32,12 +32,6 @@ func NewPathStorage() (p *PathStorage) { return } -func (p *PathStorage) Clear() { - p.Commands = p.Commands[0:0] - p.Vertices = p.Vertices[0:0] - return -} - func (p *PathStorage) appendToPath(cmd PathCmd, Vertices ...float64) { if cap(p.Vertices) <= len(p.Vertices)+6 { a := make([]PathCmd, len(p.Commands), cap(p.Commands)+256) diff --git a/samples/linecapjoin/linecapjoin.go b/samples/linecapjoin/linecapjoin.go index 6acf659..81d78f0 100644 --- a/samples/linecapjoin/linecapjoin.go +++ b/samples/linecapjoin/linecapjoin.go @@ -31,7 +31,6 @@ func Main(gc draw2d.GraphicContext, ext string) (string, error) { // Draw a line with an angle with specified line cap and join func Draw(gc draw2d.GraphicContext, cap draw2d.Cap, join draw2d.Join, x0, y0, x1, y1, offset float64) { - gc.Save() // pdf: save & restore needed to isolate caps and joins gc.SetLineCap(cap) gc.SetLineJoin(join) @@ -50,5 +49,4 @@ func Draw(gc draw2d.GraphicContext, cap draw2d.Cap, join draw2d.Join, gc.LineTo((x0+x1)/2+offset, (y0+y1)/2) gc.LineTo(x1, y1) gc.Stroke() - gc.Restore() } diff --git a/stack_gc.go b/stack_gc.go index c1ac309..1e09e8f 100644 --- a/stack_gc.go +++ b/stack_gc.go @@ -125,7 +125,7 @@ func (gc *StackGraphicContext) GetFontData() FontData { } func (gc *StackGraphicContext) BeginPath() { - gc.Current.Path.Clear() + gc.Current.Path = NewPathStorage() } func (gc *StackGraphicContext) IsEmpty() bool {