From bb775957cbd02e9bb92a67c717b4205ee7a82aa4 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 17 Oct 2013 10:21:20 +1100 Subject: [PATCH] freetype/truetype: propagate the useMyMetrics flag to nested components. Also increase the maximum recursion depth from 4 to 8, since some x-deja-vu-sans-oblique glyphs are actually depth 4. It's an arbitrary limit. The C Freetype code doesn't seem to limit recursion (below whatever the font says it needs), but it seems safer to have a limit. R=bsiegert CC=golang-dev https://codereview.appspot.com/14494062 --- freetype/truetype/glyph.go | 10 ++++++---- freetype/truetype/truetype_test.go | 4 +--- 2 files changed, 7 insertions(+), 7 deletions(-) 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}, }