From fa0c933f01226db908e3c1ccc010e865e08a2156 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Tue, 14 Jul 2026 11:19:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=AD=97=E4=BD=93=E5=8C=B9=E9=85=8D):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA=E5=9B=9E=E5=BD=92=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdgo_font_fs.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ofdgo_font_fs.go b/ofdgo_font_fs.go index 1de4a8b..1c815b7 100644 --- a/ofdgo_font_fs.go +++ b/ofdgo_font_fs.go @@ -236,6 +236,7 @@ type fontPatternMatcher struct { lowerPattern string stem string aliases []string + priority int } // newFontPatternMatcher 创建字体文件匹配器 @@ -263,8 +264,10 @@ func newFontPatternMatcher(pattern string) fontPatternMatcher { // 返回: []fontPatternMatcher 字体文件匹配器列表 func newFontPatternMatchers(patterns []string) []fontPatternMatcher { matchers := make([]fontPatternMatcher, 0, len(patterns)) - for _, pattern := range patterns { - matchers = append(matchers, newFontPatternMatcher(pattern)) + for priority, pattern := range patterns { + matcher := newFontPatternMatcher(pattern) + matcher.priority = priority + matchers = append(matchers, matcher) } return matchers } @@ -343,6 +346,7 @@ func (m fontPatternMatcher) styleSuffixNormalized(name string) string { type fontFileMatch struct { name string + priority int rank int styleRank int sortName string @@ -356,6 +360,7 @@ func appendFontFileMatch(matches *[]fontFileMatch, seen map[string]int, matcher } next := fontFileMatch{ name: file.name, + priority: matcher.priority, rank: rank, styleRank: fontFileStyleRank(matcher.styleSuffixNormalized(file.normalized), bold, italic), sortName: file.lowerBase, @@ -382,6 +387,9 @@ func sortFontFileMatches(matches []fontFileMatch) { // 入参: left 左侧匹配结果, right 右侧匹配结果 // 返回: bool 左侧是否优先 func fontFileMatchLess(left, right fontFileMatch) bool { + if left.priority != right.priority { + return left.priority < right.priority + } if left.rank != right.rank { return left.rank < right.rank }