From 6a80039fd927b21892b75a206d8a36cccb60dd37 Mon Sep 17 00:00:00 2001 From: Wojciech Matusiak Date: Thu, 21 Feb 2019 02:25:10 +0100 Subject: Adds the ability to set word spacing. --- fpdf.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fpdf.go b/fpdf.go index bc047b1..3f4c1a3 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("%.3f Tw", space*f.k)) +} + // SetAcceptPageBreakFunc allows the application to control where page breaks // occur. // -- cgit v1.2.1-24-ge1ad From 6b86862c2bf56008b1c08cce71a8604b2e11e0cf Mon Sep 17 00:00:00 2001 From: Wojciech Matusiak Date: Thu, 21 Feb 2019 16:10:33 +0100 Subject: Match precision of word spacing with rest of code. --- fpdf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fpdf.go b/fpdf.go index 3f4c1a3..8376f9c 100644 --- a/fpdf.go +++ b/fpdf.go @@ -1899,7 +1899,7 @@ func (f *Fpdf) Text(x, y float64, txtStr string) { // SetWordSpacing sets spacing between words of following text func (f *Fpdf) SetWordSpacing(space float64) { - f.out(sprintf("%.3f Tw", space*f.k)) + f.out(sprintf("%.5f Tw", space*f.k)) } // SetAcceptPageBreakFunc allows the application to control where page breaks -- cgit v1.2.1-24-ge1ad From 10d79b67761eced6c524fbfb4383813065a58050 Mon Sep 17 00:00:00 2001 From: Wojciech Matusiak Date: Thu, 21 Feb 2019 16:36:36 +0100 Subject: Add example usage for SetWordSpacing --- fpdf_test.go | 7 +++++++ pdf/reference/Fpdf_WriteAligned.pdf | Bin 1064 -> 1122 bytes 2 files changed, 7 insertions(+) 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 Binary files a/pdf/reference/Fpdf_WriteAligned.pdf and b/pdf/reference/Fpdf_WriteAligned.pdf differ -- cgit v1.2.1-24-ge1ad