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
This commit is contained in:
Nigel Tao 2013-10-17 10:21:20 +11:00
parent 8373bbf0e6
commit bb775957cb
2 changed files with 7 additions and 7 deletions

View File

@ -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 {

View File

@ -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},
}