From 4860d8e6cd3175db81b81cae5a27a54662c39d94 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Tue, 15 Oct 2013 09:27:49 -0400 Subject: 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. --- fpdf.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'fpdf.go') diff --git a/fpdf.go b/fpdf.go index da5ddec..cc1aff3 100644 --- a/fpdf.go +++ b/fpdf.go @@ -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 } -- cgit v1.2.1-24-ge1ad