@@ -26,7 +26,7 @@ var embeddedFonts = map[string][]byte{
2626 "Go-Bold" : gobold .TTF ,
2727 "Go-Italic" : goitalic .TTF ,
2828 "Go-BoldItalic" : gobolditalic .TTF ,
29- "sans-regular" : goregular .TTF ,
29+ "sans-regular" : goregular .TTF , // Will try DejaVuSans from assets first
3030 "sans-bold" : gobold .TTF ,
3131 "sans-italic" : goitalic .TTF ,
3232 "sans-bolditalic" : gobolditalic .TTF ,
@@ -40,6 +40,20 @@ var embeddedFonts = map[string][]byte{
4040 "mono-bolditalic" : gobolditalic .TTF ,
4141}
4242
43+ // Fallback fonts for better Unicode support (especially CJK characters)
44+ // Priority order: CJK fonts first, then Latin fonts
45+ var fallbackFontPaths = []string {
46+ // Try Windows system fonts for CJK support
47+ "C:/Windows/Fonts/msyh.ttc" , // Microsoft YaHei (Simplified Chinese)
48+ "C:/Windows/Fonts/msyhbd.ttc" , // Microsoft YaHei Bold
49+ "C:/Windows/Fonts/simsun.ttc" , // SimSun (Simplified Chinese)
50+ "C:/Windows/Fonts/simhei.ttf" , // SimHei (Simplified Chinese)
51+ "C:/Windows/Fonts/msjh.ttc" , // Microsoft JhengHei (Traditional Chinese)
52+ // Local assets
53+ "assets/DejaVuSans.ttf" ,
54+ "resource/font/luxisr.ttf" ,
55+ }
56+
4357// LoadFontFromFile loads a font from a file path
4458func LoadFontFromFile (path string ) (font.Face , []byte , error ) {
4559 // Check cache first
@@ -82,6 +96,21 @@ func LoadEmbeddedFont(name string) (font.Face, []byte, error) {
8296 }
8397 fontCacheMu .RUnlock ()
8498
99+ // For sans fonts, try fallback fonts first (better Unicode support)
100+ if name == "sans-regular" || name == "sans" {
101+ for _ , fallbackPath := range fallbackFontPaths {
102+ face , fontData , err := LoadFontFromFile (fallbackPath )
103+ if err == nil {
104+ // Cache with the requested name
105+ fontCacheMu .Lock ()
106+ fontCache [name ] = face
107+ fontDataCache [name ] = fontData
108+ fontCacheMu .Unlock ()
109+ return face , fontData , nil
110+ }
111+ }
112+ }
113+
85114 // Try loading from embedded fonts
86115 data , ok := embeddedFonts [name ]
87116 if ! ok {
0 commit comments