refactor(重构代码): 提升代码水平
build.yaml / build (push) Successful in 33s

This commit is contained in:
2026-07-09 11:10:47 +08:00
parent fa3260c108
commit 9eb9104380
5 changed files with 119 additions and 40 deletions
+5 -9
View File
@@ -161,16 +161,12 @@ func (r *Renderer) loadFont(fontID string) *canvas.FontFamily {
func (r *Renderer) matchFontFiles(dir string, patterns []string, bold, italic bool) []string {
var matches []fontFileMatch
index := make(map[string]int)
add := func(pattern, name string, rank int) {
if !isFontFileName(name) {
return
}
appendFontFileMatch(&matches, index, pattern, name, rank, bold, italic)
}
files, _ := filepath.Glob(filepath.Join(dir, "*"))
for _, pattern := range patterns {
for _, name := range files {
add(pattern, name, matchFontPatternRank(pattern, filepath.Base(name)))
candidates := fontFileCandidates(files, filepath.Base)
for _, matcher := range newFontPatternMatchers(patterns) {
for _, file := range candidates {
rank := matcher.rank(file.base)
appendFontFileMatch(&matches, index, matcher.pattern, file.name, rank, bold, italic)
}
}
sortFontFileMatches(matches, bold, italic)