summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@code.google.com>2013-08-14 09:01:41 -0400
committerKurt Jung <kurt.w.jung@code.google.com>2013-08-14 09:01:41 -0400
commitc6a09fef08ef94067a714feea492e2f86fc41428 (patch)
treebf27818ca192aff3d80982b4141e1ec90baab3c2
parentcb9b6b05fca2d3154237d94eae678b8c97a2604e (diff)
Demonstration of alpha blending modes
-rw-r--r--fpdf.go2
-rw-r--r--fpdf_test.go48
2 files changed, 41 insertions, 9 deletions
diff --git a/fpdf.go b/fpdf.go
index 24db0be..f526821 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -841,7 +841,7 @@ func (f *Fpdf) Arc(x, y, rx, ry, degRotate, degStart, degEnd float64, styleStr s
// To reset normal rendering after applying a blending mode, call this method
// with alpha set to 1.0 and blendModeStr set to "Normal".
//
-// See tutorial 12 for an example of this function.
+// See tutorial 12 for an example of this function, including samples of each blending mode.
func (f *Fpdf) SetAlpha(alpha float64, blendModeStr string) {
if f.err != nil {
return
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