From efe3324d4bbf11aa491b521f87e0207d71da8320 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Fri, 24 Jul 2026 17:22:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E5=AD=97=E4=BD=93):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0android=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdgo_font_loader.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/ofdgo_font_loader.go b/ofdgo_font_loader.go index 16e26bb..a343b28 100644 --- a/ofdgo_font_loader.go +++ b/ofdgo_font_loader.go @@ -162,10 +162,14 @@ func (r *Renderer) fontSources(fontID string, font *Font, style canvas.FontStyle r.fontSourceCache[fontID] = sources return sources } + systemDirs := systemFontDirs() for _, name := range []string{font.FamilyName, font.FontName} { for _, systemName := range fontSystemNames(name) { - for _, match := range r.matchFontFiles(systemFontDir(), fontFilePatterns(systemName), bold, italic) { - sources = appendFontSource(sources, seen, fontSource{kind: fontSourceFile, name: match, exact: true}) + 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: fontSourceSystem, name: systemName, exact: true}) } @@ -260,15 +264,18 @@ func (r *Renderer) matchFontFiles(dir string, patterns []string, bold, italic bo return fontFileMatchNames(matches) } -// systemFontDir 获取系统字体目录 -// 返回: string 字体目录 -func systemFontDir() string { +// systemFontDirs 获取系统字体目录 +// 返回: []string 字体目录列表 +func systemFontDirs() []string { switch runtime.GOOS { - case "linux": - return `/usr/share/fonts` + case "android": + return []string{"/product/fonts", "/system/fonts"} case "darwin": - return `/Library/Fonts` - default: - return `C:\Windows\Fonts` + return []string{`/Library/Fonts`} + case "linux": + return []string{`/usr/share/fonts`} + case "windows": + return []string{`C:\Windows\Fonts`} } + return nil }