summaryrefslogtreecommitdiff
path: root/subwrite.go
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2018-12-27 08:34:59 -0500
committerKurt <kurt.w.jung@gmail.com>2018-12-27 08:34:59 -0500
commit6bd017132c2142e181eb6f945c06a90f45027d7d (patch)
tree3729284049053f335191879b7e6c446252633bb0 /subwrite.go
parenta3cf901b6d1246d3e00875a3e88c69bee068156d (diff)
Support subscripted and superscripted text with new SubWrite method
Diffstat (limited to 'subwrite.go')
-rw-r--r--subwrite.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/subwrite.go b/subwrite.go
new file mode 100644
index 0000000..dbeee5b
--- /dev/null
+++ b/subwrite.go
@@ -0,0 +1,33 @@
+package gofpdf
+
+// Adapted from http://www.fpdf.org/en/script/script61.php by Wirus and released with the FPDF license.
+
+// SubWrite prints text from the current position in the same way as Write().
+// ht is the line height in the unit of measure specified in New(). str
+// specifies the text to write. subFontSize is the size of the font in points.
+// subOffset is the vertical offset of the text in points; a positive value
+// indicates a superscript, a negative value indicates a subscript. link is the
+// identifier returned by AddLink() or 0 for no internal link. linkStr is a
+// target URL or empty for no external link. A non--zero value for link takes
+// precedence over linkStr.
+func (f *Fpdf) SubWrite(ht float64, str string, subFontSize, subOffset float64, link int, linkStr string) {
+ if f.err != nil {
+ return
+ }
+ // resize font
+ subFontSizeOld := f.fontSizePt
+ f.SetFontSize(subFontSize)
+ // reposition y
+ subOffset = (((subFontSize - subFontSizeOld) / f.k) * 0.3) + (subOffset / f.k)
+ subX := f.x
+ subY := f.y
+ f.SetXY(subX, subY-subOffset)
+ //Output text
+ f.write(ht, str, link, linkStr)
+ // restore y position
+ subX = f.x
+ subY = f.y
+ f.SetXY(subX, subY+subOffset)
+ // restore font size
+ f.SetFontSize(subFontSizeOld)
+}