jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.31k stars 777 forks source link

New method: pdf.SetUnderlineThickness #287

Closed joewestcott closed 5 years ago

joewestcott commented 5 years ago

Hiya @jung-kurt

Do you think this method would be a useful addition to this library? It would allow the programmer to adjust the text underline thickness whilst still having it scale with the font size. I'd be happy to create a PR with the following changes:

  1. Store a new attribute on the principal struct, userUnderlineThickness, defaulting to 1.0

  2. Create a new method named pdf.SetUnderlineThickness taking a float64. This will set f.userUnderlineThickness

  3. Modify dounderline function on line 3477 of fpdf.go to multiply f.currentFont.Ut by f.userUnderlineThickness (line 3 below)

func (f *Fpdf) dounderline(x, y float64, txt string) string {
    up := float64(f.currentFont.Up)
    ut := float64(f.currentFont.Ut) * f.userUnderlineThickness // <-- this!
    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)
}

Any thought, let me know. Thanks!

jung-kurt commented 5 years ago

Go for it, @joewestcott !