Merge pull request #62 from stanim/fix

Fix pdf bugs and remove gc.Current.Path.Clear()
This commit is contained in:
Stani 2015-07-11 01:25:04 +02:00
commit 6a06be3c7c
6 changed files with 21 additions and 19 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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()
}

View File

@ -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 {