summaryrefslogtreecommitdiff
path: root/fpdf.go
diff options
context:
space:
mode:
Diffstat (limited to 'fpdf.go')
-rw-r--r--fpdf.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/fpdf.go b/fpdf.go
index 7b286a2..a7fb350 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -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
}