summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2019-08-23 07:12:00 -0400
committerKurt <kurt.w.jung@gmail.com>2019-08-23 07:12:00 -0400
commit1566d943c0e8df226a04d454b19c56832d8fdc4e (patch)
tree371d268f5da02f5072942155c1eba9c60aaed25d
parented240cb3be2b6e232a4944f9ae13cc762735e86c (diff)
parent1f076cb96ab154628c2f1087099e2d6159476e65 (diff)
Merge branch 'underline' of https://github.com/joewestcott/gofpdf into joewestcott-underline
-rw-r--r--def.go4
-rw-r--r--fpdf.go9
-rw-r--r--fpdf_test.go23
-rw-r--r--pdf/reference/Fpdf_UnderlineThickness.pdfbin0 -> 1156 bytes
4 files changed, 34 insertions, 2 deletions
diff --git a/def.go b/def.go
index 95da6ba..7fddc82 100644
--- a/def.go
+++ b/def.go
@@ -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 {
diff --git a/fpdf.go b/fpdf.go
index d64a324..f77717f 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -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)
diff --git a/fpdf_test.go b/fpdf_test.go
index c6020f3..43cea30 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -2688,3 +2688,26 @@ func ExampleFpdf_RoundedRect() {
// Output:
// Successfully generated pdf/Fpdf_RoundedRect.pdf
}
+
+// ExampleFpdf_SetUnderlineThickness demonstrates how to adjust the text
+// underline thickness.
+func ExampleFpdf_SetUnderlineThickness() {
+ pdf := gofpdf.New("P", "mm", "A4", "") // 210mm x 297mm
+ pdf.AddPage()
+ pdf.SetFont("Arial", "U", 12)
+
+ pdf.SetUnderlineThickness(0.5)
+ pdf.CellFormat(0, 10, "Thin underline", "", 1, "", false, 0, "")
+
+ pdf.SetUnderlineThickness(1)
+ pdf.CellFormat(0, 10, "Normal underline", "", 1, "", false, 0, "")
+
+ pdf.SetUnderlineThickness(2)
+ pdf.CellFormat(0, 10, "Thicker underline", "", 1, "", false, 0, "")
+
+ fileStr := example.Filename("Fpdf_UnderlineThickness")
+ err := pdf.OutputFileAndClose(fileStr)
+ example.Summary(err, fileStr)
+ // Output:
+ // Successfully generated pdf/Fpdf_UnderlineThickness.pdf
+}
diff --git a/pdf/reference/Fpdf_UnderlineThickness.pdf b/pdf/reference/Fpdf_UnderlineThickness.pdf
new file mode 100644
index 0000000..49ad9b1
--- /dev/null
+++ b/pdf/reference/Fpdf_UnderlineThickness.pdf
Binary files differ