2015-07-06 22:25:24 +00:00
|
|
|
package draw2dpdf
|
2015-06-27 14:47:27 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"image/color"
|
|
|
|
|
2015-07-06 22:07:44 +00:00
|
|
|
"github.com/llgcode/draw2d"
|
|
|
|
"github.com/jung-kurt/gofpdf"
|
2015-06-27 14:47:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2015-06-27 15:18:36 +00:00
|
|
|
gc.MoveTo(10, 10) // should always be called first for a new path
|
2015-06-27 14:47:27 +00:00
|
|
|
gc.LineTo(100, 50)
|
|
|
|
gc.QuadCurveTo(100, 10, 10, 10)
|
|
|
|
gc.Close()
|
|
|
|
gc.FillStroke()
|
|
|
|
fmt.Println(gc.LastPoint())
|
|
|
|
|
2015-07-06 22:25:24 +00:00
|
|
|
// draw2dpdf.SaveToPdfFile("example.pdf", pdf)
|
2015-06-27 14:47:27 +00:00
|
|
|
|
|
|
|
// Output:
|
|
|
|
// 10 10
|
|
|
|
}
|