git.lucas.co / go_mono
git clone https://git.lucas.co/go_mono.git

commit972c09e46d762a13c1a3c48b1fa9b87e2c537805
parentc137617195
authorNigel Tao <nigeltao@golang.org>
date2020-07-27 22:28
font/sfnt: fix Font.GlyphBounds with truncated hmtx table

Thanks to Joe Blubaugh for the suggestion.

Change-Id: I27cb776614b5a4a0d023755f01b4db06e3d9a1c5
Reviewed-on: https://go-review.googlesource.com/c/image/+/244997
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>

 font/sfnt/sfnt.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/font/sfnt/sfnt.go b/font/sfnt/sfnt.go
index f05b4cd..d882891 100644
--- a/font/sfnt/sfnt.go
+++ b/font/sfnt/sfnt.go
@@ -1518,11 +1518,12 @@ func (f *Font) GlyphBounds(b *Buffer, x GlyphIndex, ppem fixed.Int26_6, h font.H
 	// optimization, the number of records can be less than the number of
 	// glyphs, in which case the advance width value of the last record applies
 	// to all remaining glyph IDs."
+	metricIndex := x
 	if n := GlyphIndex(f.cached.numHMetrics - 1); x > n {
-		x = n
+		metricIndex = n
 	}
 
-	buf, err := b.view(&f.src, int(f.hmtx.offset)+4*int(x), 2)
+	buf, err := b.view(&f.src, int(f.hmtx.offset)+4*int(metricIndex), 2)
 	if err != nil {
 		return fixed.Rectangle26_6{}, 0, err
 	}