subwrite.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package gofpdf
  2. // Adapted from http://www.fpdf.org/en/script/script61.php by Wirus and released with the FPDF license.
  3. // SubWrite prints text from the current position in the same way as Write().
  4. // ht is the line height in the unit of measure specified in New(). str
  5. // specifies the text to write. subFontSize is the size of the font in points.
  6. // subOffset is the vertical offset of the text in points; a positive value
  7. // indicates a superscript, a negative value indicates a subscript. link is the
  8. // identifier returned by AddLink() or 0 for no internal link. linkStr is a
  9. // target URL or empty for no external link. A non--zero value for link takes
  10. // precedence over linkStr.
  11. //
  12. // The SubWrite example demonstrates this method.
  13. func (f *Fpdf) SubWrite(ht float64, str string, subFontSize, subOffset float64, link int, linkStr string) {
  14. if f.err != nil {
  15. return
  16. }
  17. // resize font
  18. subFontSizeOld := f.fontSizePt
  19. f.SetFontSize(subFontSize)
  20. // reposition y
  21. subOffset = (((subFontSize - subFontSizeOld) / f.k) * 0.3) + (subOffset / f.k)
  22. subX := f.x
  23. subY := f.y
  24. f.SetXY(subX, subY-subOffset)
  25. //Output text
  26. f.write(ht, str, link, linkStr)
  27. // restore y position
  28. subX = f.x
  29. subY = f.y
  30. f.SetXY(subX, subY+subOffset)
  31. // restore font size
  32. f.SetFontSize(subFontSizeOld)
  33. }