Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

Commit

Permalink
Merge branch 'wmatusiak-WordSpacing'
Browse files Browse the repository at this point in the history
  • Loading branch information
jung-kurt committed Feb 21, 2019
2 parents 5e8bff4 + 10d79b6 commit d0584cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fpdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
7 changes: 7 additions & 0 deletions fpdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file modified pdf/reference/Fpdf_WriteAligned.pdf
Binary file not shown.

0 comments on commit d0584cb

Please sign in to comment.