Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小雨青年
freetype
提交
7e2154db
F
freetype
项目概览
小雨青年
/
freetype
通知
14
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
freetype
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7e2154db
编写于
8月 18, 2015
作者:
N
Nigel Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Delete the f26dot6 type in favor of fixed.Int26_6.
上级
43fc220e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
67 deletion
+64
-67
truetype/hint.go
truetype/hint.go
+64
-67
未找到文件。
truetype/hint.go
浏览文件 @
7e2154db
...
...
@@ -63,7 +63,7 @@ type hinter struct {
// scaledCVT is the lazily initialized scaled Control Value Table.
scaledCVTInitialized
bool
scaledCVT
[]
f
26dot
6
scaledCVT
[]
f
ixed
.
Int26_
6
}
// graphicsState is described at https://developer.apple.com/fonts/TTRefMan/RM04/Chap4.html
...
...
@@ -73,15 +73,15 @@ type graphicsState struct {
// Reference points and zone pointers.
rp
,
zp
[
3
]
int32
// Control Value / Single Width Cut-In.
controlValueCutIn
,
singleWidthCutIn
,
singleWidth
f
26dot
6
controlValueCutIn
,
singleWidthCutIn
,
singleWidth
f
ixed
.
Int26_
6
// Delta base / shift.
deltaBase
,
deltaShift
int32
// Minimum distance.
minDist
f
26dot
6
minDist
f
ixed
.
Int26_
6
// Loop count.
loop
int32
// Rounding policy.
roundPeriod
,
roundPhase
,
roundThreshold
f
26dot
6
roundPeriod
,
roundPhase
,
roundThreshold
f
ixed
.
Int26_
6
roundSuper45
bool
// Auto-flip.
autoFlip
bool
...
...
@@ -92,13 +92,13 @@ var globalDefaultGS = graphicsState{
fv
:
[
2
]
f2dot14
{
0x4000
,
0
},
dv
:
[
2
]
f2dot14
{
0x4000
,
0
},
zp
:
[
3
]
int32
{
1
,
1
,
1
},
controlValueCutIn
:
(
17
<<
6
)
/
16
,
// 17/16 as a
n f26dot
6.
controlValueCutIn
:
(
17
<<
6
)
/
16
,
// 17/16 as a
fixed.Int26_
6.
deltaBase
:
9
,
deltaShift
:
3
,
minDist
:
1
<<
6
,
// 1 as a
n f26dot
6.
minDist
:
1
<<
6
,
// 1 as a
fixed.Int26_
6.
loop
:
1
,
roundPeriod
:
1
<<
6
,
// 1 as a
n f26dot
6.
roundThreshold
:
1
<<
5
,
// 1/2 as a
n f26dot
6.
roundPeriod
:
1
<<
6
,
// 1 as a
fixed.Int26_
6.
roundThreshold
:
1
<<
5
,
// 1/2 as a
fixed.Int26_
6.
roundSuper45
:
false
,
autoFlip
:
true
,
}
...
...
@@ -360,7 +360,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
case
opSMD
:
top
--
h
.
gs
.
minDist
=
f
26dot
6
(
h
.
stack
[
top
])
h
.
gs
.
minDist
=
f
ixed
.
Int26_
6
(
h
.
stack
[
top
])
case
opELSE
:
opcode
=
1
...
...
@@ -373,15 +373,15 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
case
opSCVTCI
:
top
--
h
.
gs
.
controlValueCutIn
=
f
26dot
6
(
h
.
stack
[
top
])
h
.
gs
.
controlValueCutIn
=
f
ixed
.
Int26_
6
(
h
.
stack
[
top
])
case
opSSWCI
:
top
--
h
.
gs
.
singleWidthCutIn
=
f
26dot
6
(
h
.
stack
[
top
])
h
.
gs
.
singleWidthCutIn
=
f
ixed
.
Int26_
6
(
h
.
stack
[
top
])
case
opSSW
:
top
--
h
.
gs
.
singleWidth
=
f26dot6
(
h
.
font
.
scale
(
h
.
scale
*
fixed
.
Int26_6
(
h
.
stack
[
top
])
))
h
.
gs
.
singleWidth
=
h
.
font
.
scale
(
h
.
scale
*
fixed
.
Int26_6
(
h
.
stack
[
top
]
))
case
opDUP
:
if
top
>=
len
(
h
.
stack
)
{
...
...
@@ -424,7 +424,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
p
==
nil
||
q
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
d
:=
dotProduct
(
f
26dot6
(
q
.
X
-
p
.
X
),
f26dot
6
(
q
.
Y
-
p
.
Y
),
h
.
gs
.
pv
)
/
2
d
:=
dotProduct
(
f
ixed
.
Int26_6
(
q
.
X
-
p
.
X
),
fixed
.
Int26_
6
(
q
.
Y
-
p
.
Y
),
h
.
gs
.
pv
)
/
2
h
.
move
(
p
,
+
d
,
true
)
h
.
move
(
q
,
-
d
,
true
)
...
...
@@ -502,9 +502,9 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
p
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
distance
:=
f
26dot
6
(
0
)
distance
:=
f
ixed
.
Int26_
6
(
0
)
if
opcode
==
opMDAP1
{
distance
=
dotProduct
(
f26dot6
(
p
.
X
),
f26dot6
(
p
.
Y
)
,
h
.
gs
.
pv
)
distance
=
dotProduct
(
p
.
X
,
p
.
Y
,
h
.
gs
.
pv
)
// TODO: metrics compensation.
distance
=
h
.
round
(
distance
)
-
distance
}
...
...
@@ -610,7 +610,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
case
opSHPIX
:
top
--
d
:=
f
26dot
6
(
h
.
stack
[
top
])
d
:=
f
ixed
.
Int26_
6
(
h
.
stack
[
top
])
if
top
<
int
(
h
.
gs
.
loop
)
{
return
errors
.
New
(
"truetype: hinting: stack underflow"
)
}
...
...
@@ -635,22 +635,22 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
}
p
:=
h
.
point
(
1
,
pointType
,
h
.
gs
.
rp
[
2
])
oldP
:=
h
.
point
(
0
,
pointType
,
h
.
gs
.
rp
[
1
])
oldRange
:=
dotProduct
(
f26dot6
(
p
.
X
-
oldP
.
X
),
f26dot6
(
p
.
Y
-
oldP
.
Y
)
,
h
.
gs
.
dv
)
oldRange
:=
dotProduct
(
p
.
X
-
oldP
.
X
,
p
.
Y
-
oldP
.
Y
,
h
.
gs
.
dv
)
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
)
curRange
:=
dotProduct
(
p
.
X
-
curP
.
X
,
p
.
Y
-
curP
.
Y
,
h
.
gs
.
pv
)
for
;
h
.
gs
.
loop
!=
0
;
h
.
gs
.
loop
--
{
top
--
i
:=
h
.
stack
[
top
]
p
=
h
.
point
(
2
,
pointType
,
i
)
oldDist
:=
dotProduct
(
f26dot6
(
p
.
X
-
oldP
.
X
),
f26dot6
(
p
.
Y
-
oldP
.
Y
)
,
h
.
gs
.
dv
)
oldDist
:=
dotProduct
(
p
.
X
-
oldP
.
X
,
p
.
Y
-
oldP
.
Y
,
h
.
gs
.
dv
)
p
=
h
.
point
(
2
,
current
,
i
)
curDist
:=
dotProduct
(
f26dot6
(
p
.
X
-
curP
.
X
),
f26dot6
(
p
.
Y
-
curP
.
Y
)
,
h
.
gs
.
pv
)
newDist
:=
f
26dot
6
(
0
)
curDist
:=
dotProduct
(
p
.
X
-
curP
.
X
,
p
.
Y
-
curP
.
Y
,
h
.
gs
.
pv
)
newDist
:=
f
ixed
.
Int26_
6
(
0
)
if
oldDist
!=
0
{
if
oldRange
!=
0
{
newDist
=
f
26dot
6
(
mulDiv
(
int64
(
oldDist
),
int64
(
curRange
),
int64
(
oldRange
)))
newDist
=
f
ixed
.
Int26_
6
(
mulDiv
(
int64
(
oldDist
),
int64
(
curRange
),
int64
(
oldRange
)))
}
else
{
newDist
=
-
oldDist
}
...
...
@@ -662,7 +662,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
case
opMSIRP0
,
opMSIRP1
:
top
-=
2
i
:=
h
.
stack
[
top
]
distance
:=
f
26dot
6
(
h
.
stack
[
top
+
1
])
distance
:=
f
ixed
.
Int26_
6
(
h
.
stack
[
top
+
1
])
// TODO: special case h.gs.zp[1] == 0 in C Freetype.
ref
:=
h
.
point
(
0
,
current
,
h
.
gs
.
rp
[
0
])
...
...
@@ -670,7 +670,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
ref
==
nil
||
p
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
curDist
:=
dotProduct
(
f26dot6
(
p
.
X
-
ref
.
X
),
f26dot6
(
p
.
Y
-
ref
.
Y
)
,
h
.
gs
.
pv
)
curDist
:=
dotProduct
(
p
.
X
-
ref
.
X
,
p
.
Y
-
ref
.
Y
,
h
.
gs
.
pv
)
// Set-RP0 bit.
if
opcode
==
opMSIRP1
{
...
...
@@ -696,7 +696,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
p
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
h
.
move
(
p
,
-
dotProduct
(
f26dot6
(
p
.
X
-
ref
.
X
),
f26dot6
(
p
.
Y
-
ref
.
Y
)
,
h
.
gs
.
pv
),
true
)
h
.
move
(
p
,
-
dotProduct
(
p
.
X
-
ref
.
X
,
p
.
Y
-
ref
.
Y
,
h
.
gs
.
pv
),
true
)
}
h
.
gs
.
loop
=
1
...
...
@@ -718,7 +718,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
*
q
=
*
p
}
p
:=
h
.
point
(
0
,
current
,
i
)
oldDist
:=
dotProduct
(
f26dot6
(
p
.
X
),
f26dot6
(
p
.
Y
)
,
h
.
gs
.
pv
)
oldDist
:=
dotProduct
(
p
.
X
,
p
.
Y
,
h
.
gs
.
pv
)
if
opcode
==
opMIAP1
{
if
fabs
(
distance
-
oldDist
)
>
h
.
gs
.
controlValueCutIn
{
distance
=
oldDist
...
...
@@ -755,7 +755,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
case
opWCVTP
:
top
-=
2
h
.
setScaledCVT
(
h
.
stack
[
top
],
f
26dot
6
(
h
.
stack
[
top
+
1
]))
h
.
setScaledCVT
(
h
.
stack
[
top
],
f
ixed
.
Int26_
6
(
h
.
stack
[
top
+
1
]))
case
opRCVT
:
h
.
stack
[
top
-
1
]
=
int32
(
h
.
getScaledCVT
(
h
.
stack
[
top
-
1
]))
...
...
@@ -764,11 +764,11 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
i
:=
h
.
stack
[
top
-
1
]
if
opcode
==
opGC0
{
p
:=
h
.
point
(
2
,
current
,
i
)
h
.
stack
[
top
-
1
]
=
int32
(
dotProduct
(
f26dot6
(
p
.
X
),
f26dot6
(
p
.
Y
)
,
h
.
gs
.
pv
))
h
.
stack
[
top
-
1
]
=
int32
(
dotProduct
(
p
.
X
,
p
.
Y
,
h
.
gs
.
pv
))
}
else
{
p
:=
h
.
point
(
2
,
unhinted
,
i
)
// Using dv as per C Freetype.
h
.
stack
[
top
-
1
]
=
int32
(
dotProduct
(
f26dot6
(
p
.
X
),
f26dot6
(
p
.
Y
)
,
h
.
gs
.
dv
))
h
.
stack
[
top
-
1
]
=
int32
(
dotProduct
(
p
.
X
,
p
.
Y
,
h
.
gs
.
dv
))
}
case
opSCFS
:
...
...
@@ -778,8 +778,8 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
p
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
c
:=
dotProduct
(
f26dot6
(
p
.
X
),
f26dot6
(
p
.
Y
)
,
h
.
gs
.
pv
)
h
.
move
(
p
,
f
26dot
6
(
h
.
stack
[
top
+
1
])
-
c
,
true
)
c
:=
dotProduct
(
p
.
X
,
p
.
Y
,
h
.
gs
.
pv
)
h
.
move
(
p
,
f
ixed
.
Int26_
6
(
h
.
stack
[
top
+
1
])
-
c
,
true
)
if
h
.
gs
.
zp
[
2
]
!=
0
{
break
}
...
...
@@ -809,7 +809,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
p
==
nil
||
q
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
d
:=
int32
(
dotProduct
(
f26dot6
(
p
.
X
-
q
.
X
),
f26dot6
(
p
.
Y
-
q
.
Y
)
,
v
))
d
:=
int32
(
dotProduct
(
p
.
X
-
q
.
X
,
p
.
Y
-
q
.
Y
,
v
))
if
scale
{
d
=
int32
(
int64
(
d
*
int32
(
h
.
scale
))
/
int64
(
h
.
font
.
fUnitsPerEm
))
}
...
...
@@ -854,7 +854,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
h
.
stack
[
top
-
1
]
=
bool2int32
(
h
.
stack
[
top
-
1
]
!=
h
.
stack
[
top
])
case
opODD
,
opEVEN
:
i
:=
h
.
round
(
f
26dot
6
(
h
.
stack
[
top
-
1
]))
>>
6
i
:=
h
.
round
(
f
ixed
.
Int26_
6
(
h
.
stack
[
top
-
1
]))
>>
6
h
.
stack
[
top
-
1
]
=
int32
(
i
&
1
)
^
int32
(
opcode
-
opODD
)
case
opIF
:
...
...
@@ -902,11 +902,11 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
h
.
stack
[
top
]
==
0
{
return
errors
.
New
(
"truetype: hinting: division by zero"
)
}
h
.
stack
[
top
-
1
]
=
int32
(
fdiv
(
f
26dot6
(
h
.
stack
[
top
-
1
]),
f26dot
6
(
h
.
stack
[
top
])))
h
.
stack
[
top
-
1
]
=
int32
(
fdiv
(
f
ixed
.
Int26_6
(
h
.
stack
[
top
-
1
]),
fixed
.
Int26_
6
(
h
.
stack
[
top
])))
case
opMUL
:
top
--
h
.
stack
[
top
-
1
]
=
int32
(
fmul
(
f
26dot6
(
h
.
stack
[
top
-
1
]),
f26dot
6
(
h
.
stack
[
top
])))
h
.
stack
[
top
-
1
]
=
int32
(
fmul
(
f
ixed
.
Int26_6
(
h
.
stack
[
top
-
1
]),
fixed
.
Int26_
6
(
h
.
stack
[
top
])))
case
opABS
:
if
h
.
stack
[
top
-
1
]
<
0
{
...
...
@@ -926,7 +926,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
case
opROUND00
,
opROUND01
,
opROUND10
,
opROUND11
:
// The four flavors of opROUND are equivalent. See the comment below on
// opNROUND for the rationale.
h
.
stack
[
top
-
1
]
=
int32
(
h
.
round
(
f
26dot
6
(
h
.
stack
[
top
-
1
])))
h
.
stack
[
top
-
1
]
=
int32
(
h
.
round
(
f
ixed
.
Int26_
6
(
h
.
stack
[
top
-
1
])))
case
opNROUND00
,
opNROUND01
,
opNROUND10
,
opNROUND11
:
// No-op. The spec says to add one of four "compensations for the engine
...
...
@@ -937,7 +937,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
case
opWCVTF
:
top
-=
2
h
.
setScaledCVT
(
h
.
stack
[
top
],
f26dot6
(
h
.
font
.
scale
(
h
.
scale
*
fixed
.
Int26_6
(
h
.
stack
[
top
+
1
])
)))
h
.
setScaledCVT
(
h
.
stack
[
top
],
h
.
font
.
scale
(
h
.
scale
*
fixed
.
Int26_6
(
h
.
stack
[
top
+
1
]
)))
case
opDELTAP2
,
opDELTAP3
,
opDELTAC1
,
opDELTAC2
,
opDELTAC3
:
goto
delta
...
...
@@ -959,9 +959,9 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
h
.
gs
.
roundPeriod
*=
46341
h
.
gs
.
roundPeriod
/=
65536
}
h
.
gs
.
roundPhase
=
h
.
gs
.
roundPeriod
*
f
26dot
6
((
h
.
stack
[
top
]
>>
4
)
&
0x03
)
/
4
h
.
gs
.
roundPhase
=
h
.
gs
.
roundPeriod
*
f
ixed
.
Int26_
6
((
h
.
stack
[
top
]
>>
4
)
&
0x03
)
/
4
if
x
:=
h
.
stack
[
top
]
&
0x0f
;
x
!=
0
{
h
.
gs
.
roundThreshold
=
h
.
gs
.
roundPeriod
*
f
26dot
6
(
x
-
4
)
/
8
h
.
gs
.
roundThreshold
=
h
.
gs
.
roundPeriod
*
f
ixed
.
Int26_
6
(
x
-
4
)
/
8
}
else
{
h
.
gs
.
roundThreshold
=
h
.
gs
.
roundPeriod
-
1
}
...
...
@@ -1137,16 +1137,16 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
oldDist
:=
f
26dot
6
(
0
)
oldDist
:=
f
ixed
.
Int26_
6
(
0
)
if
h
.
gs
.
zp
[
0
]
==
0
||
h
.
gs
.
zp
[
1
]
==
0
{
p0
:=
h
.
point
(
1
,
unhinted
,
i
)
p1
:=
h
.
point
(
0
,
unhinted
,
h
.
gs
.
rp
[
0
])
oldDist
=
dotProduct
(
f26dot6
(
p0
.
X
-
p1
.
X
),
f26dot6
(
p0
.
Y
-
p1
.
Y
)
,
h
.
gs
.
dv
)
oldDist
=
dotProduct
(
p0
.
X
-
p1
.
X
,
p0
.
Y
-
p1
.
Y
,
h
.
gs
.
dv
)
}
else
{
p0
:=
h
.
point
(
1
,
inFontUnits
,
i
)
p1
:=
h
.
point
(
0
,
inFontUnits
,
h
.
gs
.
rp
[
0
])
oldDist
=
dotProduct
(
f26dot6
(
p0
.
X
-
p1
.
X
),
f26dot6
(
p0
.
Y
-
p1
.
Y
)
,
h
.
gs
.
dv
)
oldDist
=
f26dot6
(
h
.
font
.
scale
(
h
.
scale
*
fixed
.
Int26_6
(
oldDist
))
)
oldDist
=
dotProduct
(
p0
.
X
-
p1
.
X
,
p0
.
Y
-
p1
.
Y
,
h
.
gs
.
dv
)
oldDist
=
h
.
font
.
scale
(
h
.
scale
*
oldDist
)
}
// Single-width cut-in test.
...
...
@@ -1186,7 +1186,7 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
}
// Move the point.
oldDist
=
dotProduct
(
f26dot6
(
p
.
X
-
ref
.
X
),
f26dot6
(
p
.
Y
-
ref
.
Y
)
,
h
.
gs
.
pv
)
oldDist
=
dotProduct
(
p
.
X
-
ref
.
X
,
p
.
Y
-
ref
.
Y
,
h
.
gs
.
pv
)
h
.
move
(
p
,
distance
-
oldDist
,
true
)
}
else
{
...
...
@@ -1214,14 +1214,14 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
ref
==
nil
||
p
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
oldDist
:=
dotProduct
(
f26dot6
(
p
.
X
-
ref
.
X
),
f26dot6
(
p
.
Y
-
ref
.
Y
)
,
h
.
gs
.
dv
)
oldDist
:=
dotProduct
(
p
.
X
-
ref
.
X
,
p
.
Y
-
ref
.
Y
,
h
.
gs
.
dv
)
ref
=
h
.
point
(
0
,
current
,
h
.
gs
.
rp
[
0
])
p
=
h
.
point
(
1
,
current
,
i
)
if
ref
==
nil
||
p
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
curDist
:=
dotProduct
(
f26dot6
(
p
.
X
-
ref
.
X
),
f26dot6
(
p
.
Y
-
ref
.
Y
)
,
h
.
gs
.
pv
)
curDist
:=
dotProduct
(
p
.
X
-
ref
.
X
,
p
.
Y
-
ref
.
Y
,
h
.
gs
.
pv
)
if
h
.
gs
.
autoFlip
&&
oldDist
^
cvtDist
<
0
{
cvtDist
=
-
cvtDist
...
...
@@ -1373,13 +1373,13 @@ func (h *hinter) run(program []byte, pCurrent, pUnhinted, pInFontUnits []Point,
if
a
<
0
||
len
(
h
.
scaledCVT
)
<=
int
(
a
)
{
return
errors
.
New
(
"truetype: hinting: index out of range"
)
}
h
.
scaledCVT
[
a
]
+=
f
26dot
6
(
b
)
h
.
scaledCVT
[
a
]
+=
f
ixed
.
Int26_
6
(
b
)
}
else
{
p
:=
h
.
point
(
0
,
current
,
h
.
stack
[
top
+
1
])
if
p
==
nil
{
return
errors
.
New
(
"truetype: hinting: point out of range"
)
}
h
.
move
(
p
,
f
26dot
6
(
b
),
true
)
h
.
move
(
p
,
f
ixed
.
Int26_
6
(
b
),
true
)
}
}
pc
++
...
...
@@ -1397,16 +1397,16 @@ func (h *hinter) initializeScaledCVT() {
if
n
<
32
{
n
=
32
}
h
.
scaledCVT
=
make
([]
f
26dot
6
,
len
(
h
.
font
.
cvt
)
/
2
,
n
)
h
.
scaledCVT
=
make
([]
f
ixed
.
Int26_
6
,
len
(
h
.
font
.
cvt
)
/
2
,
n
)
}
for
i
:=
range
h
.
scaledCVT
{
unscaled
:=
uint16
(
h
.
font
.
cvt
[
2
*
i
])
<<
8
|
uint16
(
h
.
font
.
cvt
[
2
*
i
+
1
])
h
.
scaledCVT
[
i
]
=
f26dot6
(
h
.
font
.
scale
(
h
.
scale
*
fixed
.
Int26_6
(
int16
(
unscaled
)
)))
h
.
scaledCVT
[
i
]
=
h
.
font
.
scale
(
h
.
scale
*
fixed
.
Int26_6
(
int16
(
unscaled
)))
}
}
// getScaledCVT returns the scaled value from the font's Control Value Table.
func
(
h
*
hinter
)
getScaledCVT
(
i
int32
)
f
26dot
6
{
func
(
h
*
hinter
)
getScaledCVT
(
i
int32
)
f
ixed
.
Int26_
6
{
if
!
h
.
scaledCVTInitialized
{
h
.
initializeScaledCVT
()
}
...
...
@@ -1417,7 +1417,7 @@ func (h *hinter) getScaledCVT(i int32) f26dot6 {
}
// setScaledCVT overrides the scaled value from the font's Control Value Table.
func
(
h
*
hinter
)
setScaledCVT
(
i
int32
,
v
f
26dot
6
)
{
func
(
h
*
hinter
)
setScaledCVT
(
i
int32
,
v
f
ixed
.
Int26_
6
)
{
if
!
h
.
scaledCVTInitialized
{
h
.
initializeScaledCVT
()
}
...
...
@@ -1435,7 +1435,7 @@ func (h *hinter) point(zonePointer uint32, pt pointType, i int32) *Point {
return
&
points
[
i
]
}
func
(
h
*
hinter
)
move
(
p
*
Point
,
distance
f
26dot
6
,
touch
bool
)
{
func
(
h
*
hinter
)
move
(
p
*
Point
,
distance
f
ixed
.
Int26_
6
,
touch
bool
)
{
fvx
:=
int64
(
h
.
gs
.
fv
[
0
])
pvx
:=
int64
(
h
.
gs
.
pv
[
0
])
if
fvx
==
0x4000
&&
pvx
==
0x4000
{
...
...
@@ -1590,7 +1590,7 @@ func (h *hinter) iupShift(interpY bool, p1, p2, p int) {
}
}
func
(
h
*
hinter
)
displacement
(
useZP1
bool
)
(
zonePointer
uint32
,
i
int32
,
d
f
26dot
6
,
ok
bool
)
{
func
(
h
*
hinter
)
displacement
(
useZP1
bool
)
(
zonePointer
uint32
,
i
int32
,
d
f
ixed
.
Int26_
6
,
ok
bool
)
{
zonePointer
,
i
=
uint32
(
0
),
h
.
gs
.
rp
[
1
]
if
useZP1
{
zonePointer
,
i
=
1
,
h
.
gs
.
rp
[
2
]
...
...
@@ -1600,7 +1600,7 @@ func (h *hinter) displacement(useZP1 bool) (zonePointer uint32, i int32, d f26do
if
p
==
nil
||
q
==
nil
{
return
0
,
0
,
0
,
false
}
d
=
dotProduct
(
f26dot6
(
p
.
X
-
q
.
X
),
f26dot6
(
p
.
Y
-
q
.
Y
)
,
h
.
gs
.
pv
)
d
=
dotProduct
(
p
.
X
-
q
.
X
,
p
.
Y
-
q
.
Y
,
h
.
gs
.
pv
)
return
zonePointer
,
i
,
d
,
true
}
...
...
@@ -1651,11 +1651,8 @@ func normalize(x, y f2dot14) [2]f2dot14 {
return
[
2
]
f2dot14
{
f2dot14
(
fx
),
f2dot14
(
fy
)}
}
// f26dot6 is a 26.6 fixed point number.
type
f26dot6
int32
// fabs returns abs(x) in 26.6 fixed point arithmetic.
func
fabs
(
x
f
26dot6
)
f26dot
6
{
func
fabs
(
x
f
ixed
.
Int26_6
)
fixed
.
Int26_
6
{
if
x
<
0
{
return
-
x
}
...
...
@@ -1663,13 +1660,13 @@ func fabs(x f26dot6) f26dot6 {
}
// fdiv returns x/y in 26.6 fixed point arithmetic.
func
fdiv
(
x
,
y
f
26dot6
)
f26dot
6
{
return
f
26dot
6
((
int64
(
x
)
<<
6
)
/
int64
(
y
))
func
fdiv
(
x
,
y
f
ixed
.
Int26_6
)
fixed
.
Int26_
6
{
return
f
ixed
.
Int26_
6
((
int64
(
x
)
<<
6
)
/
int64
(
y
))
}
// fmul returns x*y in 26.6 fixed point arithmetic.
func
fmul
(
x
,
y
f
26dot6
)
f26dot
6
{
return
f
26dot
6
((
int64
(
x
)
*
int64
(
y
)
+
1
<<
5
)
>>
6
)
func
fmul
(
x
,
y
f
ixed
.
Int26_6
)
fixed
.
Int26_
6
{
return
f
ixed
.
Int26_
6
((
int64
(
x
)
*
int64
(
y
)
+
1
<<
5
)
>>
6
)
}
// dotProduct returns the dot product of [x, y] and q. It is almost the same as
...
...
@@ -1677,10 +1674,10 @@ func fmul(x, y f26dot6) f26dot6 {
// py := int64(y)
// qx := int64(q[0])
// qy := int64(q[1])
// return f
26dot
6((px*qx + py*qy + 1<<13) >> 14)
// return f
ixed.Int26_
6((px*qx + py*qy + 1<<13) >> 14)
// except that the computation is done with 32-bit integers to produce exactly
// the same rounding behavior as C Freetype.
func
dotProduct
(
x
,
y
f
26dot6
,
q
[
2
]
f2dot14
)
f26dot
6
{
func
dotProduct
(
x
,
y
f
ixed
.
Int26_6
,
q
[
2
]
f2dot14
)
fixed
.
Int26_
6
{
// Compute x*q[0] as 64-bit value.
l
:=
uint32
((
int32
(
x
)
&
0xFFFF
)
*
int32
(
q
[
0
]))
m
:=
(
int32
(
x
)
>>
16
)
*
int32
(
q
[
0
])
...
...
@@ -1708,7 +1705,7 @@ func dotProduct(x, y f26dot6, q [2]f2dot14) f26dot6 {
l
=
lo
+
0x2000
hi
+=
bool2int32
(
l
<
lo
)
return
f
26dot
6
((
uint32
(
hi
)
<<
18
)
|
(
l
>>
14
))
return
f
ixed
.
Int26_
6
((
uint32
(
hi
)
<<
18
)
|
(
l
>>
14
))
}
// mulDiv returns x*y/z, rounded to the nearest integer.
...
...
@@ -1727,7 +1724,7 @@ func mulDiv(x, y, z int64) int64 {
// round rounds the given number. The rounding algorithm is described at
// https://developer.apple.com/fonts/TTRefMan/RM02/Chap2.html#rounding
func
(
h
*
hinter
)
round
(
x
f
26dot6
)
f26dot
6
{
func
(
h
*
hinter
)
round
(
x
f
ixed
.
Int26_6
)
fixed
.
Int26_
6
{
if
h
.
gs
.
roundPeriod
==
0
{
// Rounding is off.
return
x
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录