diff options
author | hyzgh <31174102+hyzgh@users.noreply.github.com> | 2019-08-20 19:50:37 +0800 |
---|---|---|
committer | hyzgh <31174102+hyzgh@users.noreply.github.com> | 2019-08-21 18:08:30 +0800 |
commit | 5cb8bab84fe08b93191ed0385c016592d2ac7cc4 (patch) | |
tree | a30d2d0265082e83b54a85d647255d74cd59c319 /fpdf.go | |
parent | bd30e05dff3288bc54bb696a45c4ec45ceb1156d (diff) |
fix split line bug
Change-Id: I224a7ec1af8386dcbef757c76389fb88316401bc
Diffstat (limited to 'fpdf.go')
-rw-r--r-- | fpdf.go | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -2551,20 +2551,23 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill } wmax := int(math.Ceil((w - 2*f.cMargin) * 1000 / f.fontSize)) s := strings.Replace(txtStr, "\r", "", -1) + srune := []rune(s) + // remove extra line breaks var nb int if f.isCurrentUTF8 { - nb = len([]rune(s)) - for nb > 0 && []rune(s)[nb-1] == '\n' { + nb = len(srune) + for nb > 0 && srune[nb-1] == '\n' { nb-- - s = string([]rune(s)[0:nb]) } + srune = srune[0:nb] } else { nb = len(s) - if nb > 0 && []byte(s)[nb-1] == '\n' { + bytes2 := []byte(s) + for nb > 0 && bytes2[nb-1] == '\n' { nb-- - s = s[0:nb] } + s = s[0:nb] } // dbg("[%s]\n", s) var b, b2 string @@ -2603,7 +2606,7 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill if f.isCurrentUTF8 { c = srune[i] } else { - c = rune(byte(s[i])) + c = rune(s[i]) } if c == '\n' { // Explicit line break @@ -2636,7 +2639,7 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill } continue } - if c == ' ' { + if c == ' ' || isChinese(c) { sep = i ls = l ns++ |