From c6a09fef08ef94067a714feea492e2f86fc41428 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Wed, 14 Aug 2013 09:01:41 -0400 Subject: Demonstration of alpha blending modes --- fpdf_test.go | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index 08dca43..5e2e7a8 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -707,16 +707,48 @@ func ExampleFpdf_tutorial11() { // Transparency func ExampleFpdf_tutorial12() { + const ( + gapX = 10.0 + gapY = 9.0 + rectW = 40.0 + rectH = 58.0 + pageW = 210 + pageH = 297 + ) + modeList := []string{"Normal", "Multiply", "Screen", "Overlay", + "Darken", "Lighten", "ColorDodge", "ColorBurn", "HardLight", "SoftLight", + "Difference", "Exclusion", "Hue", "Saturation", "Color", "Luminosity"} pdf := New("", "", "", FONT_DIR) - pdf.SetFont("Helvetica", "", 48) - pdf.SetLineWidth(4) - pdf.SetFillColor(180, 180, 180) + pdf.SetLineWidth(2) + pdf.SetAutoPageBreak(false, 0) pdf.AddPage() - pdf.SetXY(55, 60) - pdf.CellFormat(100, 40, "Go", "1", 0, "C", true, 0, "") - pdf.SetAlpha(0.5, "Normal") - pdf.Image(IMG_DIR+"/golang-gopher.png", 30, 10, 150, 0, false, "", 0, "") - pdf.SetAlpha(1.0, "Normal") + pdf.SetFont("Helvetica", "", 18) + pdf.SetXY(0, gapY) + pdf.SetTextColor(0, 0, 0) + pdf.CellFormat(pageW, gapY, "Alpha Blending Modes", "", 0, "C", false, 0, "") + j := 0 + y := 3 * gapY + for col := 0; col < 4; col++ { + x := gapX + for row := 0; row < 4; row++ { + pdf.Rect(x, y, rectW, rectH, "D") + pdf.SetFont("Helvetica", "B", 12) + pdf.SetFillColor(0, 0, 0) + pdf.SetTextColor(250, 250, 230) + pdf.SetXY(x, y+rectH-4) + pdf.CellFormat(rectW, 5, modeList[j], "", 0, "C", true, 0, "") + pdf.SetFont("Helvetica", "I", 150) + pdf.SetTextColor(80, 80, 120) + pdf.SetXY(x, y+2) + pdf.CellFormat(rectW, rectH, "A", "", 0, "C", false, 0, "") + pdf.SetAlpha(0.5, modeList[j]) + pdf.Image(IMG_DIR+"/golang-gopher.png", x-gapX, y, rectW+2*gapX, 0, false, "", 0, "") + pdf.SetAlpha(1.0, "Normal") + x += rectW + gapX + j++ + } + y += rectH + gapY + } pdf.OutputAndClose(docWriter(pdf, 12)) // Output: // Successfully generated pdf/tutorial12.pdf -- cgit v1.2.1-24-ge1ad