diff options
Diffstat (limited to 'fpdf.go')
-rw-r--r-- | fpdf.go | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -1376,6 +1376,16 @@ func (f *Fpdf) AddFont(familyStr, styleStr, fileStr string) { f.AddFontFromReader(familyStr, styleStr, file) } +// getFontKey is used by AddFontFromReader and GetFontDesc +func getFontKey(familyStr, styleStr string) string { + familyStr = strings.ToLower(familyStr) + styleStr = strings.ToUpper(styleStr) + if styleStr == "IB" { + styleStr = "BI" + } + return familyStr + styleStr +} + // AddFontFromReader imports a TrueType, OpenType or Type1 font and makes it // available using a reader that satisifies the io.Reader interface. See // AddFont for details about familyStr and styleStr. @@ -1385,12 +1395,7 @@ func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) { } // dbg("Adding family [%s], style [%s]", familyStr, styleStr) var ok bool - familyStr = strings.ToLower(familyStr) - styleStr = strings.ToUpper(styleStr) - if styleStr == "IB" { - styleStr = "BI" - } - fontkey := familyStr + styleStr + fontkey := getFontKey(familyStr, styleStr) _, ok = f.fonts[fontkey] if ok { return @@ -1434,8 +1439,7 @@ func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) { // documentation about the font descriptor. // See AddFont for details about familyStr and styleStr. func (f *Fpdf) GetFontDesc(familyStr, styleStr string) FontDescType { - fontkey := familyStr + styleStr // see AddFontFromReader - return f.fonts[fontkey].Desc + return f.fonts[getFontKey(familyStr, styleStr)].Desc } // SetFont sets the font used to print character strings. It is mandatory to @@ -1686,8 +1690,8 @@ func (f *Fpdf) SetAcceptPageBreakFunc(fnc func() bool) { // alignStr specifies how the text is to be positionined within the cell. // Horizontal alignment is controlled by including "L", "C" or "R" (left, // center, right) in alignStr. Vertical alignment is controlled by including -// "T", "M" or "B" (top, middle, bottom) in alignStr. The default alignment is -// left middle. +// "T", "M", "B" or "A" (top, middle, bottom, baseline) in alignStr. The default +// alignment is left middle. // // fill is true to paint the cell background or false to leave it transparent. // @@ -1778,6 +1782,16 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int, dy = (f.fontSize - h) / 2.0 } else if strings.Index(alignStr, "B") != -1 { dy = (h - f.fontSize) / 2.0 + } else if strings.Index(alignStr, "A") != -1 { + var descent float64 + d := f.currentFont.Desc + if d.Descent == 0 { + // not defined (standard font?), use average of 19% + descent = -0.19 * f.fontSize + } else { + descent = float64(d.Descent) * f.fontSize / float64(d.Ascent-d.Descent) + } + dy = (h-f.fontSize)/2.0 - descent } else { dy = 0 } |