From 70127eba31f1d3f43f7ffe7e25ad871c58784507 Mon Sep 17 00:00:00 2001 From: Stani Date: Sun, 12 Jul 2015 19:45:10 +0200 Subject: GetFontDesc returns the current font descriptor if familyStr is empty --- fpdf.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'fpdf.go') diff --git a/fpdf.go b/fpdf.go index fd0c91f..c909c19 100644 --- a/fpdf.go +++ b/fpdf.go @@ -1435,10 +1435,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 } -- cgit v1.2.1-24-ge1ad From 948d75670f89e31587919f7828fe9931387322a3 Mon Sep 17 00:00:00 2001 From: Stani Date: Sun, 12 Jul 2015 22:54:44 +0200 Subject: implement GetAlpha --- fpdf.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'fpdf.go') 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