From 24315acbbda57c4f6b80c8441fd108087dd7e305 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 9 Mar 2019 07:58:59 -0500 Subject: Factored pattern draw for transformation / graphic state test --- fpdf_test.go | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index 92ac3d9..53609bf 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -2448,35 +2448,27 @@ func ExampleFpdf_SetFillColor() { pdf := gofpdf.New("P", "mm", "A4", "") pdf.AddPage() - pdf.SetFont("Arial", "", 12) - - pdf.TransformBegin() - pdf.TransformTranslateX(5) - pdf.TransformTranslateY(5) - pdf.SetLineJoinStyle("round") - pdf.SetLineWidth(2) - pdf.SetDrawColor(128, 64, 0) - pdf.SetFillColor(255, 127, 0) - pdf.SetAlpha(0.5, "Normal") - pdf.SetDashPattern([]float64{5, 10}, 0) - pdf.Rect(0, 0, 20, 20, "FD") - pdf.SetFontSize(8) - pdf.Write(10, "Test") - pdf.TransformEnd() + pdf.SetFont("Arial", "", 8) - pdf.TransformBegin() - pdf.TransformTranslateX(35) - pdf.TransformTranslateY(35) - pdf.SetLineJoinStyle("round") - pdf.SetLineWidth(2) - pdf.SetDrawColor(128, 64, 0) - pdf.SetFillColor(255, 127, 0) - pdf.SetAlpha(0.5, "Normal") - pdf.SetDashPattern([]float64{5, 10}, 0) - pdf.Rect(0, 0, 20, 20, "FD") - pdf.SetFontSize(8) - pdf.Write(10, "Test") - pdf.TransformEnd() + draw := func(trX, trY float64) { + pdf.TransformBegin() + pdf.TransformTranslateX(trX) + pdf.TransformTranslateY(trY) + pdf.SetLineJoinStyle("round") + pdf.SetLineWidth(0.5) + pdf.SetDrawColor(128, 64, 0) + pdf.SetFillColor(255, 127, 0) + pdf.SetAlpha(0.5, "Normal") + pdf.SetDashPattern([]float64{5, 10}, 0) + pdf.Rect(0, 0, 40, 40, "FD") + pdf.SetFontSize(12) + pdf.SetXY(5, 5) + pdf.Write(0, "Test") + pdf.TransformEnd() + } + + draw(5, 5) + draw(50, 50) fileStr := example.Filename("Fpdf_SetFillColor") err := pdf.OutputFileAndClose(fileStr) -- cgit v1.2.1-24-ge1ad