From e869d1301c550b65bb6b9720a5ba98423861a735 Mon Sep 17 00:00:00 2001 From: "Lawrence Kesteloot (lk" Date: Mon, 21 Jul 2014 22:47:13 -0700 Subject: Use integer math in SplitLines(). The math for the limit used to be done in floats, but round-off error sometimes resulted in a string being wrapped at a width that had previously been returned by GetStringWidth() for that same string. (I got this with the string "$53,013" in Arial 12 point.) --- fpdf.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fpdf.go b/fpdf.go index 6ad5bd6..dd7d957 100644 --- a/fpdf.go +++ b/fpdf.go @@ -1712,7 +1712,7 @@ func (f *Fpdf) SplitLines(txt []byte, w float64) [][]byte { // Function contributed by Bruno Michel lines := [][]byte{} cw := &f.currentFont.Cw - wmax := (w - 2*f.cMargin) * 1000 / f.fontSize + wmax := int(math.Ceil((w - 2*f.cMargin) * 1000 / f.fontSize)) s := bytes.Replace(txt, []byte("\r"), []byte{}, -1) nb := len(s) for nb > 0 && s[nb-1] == '\n' { @@ -1722,10 +1722,10 @@ func (f *Fpdf) SplitLines(txt []byte, w float64) [][]byte { sep := -1 i := 0 j := 0 - l := 0.0 + l := 0 for i < nb { c := s[i] - l += float64(cw[c]) + l += cw[c] if c == ' ' || c == '\t' || c == '\n' { sep = i } -- cgit v1.2.1-24-ge1ad