From 948d75670f89e31587919f7828fe9931387322a3 Mon Sep 17 00:00:00 2001 From: Stani Date: Sun, 12 Jul 2015 22:54:44 +0200 Subject: implement GetAlpha --- def.go | 2 ++ fpdf.go | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/def.go b/def.go index 3973351..437449c 100644 --- a/def.go +++ b/def.go @@ -223,6 +223,8 @@ type Fpdf struct { dashPhase float64 // dash phase blendList []blendModeType // slice[idx] of alpha transparency modes, 1-based blendMap map[string]int // map into blendList + blendMode string // current blend mode + alpha float64 // current transpacency gradientList []gradientType // slice[idx] of gradient records clipNest int // Number of active clipping contexts transformNest int // Number of active transformation contexts diff --git a/fpdf.go b/fpdf.go index c909c19..22de11d 100644 --- a/fpdf.go +++ b/fpdf.go @@ -170,6 +170,8 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) f.blendList = make([]blendModeType, 0, 8) f.blendList = append(f.blendList, blendModeType{}) // blendList[0] is unused (1-based) f.blendMap = make(map[string]int) + f.blendMode = "Normal" + f.alpha = 1 f.gradientList = make([]gradientType, 0, 8) f.gradientList = append(f.gradientList, gradientType{}) // gradientList[0] is unused // Set default PDF version number @@ -1062,6 +1064,13 @@ func (f *Fpdf) Arc(x, y, rx, ry, degRotate, degStart, degEnd float64, styleStr s f.arc(x, y, rx, ry, degRotate, degStart, degEnd, styleStr, false) } +// GetAlpha returns the alpha blending channel, which consists of the +// alpha transparency value and the blend mode. See SetAlpha for more +// details. +func (f *Fpdf) GetAlpha() (alpha float64, blendModeStr string) { + return f.alpha, f.blendMode +} + // SetAlpha sets the alpha blending channel. The blending effect applies to // text, drawings and images. // @@ -1076,7 +1085,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". func (f *Fpdf) SetAlpha(alpha float64, blendModeStr string) { - if f.err != nil { + if f.err != nil || (alpha == f.alpha && blendModeStr == f.blendMode) { return } var bl blendModeType @@ -1095,6 +1104,8 @@ func (f *Fpdf) SetAlpha(alpha float64, blendModeStr string) { f.err = fmt.Errorf("alpha value (0.0 - 1.0) is out of range: %.3f", alpha) return } + f.alpha = alpha + f.blendMode = blendModeStr alphaStr := sprintf("%.3f", alpha) keyStr := sprintf("%s %s", alphaStr, blendModeStr) pos, ok := f.blendMap[keyStr] -- cgit v1.2.1-24-ge1ad