diff --git a/freetype/truetype/glyph.go b/freetype/truetype/glyph.go index a3bed71..90f40b4 100644 --- a/freetype/truetype/glyph.go +++ b/freetype/truetype/glyph.go @@ -94,7 +94,8 @@ func (g *GlyphBuf) Load(f *Font, scale int32, i Index, h *Hinter) error { } func (g *GlyphBuf) load(recursion int32, i Index, useMyMetrics bool) (err error) { - if recursion >= 4 { + // The recursion limit here is arbitrary, but defends against malformed glyphs. + if recursion >= 32 { return UnsupportedError("excessive compound glyph recursion") } // Find the relevant slice of g.font.glyf. @@ -126,7 +127,7 @@ func (g *GlyphBuf) load(recursion int32, i Index, useMyMetrics bool) (err error) return UnsupportedError("negative number of contours") } pp1x = g.font.scale(g.scale * (b.XMin - uhm.LeftSideBearing)) - if err := g.loadCompound(recursion, glyf); err != nil { + if err := g.loadCompound(recursion, glyf, useMyMetrics); err != nil { return err } } else { @@ -267,7 +268,7 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) { return program } -func (g *GlyphBuf) loadCompound(recursion int32, glyf []byte) error { +func (g *GlyphBuf) loadCompound(recursion int32, glyf []byte, useMyMetrics bool) error { // Flags for decoding a compound glyph. These flags are documented at // http://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html. const ( @@ -319,7 +320,8 @@ func (g *GlyphBuf) loadCompound(recursion int32, glyf []byte) error { } } np0 := len(g.Point) - if err := g.load(recursion+1, component, flags&flagUseMyMetrics != 0); err != nil { + componentUMM := useMyMetrics && (flags&flagUseMyMetrics != 0) + if err := g.load(recursion+1, component, componentUMM); err != nil { return err } if hasTransform { diff --git a/freetype/truetype/truetype_test.go b/freetype/truetype/truetype_test.go index 3f33e04..1b63fd1 100644 --- a/freetype/truetype/truetype_test.go +++ b/freetype/truetype/truetype_test.go @@ -252,10 +252,8 @@ var scalingTestCases = []struct { hintingBrokenAt int }{ {"luxisr", 12, -1}, - // TODO: uncomment the fonts below, once they get past Parse and - // GlyphBuf.Load, and the unhinted values match C Freetype. {"x-arial-bold", 11, 0}, - //{"x-deja-vu-sans-oblique", 17, 0}, + {"x-deja-vu-sans-oblique", 17, 0}, {"x-droid-sans-japanese", 9, 0}, {"x-times-new-roman", 13, 0}, }