mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
+10
-2
@@ -236,6 +236,7 @@ type fontPatternMatcher struct {
|
|||||||
lowerPattern string
|
lowerPattern string
|
||||||
stem string
|
stem string
|
||||||
aliases []string
|
aliases []string
|
||||||
|
priority int
|
||||||
}
|
}
|
||||||
|
|
||||||
// newFontPatternMatcher 创建字体文件匹配器
|
// newFontPatternMatcher 创建字体文件匹配器
|
||||||
@@ -263,8 +264,10 @@ func newFontPatternMatcher(pattern string) fontPatternMatcher {
|
|||||||
// 返回: []fontPatternMatcher 字体文件匹配器列表
|
// 返回: []fontPatternMatcher 字体文件匹配器列表
|
||||||
func newFontPatternMatchers(patterns []string) []fontPatternMatcher {
|
func newFontPatternMatchers(patterns []string) []fontPatternMatcher {
|
||||||
matchers := make([]fontPatternMatcher, 0, len(patterns))
|
matchers := make([]fontPatternMatcher, 0, len(patterns))
|
||||||
for _, pattern := range patterns {
|
for priority, pattern := range patterns {
|
||||||
matchers = append(matchers, newFontPatternMatcher(pattern))
|
matcher := newFontPatternMatcher(pattern)
|
||||||
|
matcher.priority = priority
|
||||||
|
matchers = append(matchers, matcher)
|
||||||
}
|
}
|
||||||
return matchers
|
return matchers
|
||||||
}
|
}
|
||||||
@@ -343,6 +346,7 @@ func (m fontPatternMatcher) styleSuffixNormalized(name string) string {
|
|||||||
|
|
||||||
type fontFileMatch struct {
|
type fontFileMatch struct {
|
||||||
name string
|
name string
|
||||||
|
priority int
|
||||||
rank int
|
rank int
|
||||||
styleRank int
|
styleRank int
|
||||||
sortName string
|
sortName string
|
||||||
@@ -356,6 +360,7 @@ func appendFontFileMatch(matches *[]fontFileMatch, seen map[string]int, matcher
|
|||||||
}
|
}
|
||||||
next := fontFileMatch{
|
next := fontFileMatch{
|
||||||
name: file.name,
|
name: file.name,
|
||||||
|
priority: matcher.priority,
|
||||||
rank: rank,
|
rank: rank,
|
||||||
styleRank: fontFileStyleRank(matcher.styleSuffixNormalized(file.normalized), bold, italic),
|
styleRank: fontFileStyleRank(matcher.styleSuffixNormalized(file.normalized), bold, italic),
|
||||||
sortName: file.lowerBase,
|
sortName: file.lowerBase,
|
||||||
@@ -382,6 +387,9 @@ func sortFontFileMatches(matches []fontFileMatch) {
|
|||||||
// 入参: left 左侧匹配结果, right 右侧匹配结果
|
// 入参: left 左侧匹配结果, right 右侧匹配结果
|
||||||
// 返回: bool 左侧是否优先
|
// 返回: bool 左侧是否优先
|
||||||
func fontFileMatchLess(left, right fontFileMatch) bool {
|
func fontFileMatchLess(left, right fontFileMatch) bool {
|
||||||
|
if left.priority != right.priority {
|
||||||
|
return left.priority < right.priority
|
||||||
|
}
|
||||||
if left.rank != right.rank {
|
if left.rank != right.rank {
|
||||||
return left.rank < right.rank
|
return left.rank < right.rank
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user