From 5d1b0f33156420d118496f25fe34c41ad08ae489 Mon Sep 17 00:00:00 2001 From: Stani Date: Sat, 27 Jun 2015 16:47:27 +0200 Subject: [PATCH] added an example as documentation and test --- pdf2d/graphiccontext_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pdf2d/graphiccontext_test.go diff --git a/pdf2d/graphiccontext_test.go b/pdf2d/graphiccontext_test.go new file mode 100644 index 0000000..09a8cba --- /dev/null +++ b/pdf2d/graphiccontext_test.go @@ -0,0 +1,35 @@ +package pdf2d + +import ( + "fmt" + "image/color" + + "github.com/stanim/draw2d" + "github.com/stanim/gofpdf" +) + +func ExampleGraphicContext() { + // Initialize the graphic context on a pdf document + pdf := gofpdf.New("P", "mm", "A4", "../font") + pdf.AddPage() + gc := NewGraphicContext(pdf) + + // some properties + gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff}) + gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff}) + gc.SetLineCap(draw2d.RoundCap) + gc.SetLineWidth(5) + + // draw something + gc.MoveTo(10, 10) // should always be called for a new path + gc.LineTo(100, 50) + gc.QuadCurveTo(100, 10, 10, 10) + gc.Close() + gc.FillStroke() + fmt.Println(gc.LastPoint()) + + // pdf2d.SaveToPdfFile("example.pdf", pdf) + + // Output: + // 10 10 +}