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