mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 09:37:26 +08:00
1 parent
5842522edf
commit
6dceeee194
8 files changed
+82
-19
No files matched your search
+29
-1
@@ -397,8 +397,18 @@ func sanitizeCFF(data []byte) ([]byte, error) {
|
||||
var finalPrivData []byte
|
||||
if len(privDictData) > 0 {
|
||||
pDict := parseCFFDict(privDictData)
|
||||
if err := normalizeCFFPrivate(pDict); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := pDict[19]; ok || len(localSubrData) > 0 {
|
||||
pDict[19] = []float64{float64(privateLen)}
|
||||
pDict[19] = []float64{0}
|
||||
for {
|
||||
length := len(encodeCFFDict(pDict))
|
||||
if pDict[19][0] == float64(length) {
|
||||
break
|
||||
}
|
||||
pDict[19][0] = float64(length)
|
||||
}
|
||||
}
|
||||
finalPrivData = encodeCFFDict(pDict)
|
||||
privateLen = len(finalPrivData)
|
||||
@@ -438,6 +448,21 @@ func sanitizeCFF(data []byte) ([]byte, error) {
|
||||
return newCFF.Bytes(), nil
|
||||
}
|
||||
|
||||
// normalizeCFFPrivate 移除旧版CFF中不生效的缺省字段,拒绝需要额外解释的取值
|
||||
// 入参: dict 私有字典
|
||||
// 返回: error 不支持的旧版行为
|
||||
func normalizeCFFPrivate(dict cffDict) error {
|
||||
for op, value := range map[int]float64{1215: 0, 1216: -1} {
|
||||
if values, ok := dict[op]; ok {
|
||||
if len(values) != 1 || values[0] != value {
|
||||
return fmt.Errorf("unsupported legacy CFF private operator %d", op)
|
||||
}
|
||||
delete(dict, op)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// sanitizeMultiFDCFF 清洗多FD的CID CFF数据
|
||||
// 入参: data 原始CFF数据, hdrSize 头部大小, nameIndexData 名称索引, topDict 顶层字典
|
||||
// 入参: stringIndexData 字符串索引, globalSubrIndexData 全局子程序索引, fdArrOff FDArray偏移, fdCount FD数量
|
||||
@@ -479,6 +504,9 @@ func sanitizeMultiFDCFF(data []byte, hdrSize int, nameIndexData []byte, topDict
|
||||
}
|
||||
}
|
||||
delete(privateDict, 19)
|
||||
if err := normalizeCFFPrivate(privateDict); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalPrivData := encodeCFFDict(privateDict)
|
||||
privateLen := len(finalPrivData)
|
||||
charStringsData := encodeCFFIndex(inlined)
|
||||
|
||||
Reference in new issue
Block a user