feat(字体处理): 优化字体压缩,降低裁剪开销
build.yaml / build (push) Successful in 43s

This commit is contained in:
xiaoqidun committed 2026-10-11 01:36:50 +08:00
1 parent 62c81e7061
commit 226688bbdc
2 files changed
+33 -5

No files matched your search

+8 -1
View File
@@ -55,6 +55,8 @@ type type2State struct {
seed uint64
steps *int
dependencies map[uint16]bool
localUsage []bool
globalUsage []bool
}
// readType2Index 读取并校验CFF索引的全部偏移,不复制程序字节
@@ -336,13 +338,18 @@ func (s *type2State) run(data []byte, depth int) (bool, error) {
value := s.args[len(s.args)-1]
s.args = s.args[:len(s.args)-1]
subrs := s.font.locals
usage := s.localUsage
if op == 29 {
subrs = s.font.globals
usage = s.globalUsage
}
value += float64(cffSubrBias(len(subrs)))
if value < 0 || value >= float64(len(subrs)) || value != math.Trunc(value) {
return false, fmt.Errorf("invalid Type2 subroutine number")
}
if usage != nil {
usage[int(value)] = true
}
ended, err := s.run(subrs[int(value)], depth+1)
if ended || err != nil {
return ended, err
@@ -503,7 +510,7 @@ func (s *type2State) appendComponent(code, x, y float64) error {
if s.dependencies != nil {
s.dependencies[uint16(gid)] = true
}
child := type2State{font: s.font, matrix: s.matrix, width: s.font.def, component: true, output: s.output, originX: x, originY: y, outX: s.outX, outY: s.outY, seed: s.font.seed + uint64(gid), steps: s.steps, stripHints: s.stripHints, dependencies: s.dependencies}
child := type2State{font: s.font, matrix: s.matrix, width: s.font.def, component: true, output: s.output, originX: x, originY: y, outX: s.outX, outY: s.outY, seed: s.font.seed + uint64(gid), steps: s.steps, stripHints: s.stripHints, dependencies: s.dependencies, localUsage: s.localUsage, globalUsage: s.globalUsage}
_, err := child.run(s.font.chars[gid], 0)
if err != nil {
return fmt.Errorf("invalid Type2 component %s: %w", name, err)