diff options
author | Kurt Jung <kurt.w.jung@code.google.com> | 2013-09-04 15:06:56 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@code.google.com> | 2013-09-04 15:06:56 -0400 |
commit | 845888136482c81fd76860b57e254c0e8fa6c149 (patch) | |
tree | 0cb49ce1cf0de4875ee103495490b63b8bccd22c /fpdf.go | |
parent | 9b78fbbf6a97869fca10d53e11a52b2d2a9c37a2 (diff) |
Set error condition if out-of-range Unicode rune is encountered in GetStringWidth
Diffstat (limited to 'fpdf.go')
-rw-r--r-- | fpdf.go | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -658,9 +658,20 @@ func (f *Fpdf) SetTextColor(r, g, b int) { // Returns the length of a string in user units. A font must be selected. func (f *Fpdf) GetStringWidth(s string) float64 { + if f.err != nil { + return 0 + } w := 0 + count := rune(len(f.currentFont.Cw)) for _, ch := range s { - w += f.currentFont.Cw[ch] + if ch < count { + w += f.currentFont.Cw[ch] + } else { + if f.err == nil { + f.err = fmt.Errorf("Unicode strings not supported") + } + return 0 + } } return float64(w) * f.fontSize / 1000 } |