summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2019-08-12 09:20:09 -0400
committerKurt <kurt.w.jung@gmail.com>2019-08-12 09:20:09 -0400
commit0d44f4b8df0f8964427cbaaa5eb70f98ae56a0ca (patch)
treebfcb39994b6303c7aff77cc6af048ce0c4a9fb51 /fpdf_test.go
parent7c5006543b654248bb1fb640703faf0a53f59f71 (diff)
Revise comment, fix style write, extend example for RoundedRect
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go56
1 files changed, 46 insertions, 10 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index 08814e0..c6020f3 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -2641,14 +2641,50 @@ func ExampleUTF8CutFont() {
}
func ExampleFpdf_RoundedRect() {
- pdf := gofpdf.New("P", "mm", "A4", "")
- pdf.AddPage()
- pdf.SetFillColor(160, 160, 160)
- pdf.SetLineWidth(0.5)
- pdf.RoundedRect(70, 30, 68, 46, 20, "1234", "FD")
- fileStr := example.Filename("Fpdf_RoundedRect")
- err := pdf.OutputFileAndClose(fileStr)
- example.Summary(err, fileStr)
- // Output:
- // Successfully generated pdf/Fpdf_RoundedRect.pdf
+ const (
+ wd = 40.0
+ hgap = 10.0
+ radius = 10.0
+ ht = 60.0
+ vgap = 10.0
+ )
+ corner := func(b1, b2, b3, b4 bool) (cstr string) {
+ if b1 {
+ cstr = "1"
+ }
+ if b2 {
+ cstr += "2"
+ }
+ if b3 {
+ cstr += "3"
+ }
+ if b4 {
+ cstr += "4"
+ }
+ return
+ }
+ pdf := gofpdf.New("P", "mm", "A4", "") // 210 x 297
+ pdf.AddPage()
+ pdf.SetLineWidth(0.5)
+ y := vgap
+ r := 40
+ g := 30
+ b := 20
+ for row := 0; row < 4; row++ {
+ x := hgap
+ for col := 0; col < 4; col++ {
+ pdf.SetFillColor(r, g, b)
+ pdf.RoundedRect(x, y, wd, ht, radius, corner(row&1 == 1, row&2 == 2, col&1 == 1, col&2 == 2), "FD")
+ r += 8
+ g += 10
+ b += 12
+ x += wd + hgap
+ }
+ y += ht + vgap
+ }
+ fileStr := example.Filename("Fpdf_RoundedRect")
+ err := pdf.OutputFileAndClose(fileStr)
+ example.Summary(err, fileStr)
+ // Output:
+ // Successfully generated pdf/Fpdf_RoundedRect.pdf
}