diff options
author | Joe Westcott <joewestcott@users.noreply.github.com> | 2019-08-22 22:31:52 +0100 |
---|---|---|
committer | Joe Westcott <joewestcott@users.noreply.github.com> | 2019-08-22 22:31:52 +0100 |
commit | 06680f145154e962a17ba7aaf33ab597ce83ef2e (patch) | |
tree | 3d1f571da69de116a1de1302656d6e1daf7a7be4 | |
parent | 9f0804cef4bf975423bbc86ccb9215915ae80478 (diff) |
Add SetUnderlineThickness method
-rw-r--r-- | def.go | 4 | ||||
-rw-r--r-- | fpdf.go | 9 |
2 files changed, 11 insertions, 2 deletions
@@ -452,6 +452,7 @@ type Pdf interface { SetTextSpotColor(nameStr string, tint byte) SetTitle(titleStr string, isUTF8 bool) SetTopMargin(margin float64) + SetUnderlineThickness(thickness float64) SetXmpMetadata(xmpStream []byte) SetX(x float64) SetXY(x, y float64) @@ -595,7 +596,8 @@ type Fpdf struct { // Composite values of colors draw, fill, text colorType } - spotColorMap map[string]spotColorType // Map of named ink-based colors + spotColorMap map[string]spotColorType // Map of named ink-based colors + userUnderlineThickness float64 // A custom user underline thickness multiplier. } type encType struct { @@ -202,6 +202,7 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) f.layerInit() f.catalogSort = gl.catalogSort f.creationDate = gl.creationDate + f.userUnderlineThickness = 1 return } @@ -3538,10 +3539,16 @@ func blankCount(str string) (count int) { return } +// SetUnderlineThickness accepts a multiplier for adjusting the text underline +// thickness, defaulting to 1. See SetUnderlineThickness example. +func (f *Fpdf) SetUnderlineThickness(thickness float64) { + f.userUnderlineThickness = thickness +} + // Underline text func (f *Fpdf) dounderline(x, y float64, txt string) string { up := float64(f.currentFont.Up) - ut := float64(f.currentFont.Ut) + ut := float64(f.currentFont.Ut) * f.userUnderlineThickness w := f.GetStringWidth(txt) + f.ws*float64(blankCount(txt)) return sprintf("%.2f %.2f %.2f %.2f re f", x*f.k, (f.h-(y-up/1000*f.fontSize))*f.k, w*f.k, -ut/1000*f.fontSizePt) |