summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2019-04-17 15:06:04 -0400
committerKurt <kurt.w.jung@gmail.com>2019-04-17 15:06:04 -0400
commitc4efce9a69a2984635492636b9c3292d7d0c7e47 (patch)
tree3fbf4ad80bf3e8c13ee39789141538c5d477f842
parent29741e337ab46231e17a6873fb1fe56df5994271 (diff)
Anka2310's modified fix for the right justify bug
-rw-r--r--fpdf.go2
-rw-r--r--fpdf_test.go4
2 files changed, 4 insertions, 2 deletions
diff --git a/fpdf.go b/fpdf.go
index 4881ba4..bd4aa4e 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -2441,7 +2441,7 @@ func (f *Fpdf) WriteAligned(width, lineHeight float64, textStr, alignStr string)
f.Write(lineHeight, lineStr)
f.SetLeftMargin(lMargin)
case "R":
- f.SetLeftMargin(lMargin + (width - lineWidth))
+ f.SetLeftMargin(lMargin + (width - lineWidth) - 2.01*f.cMargin)
f.Write(lineHeight, lineStr)
f.SetLeftMargin(lMargin)
default:
diff --git a/fpdf_test.go b/fpdf_test.go
index d894607..7d956ce 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -791,6 +791,8 @@ func ExampleFpdf_AddFont() {
// ExampleFpdf_WriteAligned demonstrates how to align text with the Write function.
func ExampleFpdf_WriteAligned() {
pdf := gofpdf.New("P", "mm", "A4", example.FontDir())
+ pdf.SetLeftMargin(50.0)
+ pdf.SetRightMargin(50.0)
pdf.AddPage()
pdf.SetFont("Helvetica", "", 12)
pdf.WriteAligned(0, 35, "This text is the default alignment, Left", "")
@@ -801,7 +803,7 @@ func ExampleFpdf_WriteAligned() {
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"
+ line := "This can by used to write justified text"
leftMargin, _, rightMargin, _ := pdf.GetMargins()
pageWidth, _ := pdf.GetPageSize()
pageWidth -= leftMargin + rightMargin