mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
1 parent
0be872691d
commit
5cc811c2a1
6 files changed
+159
-213
No files matched your search
@@ -15,6 +15,7 @@
|
||||
package ofdgo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -389,3 +390,46 @@ func appendFontPattern(patterns []string, seen map[string]bool, pattern string)
|
||||
seen[key] = true
|
||||
return append(patterns, pattern)
|
||||
}
|
||||
|
||||
// appendFontFileNames 建立各字体的内部名称与文件别名匹配候选
|
||||
// 入参: candidates 字体候选, index 文件候选索引, faces 各字体内部名称
|
||||
// 返回: []fontFileCandidate 字体候选列表
|
||||
func appendFontFileNames(candidates []fontFileCandidate, index int, faces [][]string) []fontFileCandidate {
|
||||
file := candidates[index]
|
||||
replaced := false
|
||||
for face, names := range faces {
|
||||
file.face = face
|
||||
file.names = make([]string, len(names))
|
||||
for i, name := range names {
|
||||
file.names[i] = basefont.NormalizeName(name)
|
||||
}
|
||||
for _, name := range file.names {
|
||||
file.normalized = name
|
||||
if !replaced {
|
||||
candidates[index] = file
|
||||
replaced = true
|
||||
} else {
|
||||
candidates = append(candidates, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidates
|
||||
}
|
||||
|
||||
// fontCollectionIndex 按内部名称与样式选择集合项,未匹配时保留首项
|
||||
// 入参: data 集合数据, names 字体名称, bold 是否粗体, italic 是否斜体
|
||||
// 返回: int 零起始字体索引
|
||||
func fontCollectionIndex(data []byte, names []string, bold, italic bool) int {
|
||||
return fontNameIndex(basefont.FileNames(bytes.NewReader(data)), names, bold, italic)
|
||||
}
|
||||
|
||||
// fontNameIndex 按名称与样式选择字体索引,未匹配时保留首项
|
||||
// 入参: faces 各字体名称, names 目标名称, bold 是否粗体, italic 是否斜体
|
||||
// 返回: int 零起始字体索引
|
||||
func fontNameIndex(faces [][]string, names []string, bold, italic bool) int {
|
||||
candidates := appendFontFileNames([]fontFileCandidate{{}}, 0, faces)
|
||||
if matches := fontFileMatches(candidates, names, bold, italic); len(matches) > 0 {
|
||||
return matches[0].face
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in new issue
Block a user