summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@code.google.com>2014-06-29 14:14:19 -0400
committerKurt Jung <kurt.w.jung@code.google.com>2014-06-29 14:14:19 -0400
commit875b1c7a15f289f388a0187781c5f2b1f4e9dc90 (patch)
tree764467e3a6b71b1d7b8c3ee35edf3e5b261b6d09 /fpdf_test.go
parent2ba1e1bcedbc413c15f211a977c5ffee5621ce0e (diff)
Polygon function and demonstration
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index c727087..262e482 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -21,6 +21,7 @@ import (
"code.google.com/p/gofpdf"
"fmt"
"io/ioutil"
+ "math"
"os"
"path/filepath"
"strings"
@@ -1197,3 +1198,50 @@ func ExampleFpdf_tutorial24() {
// Output:
// Successfully generated pdf/tutorial24.pdf
}
+
+// This example displays equilateral polygons in a demonstration of the Polygon
+// function.
+func ExampleFpdf_tutorial25() {
+ const rowCount = 5
+ const colCount = 4
+ const ptSize = 36
+ var x, y, radius, gap, advance float64
+ var rgVal int
+ var pts []gofpdf.PointType
+ vertices := func(count int) (res []gofpdf.PointType) {
+ var pt gofpdf.PointType
+ res = make([]gofpdf.PointType, 0, count)
+ mlt := 2.0 * math.Pi / float64(count)
+ for j := 0; j < count; j++ {
+ pt.Y, pt.X = math.Sincos(float64(j) * mlt)
+ res = append(res, gofpdf.PointType{x + radius*pt.X, y + radius*pt.Y})
+ }
+ return
+ }
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir) // A4 210.0 x 297.0
+ pdf.AddPage()
+ pdf.SetFont("Helvetica", "", ptSize)
+ pdf.SetDrawColor(0, 80, 180)
+ gap = 12.0
+ pdf.SetY(gap)
+ pdf.CellFormat(190.0, gap, "Equilateral polygons", "", 1, "C", false, 0, "")
+ radius = (210.0 - float64(colCount+1)*gap) / (2.0 * float64(colCount))
+ advance = gap + 2.0*radius
+ y = 2*gap + pdf.PointConvert(ptSize) + radius
+ rgVal = 230
+ for row := 0; row < rowCount; row++ {
+ pdf.SetFillColor(rgVal, rgVal, 0)
+ rgVal -= 12
+ x = gap + radius
+ for col := 0; col < colCount; col++ {
+ pts = vertices(row*colCount + col + 3)
+ // pdf.Circle(x, y, radius, "FD")
+ pdf.Polygon(pts, "FD")
+ x += advance
+ }
+ y += advance
+ }
+ pdf.OutputAndClose(docWriter(pdf, 25))
+ // Output:
+ // Successfully generated pdf/tutorial25.pdf
+}