From e1f638ef1d4464b97df985b7de2c2d520693233d Mon Sep 17 00:00:00 2001 From: R?my Oudompheng Date: Tue, 22 Oct 2013 17:13:52 +1100 Subject: [PATCH] freetype/truetype: fix IP rounding for negative numbers. Found in Adobe Source Sans Pro. R=golang-dev, bsiegert, nigeltao CC=golang-dev https://codereview.appspot.com/15360043 Committer: Nigel Tao --- freetype/truetype/hint.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/freetype/truetype/hint.go b/freetype/truetype/hint.go index 955b36b..df7745a 100644 --- a/freetype/truetype/hint.go +++ b/freetype/truetype/hint.go @@ -472,7 +472,9 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point, p = h.point(1, current, h.gs.rp[2]) curP := h.point(0, current, h.gs.rp[1]) curRange := dotProduct(f26dot6(p.X-curP.X), f26dot6(p.Y-curP.Y), h.gs.pv) - + if oldRange < 0 { + oldRange, curRange = -oldRange, -curRange + } for ; h.gs.loop != 0; h.gs.loop-- { top-- i := h.stack[top] @@ -483,8 +485,14 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point, newDist := f26dot6(0) if oldDist != 0 { if oldRange != 0 { - newDist = f26dot6( - (int64(oldDist)*int64(curRange) + int64(oldRange/2)) / int64(oldRange)) + // Compute and round oldDist * curRange / oldRange. + x := int64(oldDist) * int64(curRange) + if x < 0 { + x -= int64(oldRange) / 2 + } else { + x += int64(oldRange) / 2 + } + newDist = f26dot6(x / int64(oldRange)) } else { newDist = -oldDist }