mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 13:56:32 +08:00
1 parent
28175723e6
commit
32585c6343
46 files changed
+84
-168
No files matched your search
@@ -916,70 +916,6 @@ func getCFFIndexData(data []byte, offset int) ([]byte, int) {
|
||||
return data[base : base+off1-1], end - offset
|
||||
}
|
||||
|
||||
// readCFFIndexItems 读取CFF索引中的所有数据项
|
||||
// 入参: data CFF数据, offset 索引偏移
|
||||
// 返回: [][]byte 数据项列表
|
||||
func readCFFIndexItems(data []byte, offset int) [][]byte {
|
||||
items, _, _ := readType2Index(data, offset)
|
||||
return items
|
||||
}
|
||||
|
||||
// parseCFFFDSelect 解析CID CFF的FDSelect
|
||||
// 入参: data CFF数据, offset FDSelect偏移, numGlyphs 字形数量
|
||||
// 返回: []int 字形对应的FD索引
|
||||
func parseCFFFDSelect(data []byte, offset int, numGlyphs int) []int {
|
||||
result := make([]int, numGlyphs)
|
||||
if offset <= 0 || offset >= len(data) {
|
||||
return result
|
||||
}
|
||||
format := data[offset]
|
||||
pos := offset + 1
|
||||
switch format {
|
||||
case 0:
|
||||
for i := 0; i < numGlyphs && pos+i < len(data); i++ {
|
||||
result[i] = int(data[pos+i])
|
||||
}
|
||||
case 3:
|
||||
if pos+2 > len(data) {
|
||||
return result
|
||||
}
|
||||
nRanges := int(binary.BigEndian.Uint16(data[pos:]))
|
||||
pos += 2
|
||||
ranges := make([]struct {
|
||||
first int
|
||||
fd int
|
||||
}, 0, nRanges)
|
||||
for i := 0; i < nRanges && pos+3 <= len(data); i++ {
|
||||
first := int(binary.BigEndian.Uint16(data[pos:]))
|
||||
fd := int(data[pos+2])
|
||||
ranges = append(ranges, struct {
|
||||
first int
|
||||
fd int
|
||||
}{first: first, fd: fd})
|
||||
pos += 3
|
||||
}
|
||||
if pos+2 > len(data) {
|
||||
return result
|
||||
}
|
||||
sentinel := int(binary.BigEndian.Uint16(data[pos:]))
|
||||
for i, item := range ranges {
|
||||
end := sentinel
|
||||
if i+1 < len(ranges) {
|
||||
end = ranges[i+1].first
|
||||
}
|
||||
if end > numGlyphs {
|
||||
end = numGlyphs
|
||||
}
|
||||
for gid := item.first; gid < end; gid++ {
|
||||
if gid >= 0 && gid < numGlyphs {
|
||||
result[gid] = item.fd
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// cffSubrBias 获取Type2子程序偏移
|
||||
// 入参: count 子程序数量
|
||||
// 返回: int 偏移量
|
||||
|
||||
Reference in new issue
Block a user