From cce54f9bf8de8d0746aa9633ad2ef50a90e76810 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 26 Nov 2013 20:06:51 +1100 Subject: [PATCH] freetype/truetype: fix order of 1st phantom point adjustment and 2nd / 4th phantom point rounding. R=bsiegert CC=golang-dev, remyoudompheng https://codereview.appspot.com/32040043 --- freetype/truetype/glyph.go | 27 +++++++++++++-------------- freetype/truetype/truetype_test.go | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/freetype/truetype/glyph.go b/freetype/truetype/glyph.go index 265ce08..6f59af2 100644 --- a/freetype/truetype/glyph.go +++ b/freetype/truetype/glyph.go @@ -137,7 +137,8 @@ func (g *GlyphBuf) load(recursion int32, i Index, useMyMetrics bool) (err error) } else { np0, ne0 := len(g.Point), len(g.End) program := g.loadSimple(glyf, ne) - g.addPhantomsAndScale(b, uhm, i, np0, g.hinter != nil) + g.addPhantomsAndScale(b, uhm, i, np0, true) + pp1x = g.Point[len(g.Point)-4].X if g.hinter != nil { if len(program) != 0 { err := g.hinter.run( @@ -151,16 +152,7 @@ func (g *GlyphBuf) load(recursion int32, i Index, useMyMetrics bool) (err error) return err } } - } - // Drop the four phantom points. - pp1x = g.Point[len(g.Point)-4].X - if g.hinter != nil { - if dx := ((pp1x + 32) &^ 63) - pp1x; dx != 0 { - for i := np0; i < len(g.Point); i++ { - g.Point[i].X += dx - } - pp1x = g.Point[len(g.Point)-4].X - } + // Drop the four phantom points. g.InFontUnits = g.InFontUnits[:len(g.InFontUnits)-4] g.Unhinted = g.Unhinted[:len(g.Unhinted)-4] } @@ -383,7 +375,7 @@ func (g *GlyphBuf) loadCompound(recursion int32, b Bounds, uhm HMetric, i Index, return nil } -func (g *GlyphBuf) addPhantomsAndScale(b Bounds, uhm HMetric, i Index, np0 int, appendOther bool) { +func (g *GlyphBuf) addPhantomsAndScale(b Bounds, uhm HMetric, i Index, np0 int, simple bool) { // Add the four phantom points. uvm := g.font.unscaledVMetric(i) g.Point = append(g.Point, @@ -393,7 +385,7 @@ func (g *GlyphBuf) addPhantomsAndScale(b Bounds, uhm HMetric, i Index, np0 int, Point{Y: b.YMax + uvm.TopSideBearing - uvm.AdvanceHeight}, ) // Scale the points. - if appendOther { + if simple && g.hinter != nil { g.InFontUnits = append(g.InFontUnits, g.Point[np0:]...) } for i := np0; i < len(g.Point); i++ { @@ -401,8 +393,15 @@ func (g *GlyphBuf) addPhantomsAndScale(b Bounds, uhm HMetric, i Index, np0 int, p.X = g.font.scale(g.scale * p.X) p.Y = g.font.scale(g.scale * p.Y) } - if appendOther { + if simple && g.hinter != nil { g.Unhinted = append(g.Unhinted, g.Point[np0:]...) + // Round the 1st phantom point to the grid, shifting all other points equally. + pp1x := g.Point[len(g.Point)-4].X + if dx := ((pp1x + 32) &^ 63) - pp1x; dx != 0 { + for i := np0; i < len(g.Point); i++ { + g.Point[i].X += dx + } + } } // Round the 2nd and 4th phantom point to the grid. p := &g.Point[len(g.Point)-3] diff --git a/freetype/truetype/truetype_test.go b/freetype/truetype/truetype_test.go index fd5d0d8..e52f8cf 100644 --- a/freetype/truetype/truetype_test.go +++ b/freetype/truetype/truetype_test.go @@ -255,7 +255,7 @@ var scalingTestCases = []struct { hintingBrokenAt int }{ {"luxisr", 12, -1}, - {"x-arial-bold", 11, 1}, + {"x-arial-bold", 11, 17}, {"x-deja-vu-sans-oblique", 17, -1}, {"x-droid-sans-japanese", 9, 0}, {"x-times-new-roman", 13, 0},