mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
+16
-9
@@ -162,11 +162,15 @@ func (r *Renderer) fontSources(fontID string, font *Font, style canvas.FontStyle
|
|||||||
r.fontSourceCache[fontID] = sources
|
r.fontSourceCache[fontID] = sources
|
||||||
return sources
|
return sources
|
||||||
}
|
}
|
||||||
|
systemDirs := systemFontDirs()
|
||||||
for _, name := range []string{font.FamilyName, font.FontName} {
|
for _, name := range []string{font.FamilyName, font.FontName} {
|
||||||
for _, systemName := range fontSystemNames(name) {
|
for _, systemName := range fontSystemNames(name) {
|
||||||
for _, match := range r.matchFontFiles(systemFontDir(), fontFilePatterns(systemName), bold, italic) {
|
systemPatterns := fontFilePatterns(systemName)
|
||||||
|
for _, dir := range systemDirs {
|
||||||
|
for _, match := range r.matchFontFiles(dir, systemPatterns, bold, italic) {
|
||||||
sources = appendFontSource(sources, seen, fontSource{kind: fontSourceFile, name: match, exact: true})
|
sources = appendFontSource(sources, seen, fontSource{kind: fontSourceFile, name: match, exact: true})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sources = appendFontSource(sources, seen, fontSource{kind: fontSourceSystem, name: systemName, exact: true})
|
sources = appendFontSource(sources, seen, fontSource{kind: fontSourceSystem, name: systemName, exact: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,15 +264,18 @@ func (r *Renderer) matchFontFiles(dir string, patterns []string, bold, italic bo
|
|||||||
return fontFileMatchNames(matches)
|
return fontFileMatchNames(matches)
|
||||||
}
|
}
|
||||||
|
|
||||||
// systemFontDir 获取系统字体目录
|
// systemFontDirs 获取系统字体目录
|
||||||
// 返回: string 字体目录
|
// 返回: []string 字体目录列表
|
||||||
func systemFontDir() string {
|
func systemFontDirs() []string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "android":
|
||||||
return `/usr/share/fonts`
|
return []string{"/product/fonts", "/system/fonts"}
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return `/Library/Fonts`
|
return []string{`/Library/Fonts`}
|
||||||
default:
|
case "linux":
|
||||||
return `C:\Windows\Fonts`
|
return []string{`/usr/share/fonts`}
|
||||||
|
case "windows":
|
||||||
|
return []string{`C:\Windows\Fonts`}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user