refactor(清理代码): 增加可维护性
build.yaml / build (push) Successful in 33s

This commit is contained in:
2026-07-08 15:22:05 +08:00
parent cc0a627a3c
commit 27a5da45ec
5 changed files with 0 additions and 95 deletions
-7
View File
@@ -310,13 +310,6 @@ func isFontFileName(name string) bool {
} }
} }
// fontRuleMatch 判断字体规则是否匹配
// 入参: rule 字体匹配规则, name 字体名称
// 返回: bool 是否匹配
func fontRuleMatch(rule fontMatchRule, name string) bool {
return fontRuleMatchLevel(rule, name) != fontMatchNone
}
// fontRuleMatchLevel 获取字体规则匹配等级 // fontRuleMatchLevel 获取字体规则匹配等级
// 入参: rule 字体匹配规则, name 字体名称 // 入参: rule 字体匹配规则, name 字体名称
// 返回: int 匹配等级 // 返回: int 匹配等级
-35
View File
@@ -20,13 +20,6 @@ import (
"sort" "sort"
) )
// align4 计算 4 字节对齐后的长度
// 入参: n 原始长度
// 返回: uint32 对齐后的长度
func align4(n uint32) uint32 {
return (n + 3) & ^uint32(3)
}
// packedGlyphRune 获取包装字体字符 // packedGlyphRune 获取包装字体字符
// 入参: gid 字形ID // 入参: gid 字形ID
// 返回: rune 包装字体字符 // 返回: rune 包装字体字符
@@ -55,27 +48,6 @@ func calcTableChecksum(data []byte) uint32 {
return sum return sum
} }
// checkMissingCmap 检查是否缺失 cmap 表
// 入参: data 字体数据
// 返回: bool 是否缺失
func checkMissingCmap(data []byte) bool {
if len(data) < 12 {
return true
}
numTables := binary.BigEndian.Uint16(data[4:6])
for i := 0; i < int(numTables); i++ {
pos := 12 + i*16
if len(data) < pos+4 {
break
}
tag := string(data[pos : pos+4])
if tag == "cmap" {
return false
}
}
return true
}
// parseCmapMappings 解析 cmap 字符映射 // parseCmapMappings 解析 cmap 字符映射
// 入参: data cmap表数据 // 入参: data cmap表数据
// 返回: map[rune]uint16 字符到字形映射 // 返回: map[rune]uint16 字符到字形映射
@@ -287,13 +259,6 @@ func buildHheaTable(numGlyphs uint16) []byte {
return buf.Bytes() return buf.Bytes()
} }
// buildMaxpTable 构建 maxp 表
// 入参: numGlyphs 字形数量
// 返回: []byte maxp表数据
func buildMaxpTable(numGlyphs uint16) []byte {
return buildCFFMaxpTable(numGlyphs)
}
// buildCFFMaxpTable 构建 CFF 轮廓使用的 maxp 0.5 表 // buildCFFMaxpTable 构建 CFF 轮廓使用的 maxp 0.5 表
// 入参: numGlyphs 字形数量 // 入参: numGlyphs 字形数量
// 返回: []byte maxp表数据 // 返回: []byte maxp表数据
-1
View File
@@ -61,7 +61,6 @@ type SignedInfo struct {
Seal SignatureSeal `xml:"Seal"` Seal SignatureSeal `xml:"Seal"`
StampAnnot []SignatureStamp `xml:"StampAnnot"` StampAnnot []SignatureStamp `xml:"StampAnnot"`
References SignatureReferences `xml:"References"` References SignatureReferences `xml:"References"`
Raw []byte `xml:"-"`
} }
// SignatureProvider 签名提供者信息 // SignatureProvider 签名提供者信息
-45
View File
@@ -355,11 +355,6 @@ func parseSignatureFile(data []byte) (*SignatureFile, error) {
if err := xml.Unmarshal(data, &sigFile); err != nil { if err := xml.Unmarshal(data, &sigFile); err != nil {
return nil, err return nil, err
} }
raw, err := xmlElementRaw(data, "SignedInfo")
if err != nil {
return nil, err
}
sigFile.SignedInfo.Raw = raw
return &sigFile, nil return &sigFile, nil
} }
@@ -720,46 +715,6 @@ func compactSignatureCerts(certs [][]byte) [][]byte {
return out return out
} }
// xmlElementRaw 提取XML元素原始字节
// 入参: data XML数据, localName 元素名称
// 返回: []byte 元素原始字节, error 错误信息
func xmlElementRaw(data []byte, localName string) ([]byte, error) {
dec := xml.NewDecoder(bytes.NewReader(data))
for {
tok, err := dec.Token()
if err == io.EOF {
break
}
if err != nil {
return nil, err
}
start, ok := tok.(xml.StartElement)
if !ok || start.Name.Local != localName {
continue
}
end := int(dec.InputOffset())
begin := bytes.LastIndex(data[:end], []byte("<"))
if begin < 0 {
return nil, fmt.Errorf("xml element not found: %s", localName)
}
depth := 1
for depth > 0 {
tok, err = dec.Token()
if err != nil {
return nil, err
}
switch tok.(type) {
case xml.StartElement:
depth++
case xml.EndElement:
depth--
}
}
return append([]byte(nil), data[begin:int(dec.InputOffset())]...), nil
}
return nil, fmt.Errorf("xml element not found: %s", localName)
}
// signatureCertInfo 解析签名证书信息 // signatureCertInfo 解析签名证书信息
// 入参: data DER编码证书 // 入参: data DER编码证书
// 返回: SignatureCertInfo 签名证书信息 // 返回: SignatureCertInfo 签名证书信息
-7
View File
@@ -22,13 +22,6 @@ import (
"github.com/tdewolff/canvas" "github.com/tdewolff/canvas"
) )
// parseColor 解析颜色字符串
// 入参: val 颜色值(R G B)
// 返回: color.Color 颜色对象
func parseColor(val string) color.Color {
return parseColorWithAlpha(val, nil)
}
// parseColorWithAlpha 解析带透明度的颜色 // parseColorWithAlpha 解析带透明度的颜色
// 入参: val 颜色值, alpha 透明度 // 入参: val 颜色值, alpha 透明度
// 返回: color.Color 颜色对象 // 返回: color.Color 颜色对象