Skip to content

Commit

Permalink
Address issue jung-kurt#333 by removing at most one trailing newline …
Browse files Browse the repository at this point in the history
…from txtStr in MultiCell() with non-UTF-8 fonts only. Explain this in MultiCell() documentation.
  • Loading branch information
jung-kurt committed Nov 9, 2019
1 parent 50ed053 commit c86cd48
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion fpdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,15 @@ func (f *Fpdf) SplitLines(txt []byte, w float64) [][]byte {
// the right margin.
//
// h indicates the line height of each cell in the unit of measure specified in New().
//
// Note: this method has a known bug that treats UTF-8 fonts differently than
// non-UTF-8 fonts. With UTF-8 fonts, all trailing newlines in txtStr are
// removed. With a non-UTF-8 font, if txtStr has one or more trailing newlines,
// only the last is removed. In the next major module version, the UTF-8 logic
// will be changed to match the non-UTF-8 logic. To prepare for that change,
// applications that use UTF-8 fonts and depend on having all trailing newlines
// removed should call strings.TrimRight(txtStr, "\r\n") before calling this
// method.
func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill bool) {
if f.err != nil {
return
Expand Down Expand Up @@ -2611,7 +2620,15 @@ func (f *Fpdf) MultiCell(w, h float64, txtStr, borderStr, alignStr string, fill
} else {
nb = len(s)
bytes2 := []byte(s)
for nb > 0 && bytes2[nb-1] == '\n' {

// for nb > 0 && bytes2[nb-1] == '\n' {

// Prior to August 2019, if s ended with a newline, this code stripped it.
// After that date, to be compatible with the UTF-8 code above, *all*
// trailing newlines were removed. Because this regression caused at least
// one application to break (see issue #333), the original behavior has been
// reinstated with a caveat included in the documentation.
if nb > 0 && bytes2[nb-1] == '\n' {
nb--
}
s = s[0:nb]
Expand Down

0 comments on commit c86cd48

Please sign in to comment.