diff options
author | Kurt Jung <kurt.w.jung@code.google.com> | 2013-10-15 09:27:49 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@code.google.com> | 2013-10-15 09:27:49 -0400 |
commit | 4860d8e6cd3175db81b81cae5a27a54662c39d94 (patch) | |
tree | 746fe66520d3be7edcd7da074e41392d26ce6260 /fpdf.go | |
parent | 1df224f1d58d731bd9027a5af26b4604a183c4c8 (diff) |
Bruno Michel identified a problem with encoded characters that have a value of 0x80 or greater. His correction makes sure Go treats strings as an array of bytes rather than runes.
Diffstat (limited to 'fpdf.go')
-rw-r--r-- | fpdf.go | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -666,16 +666,11 @@ func (f *Fpdf) GetStringWidth(s string) float64 { return 0 } w := 0 - count := rune(len(f.currentFont.Cw)) - for _, ch := range s { - if ch < count { - w += f.currentFont.Cw[ch] - } else { - if f.err == nil { - f.err = fmt.Errorf("Unicode strings not supported") - } - return 0 + for _, ch := range []byte(s) { + if ch == 0 { + break } + w += f.currentFont.Cw[ch] } return float64(w) * f.fontSize / 1000 } |