From 02a88bab17807cfbdbed41e2301cebc680cbd127 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 27 Nov 2013 20:09:54 +1100 Subject: [PATCH] freetype/truetype: fix SHC, MIRP opcodes. R=bsiegert CC=golang-dev, remyoudompheng https://codereview.appspot.com/33750043 --- freetype/truetype/hint.go | 15 ++++++++++----- freetype/truetype/truetype_test.go | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/freetype/truetype/hint.go b/freetype/truetype/hint.go index 707f965..510238c 100644 --- a/freetype/truetype/hint.go +++ b/freetype/truetype/hint.go @@ -545,7 +545,7 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point, case opSHC0, opSHC1: top-- - _, _, d, ok := h.displacement(opcode&1 == 0) + zonePointer, i, d, ok := h.displacement(opcode&1 == 0) if !ok { return errors.New("truetype: hinting: point out of range") } @@ -557,12 +557,15 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point, if contour < 0 || len(ends) <= int(contour) { return errors.New("truetype: hinting: contour out of range") } - j0, j1 := 0, h.ends[contour] + j0, j1 := int32(0), int32(h.ends[contour]) if contour > 0 { - j0 = h.ends[contour-1] + j0 = int32(h.ends[contour-1]) } + move := h.gs.zp[zonePointer] != h.gs.zp[2] for j := j0; j < j1; j++ { - h.move(h.point(2, current, int32(j)), d, false) + if move || j != i { + h.move(h.point(2, current, j), d, false) + } } case opSHZ0, opSHZ1: @@ -1149,7 +1152,9 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point, distance := cvtDist if opcode&0x04 != 0 { // The CVT value is only used if close enough to oldDist. - if (cvtDist - oldDist).abs() > h.gs.controlValueCutIn { + if (h.gs.zp[0] == h.gs.zp[1]) && + ((cvtDist - oldDist).abs() > h.gs.controlValueCutIn) { + distance = oldDist } distance = h.round(distance) diff --git a/freetype/truetype/truetype_test.go b/freetype/truetype/truetype_test.go index 03f4bb4..cea20c1 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, 94}, + {"x-arial-bold", 11, 130}, {"x-deja-vu-sans-oblique", 17, -1}, {"x-droid-sans-japanese", 9, 0}, {"x-times-new-roman", 13, 0},