package image import ( "os" "runtime" ) // CollectFontCandidates 收集常见中文字体路径,允许用 DOUYU_FONT 指定自定义字体。 func CollectFontCandidates() []string { candidates := []string{} if custom := os.Getenv("DOUYU_FONT"); custom != "" { candidates = append(candidates, custom) } candidates = append(candidates, "Microsoft Yahei.ttf", "Microsoft YaHei.ttf", "NotoSansCJKsc-Regular.otf", "NotoSansCJK-Regular.ttc", ) switch runtime.GOOS { case "darwin": candidates = append(candidates, "/System/Library/Fonts/PingFang.ttc", "/System/Library/Fonts/Supplemental/Arial Unicode.ttf", "/System/Library/Fonts/Supplemental/Songti.ttc", ) case "windows": candidates = append(candidates, `C:\Windows\Fonts\msyh.ttc`, `C:\Windows\Fonts\simhei.ttf`, `C:\Windows\Fonts\simsun.ttc`, ) default: candidates = append(candidates, "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.otf", "/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc", "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc", "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", ) } return candidates }