summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2019-02-21 11:25:22 -0500
committerKurt <kurt.w.jung@gmail.com>2019-02-21 11:25:22 -0500
commitd0584cb180f1316776ad59421ceed4c02f47e104 (patch)
tree7f1e8cf2e4765b1a8cb1f24f3d4f0320fb80e029
parent5e8bff406205400b6d067dc6d96666dedc2cf32a (diff)
parent10d79b67761eced6c524fbfb4383813065a58050 (diff)
Merge branch 'wmatusiak-WordSpacing'
-rw-r--r--fpdf.go5
-rw-r--r--fpdf_test.go7
-rw-r--r--pdf/reference/Fpdf_WriteAligned.pdfbin1064 -> 1122 bytes
3 files changed, 12 insertions, 0 deletions
diff --git a/fpdf.go b/fpdf.go
index bc047b1..8376f9c 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -1897,6 +1897,11 @@ func (f *Fpdf) Text(x, y float64, txtStr string) {
f.out(s)
}
+// SetWordSpacing sets spacing between words of following text
+func (f *Fpdf) SetWordSpacing(space float64) {
+ f.out(sprintf("%.5f Tw", space*f.k))
+}
+
// SetAcceptPageBreakFunc allows the application to control where page breaks
// occur.
//
diff --git a/fpdf_test.go b/fpdf_test.go
index 86fae86..d84de54 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -799,6 +799,13 @@ func ExampleFpdf_WriteAligned() {
pdf.WriteAligned(0, 35, "This text is aligned Center", "C")
pdf.Ln(35)
pdf.WriteAligned(0, 35, "This text is aligned Right", "R")
+ pdf.Ln(35)
+ line := "This text fill line using word spacing. This can by used to write justified text"
+ leftMargin, _, rightMargin, _ := pdf.GetMargins()
+ pageWidth, _ := pdf.GetPageSize()
+ pageWidth -= leftMargin + rightMargin
+ pdf.SetWordSpacing((pageWidth - pdf.GetStringWidth(line)) / float64(strings.Count(line, " ")))
+ pdf.WriteAligned(pageWidth, 35, line, "L")
fileStr := example.Filename("Fpdf_WriteAligned")
err := pdf.OutputFileAndClose(fileStr)
example.Summary(err, fileStr)
diff --git a/pdf/reference/Fpdf_WriteAligned.pdf b/pdf/reference/Fpdf_WriteAligned.pdf
index c3b52a0..0daf8fe 100644
--- a/pdf/reference/Fpdf_WriteAligned.pdf
+++ b/pdf/reference/Fpdf_WriteAligned.pdf
Binary files differ