提交 c3fc3971 编写于 作者: N Nigel Tao

freetype/truetype: refactor dispatch for high opcodes.

Also delete "q means that that opcode is not yet implemented", as all
valid opcodes are now implemented.

R=bsiegert
CC=golang-codereviews
https://codereview.appspot.com/53050044
上级 39b01678
......@@ -195,9 +195,6 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
return errors.New("truetype: hinting: too many steps")
}
opcode = program[pc]
if popCount[opcode] == q {
return errors.New("truetype: hinting: unimplemented instruction")
}
if top < int(popCount[opcode]) {
return errors.New("truetype: hinting: stack underflow")
}
......@@ -1115,27 +1112,24 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
// freetype-go does not support rotated or stretched glyphs.
top -= 2
case opPUSHB000, opPUSHB001, opPUSHB010, opPUSHB011,
opPUSHB100, opPUSHB101, opPUSHB110, opPUSHB111:
opcode -= opPUSHB000 - 1
goto push
default:
if opcode < opPUSHB000 {
return errors.New("truetype: hinting: unrecognized instruction")
}
case opPUSHW000, opPUSHW001, opPUSHW010, opPUSHW011,
opPUSHW100, opPUSHW101, opPUSHW110, opPUSHW111:
if opcode < opMDRP00000 {
// PUSHxxxx opcode.
opcode -= opPUSHW000 - 1
opcode += 0x80
if opcode < opPUSHW000 {
opcode -= opPUSHB000 - 1
} else {
opcode -= opPUSHW000 - 1 - 0x80
}
goto push
}
case opMDRP00000, opMDRP00001, opMDRP00010, opMDRP00011,
opMDRP00100, opMDRP00101, opMDRP00110, opMDRP00111,
opMDRP01000, opMDRP01001, opMDRP01010, opMDRP01011,
opMDRP01100, opMDRP01101, opMDRP01110, opMDRP01111,
opMDRP10000, opMDRP10001, opMDRP10010, opMDRP10011,
opMDRP10100, opMDRP10101, opMDRP10110, opMDRP10111,
opMDRP11000, opMDRP11001, opMDRP11010, opMDRP11011,
opMDRP11100, opMDRP11101, opMDRP11110, opMDRP11111:
if opcode < opMIRP00000 {
// MDRPxxxxx opcode.
top--
i := h.stack[top]
......@@ -1197,14 +1191,8 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
oldDist = dotProduct(f26dot6(p.X-ref.X), f26dot6(p.Y-ref.Y), h.gs.pv)
h.move(p, distance-oldDist, true)
case opMIRP00000, opMIRP00001, opMIRP00010, opMIRP00011,
opMIRP00100, opMIRP00101, opMIRP00110, opMIRP00111,
opMIRP01000, opMIRP01001, opMIRP01010, opMIRP01011,
opMIRP01100, opMIRP01101, opMIRP01110, opMIRP01111,
opMIRP10000, opMIRP10001, opMIRP10010, opMIRP10011,
opMIRP10100, opMIRP10101, opMIRP10110, opMIRP10111,
opMIRP11000, opMIRP11001, opMIRP11010, opMIRP11011,
opMIRP11100, opMIRP11101, opMIRP11110, opMIRP11111:
} else {
// MIRPxxxxx opcode.
top -= 2
i := h.stack[top]
......@@ -1276,9 +1264,7 @@ func (h *Hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
// Move the point.
h.move(p, distance-curDist, true)
default:
return errors.New("truetype: hinting: unrecognized instruction")
}
}
pc++
continue
......
......@@ -278,15 +278,12 @@ var popCount = [256]uint8{
2, 2, 2, 2, 2, 2, 1, 1, 1, 0, 2, 2, 1, 1, 1, 1, // 0x50 - 0x5f
2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6f
2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 0, 0, 0, 1, 1, // 0x70 - 0x7f
0, 2, 2, 0, 0, 1, 2, 2, 1, 1, 3, 2, 2, 1, 2, q, // 0x80 - 0x8f
q, q, q, q, q, q, q, q, q, q, q, q, q, q, q, q, // 0x90 - 0x9f
q, q, q, q, q, q, q, q, q, q, q, q, q, q, q, q, // 0xa0 - 0xaf
0, 2, 2, 0, 0, 1, 2, 2, 1, 1, 3, 2, 2, 1, 2, 0, // 0x80 - 0x8f
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x90 - 0x9f
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xa0 - 0xaf
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xb0 - 0xbf
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xc0 - 0xcf
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xd0 - 0xdf
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xe0 - 0xef
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xf0 - 0xff
}
// popCount[opcode] == q means that that opcode is not yet implemented.
const q = 255
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册