diff options
author | Lawrence Kesteloot (lk <Lawrence Kesteloot (lk@headcode.com)> | 2014-07-21 22:47:13 -0700 |
---|---|---|
committer | Lawrence Kesteloot (lk <Lawrence Kesteloot (lk@headcode.com)> | 2014-07-21 22:47:13 -0700 |
commit | e869d1301c550b65bb6b9720a5ba98423861a735 (patch) | |
tree | 81c6c8d9874b12cf7b6b65fcfc8354f37871652a | |
parent | 7b79f51bb56464bcabcd82a31b8ea75c74677689 (diff) |
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.)
-rw-r--r-- | fpdf.go | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -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 } |