summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@gmail.com>2015-07-06 16:58:41 -0400
committerKurt Jung <kurt.w.jung@gmail.com>2015-07-06 16:58:41 -0400
commit19ef571c9c8f0ea66120545e7280c264829cd66b (patch)
treecfe55b858f720d5e313d5a09e98e2221ee59fdba /fpdf_test.go
parentbc7edcc6a96f0232c6bb4f358bde13e146842242 (diff)
parentdc18daf15849e2476bbec42e833a843a2f05fd71 (diff)
Small tweak to increment operator keep golint happy
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index 9ac1e18..3872331 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -26,6 +26,7 @@ import (
"net/http"
"os"
"path/filepath"
+ "strconv"
"strings"
"github.com/jung-kurt/gofpdf"
@@ -1516,3 +1517,78 @@ func ExampleFpdf_tutorial31() {
// Output:
// Successfully generated pdf/tutorial31.pdf
}
+
+// This example demonstrates the Path Drawing functions, such as: MoveTo,
+// LineTo, CurveTo, ..., ClosePath and DrawPath.
+func ExampleFpdf_tutorial32() {
+ pdf := gofpdf.New("P", "mm", "A4", "")
+ pdf.SetDrawColor(0xff, 0x00, 0x00)
+ pdf.SetFillColor(0x99, 0x99, 0x99)
+ pdf.SetFont("Helvetica", "", 15)
+ pdf.AddPage()
+ pdf.SetAlpha(1, "Multiply")
+ var (
+ polygon = func(cx, cy, r, n, dir float64) {
+ da := 2 * math.Pi / n
+ pdf.MoveTo(cx+r, cy)
+ pdf.Text(cx+r, cy, "0")
+ i := 1
+ for a := da; a < 2*math.Pi; a += da {
+ x, y := cx+r*math.Cos(dir*a), cy+r*math.Sin(dir*a)
+ pdf.LineTo(x, y)
+ pdf.Text(x, y, strconv.Itoa(i))
+ i++
+ }
+ pdf.ClosePath()
+ }
+ polygons = func(cx, cy, r, n, dir float64) {
+ d := 1.0
+ for rf := r; rf > 0; rf -= 10 {
+ polygon(cx, cy, rf, n, d)
+ d *= dir
+ }
+ }
+ star = func(cx, cy, r, n float64) {
+ da := 4 * math.Pi / n
+ pdf.MoveTo(cx+r, cy)
+ for a := da; a < 4*math.Pi+da; a += da {
+ x, y := cx+r*math.Cos(a), cy+r*math.Sin(a)
+ pdf.LineTo(x, y)
+ }
+ pdf.ClosePath()
+ }
+ )
+ // triangle
+ polygons(55, 45, 40, 3, 1)
+ pdf.DrawPath("B")
+ pdf.Text(15, 95, "B (same direction, non zero winding)")
+
+ // square
+ polygons(155, 45, 40, 4, 1)
+ pdf.DrawPath("B*")
+ pdf.Text(115, 95, "B* (same direction, even odd)")
+
+ // pentagon
+ polygons(55, 145, 40, 5, -1)
+ pdf.DrawPath("B")
+ pdf.Text(15, 195, "B (different direction, non zero winding)")
+
+ // hexagon
+ polygons(155, 145, 40, 6, -1)
+ pdf.DrawPath("B*")
+ pdf.Text(115, 195, "B* (different direction, even odd)")
+
+ // star
+ star(55, 245, 40, 5)
+ pdf.DrawPath("B")
+ pdf.Text(15, 290, "B (non zero winding)")
+
+ // star
+ star(155, 245, 40, 5)
+ pdf.DrawPath("B*")
+ pdf.Text(115, 290, "B* (even odd)")
+
+ pdf.OutputAndClose(docWriter(pdf, 32))
+ // Output:
+ // Successfully generated pdf/tutorial32.pdf
+}