diff options
| -rw-r--r-- | def.go | 2 | ||||
| -rw-r--r-- | fpdf.go | 21 | 
2 files changed, 20 insertions, 3 deletions
| @@ -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 @@ -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] @@ -1435,10 +1446,14 @@ func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) {  }  // GetFontDesc returns the font descriptor, which can be used for -// example to find the baseline of a font. See FontDescType for -// documentation about the font descriptor. +// example to find the baseline of a font. If familyStr is empty +// current font descriptor will be returned. +// See FontDescType for documentation about the font descriptor.  // See AddFont for details about familyStr and styleStr.  func (f *Fpdf) GetFontDesc(familyStr, styleStr string) FontDescType { +	if familyStr == "" { +		return f.currentFont.Desc +	}  	return f.fonts[getFontKey(familyStr, styleStr)].Desc  } | 
