-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No support for Chinese ttf font #2660
Comments
Add this init in main.go dump accured:
|
Can you please fill in the bug report with version information requested? Additionally the stack shows |
|
This is not code that replicates the error. We would need the Fyne code (including the Entry widget) and the keystrokes you used to demonstrate the problem. |
可以支持中文的,我在Deepin(Linux)和Windows都能正常显示和输入中文。 如果实在读取系统字体有问题,可以使用主题的方式,把字体编译成主题资源,然后使用自己的中文主题来显示界面。 |
I suspect that this is what you mean? I ran it though a translation service. I'd prefer if we could stick to English for conversations here to make sure that everyone can understand. |
because the default font in Fyne dose not support Chinese, but you can do something like this, it works well for me:
type myTheme struct {
regular, bold, italic, boldItalic, monospace fyne.Resource
}
func (t *myTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
return theme.DefaultTheme().Color(name, variant)
}
func (t *myTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
return theme.DefaultTheme().Icon(name)
}
func (m *myTheme) Font(style fyne.TextStyle) fyne.Resource {
if style.Monospace {
return m.monospace
}
if style.Bold {
if style.Italic {
return m.boldItalic
}
return m.bold
}
if style.Italic {
return m.italic
}
return m.regular
}
func (m *myTheme) Size(name fyne.ThemeSizeName) float32 {
return theme.DefaultTheme().Size(name)
}
func (t *myTheme) SetFonts(regularFontPath string, monoFontPath string) {
t.regular = theme.TextFont()
t.bold = theme.TextBoldFont()
t.italic = theme.TextItalicFont()
t.boldItalic = theme.TextBoldItalicFont()
t.monospace = theme.TextMonospaceFont()
if regularFontPath != "" {
t.regular = loadCustomFont(regularFontPath, "Regular", t.regular)
t.bold = loadCustomFont(regularFontPath, "Bold", t.bold)
t.italic = loadCustomFont(regularFontPath, "Italic", t.italic)
t.boldItalic = loadCustomFont(regularFontPath, "BoldItalic", t.boldItalic)
}
if monoFontPath != "" {
t.monospace = loadCustomFont(monoFontPath, "Regular", t.monospace)
} else {
t.monospace = t.regular
}
}
func loadCustomFont(env, variant string, fallback fyne.Resource) fyne.Resource {
variantPath := strings.Replace(env, "Regular", variant, -1)
res, err := fyne.LoadResourceFromPath(variantPath)
if err != nil {
fyne.LogError("Error loading specified font", err)
return fallback
}
return res
}
t := &myTheme{}
t.SetFonts("./assets/font/Consolas-with-Yahei Regular Nerd Font.ttf", "")
// note that under "./assets/font", there are actually 4 files:
// Consolas-with-Yahei Bold Nerd Font.ttf
// Consolas-with-Yahei BoldItalic Nerd Font.ttf
// Consolas-with-Yahei Italic Nerd Font.ttf
// Consolas-with-Yahei Regular Nerd Font.ttf
app.Settings().SetTheme(t)
in chinese: 因为Fyne的默认字体并不支持中文,你可以像我这么干,很顺利的显示出来了:
type myTheme struct {
regular, bold, italic, boldItalic, monospace fyne.Resource
}
func (t *myTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
return theme.DefaultTheme().Color(name, variant)
}
func (t *myTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
return theme.DefaultTheme().Icon(name)
}
func (m *myTheme) Font(style fyne.TextStyle) fyne.Resource {
if style.Monospace {
return m.monospace
}
if style.Bold {
if style.Italic {
return m.boldItalic
}
return m.bold
}
if style.Italic {
return m.italic
}
return m.regular
}
func (m *myTheme) Size(name fyne.ThemeSizeName) float32 {
return theme.DefaultTheme().Size(name)
}
func (t *myTheme) SetFonts(regularFontPath string, monoFontPath string) {
t.regular = theme.TextFont()
t.bold = theme.TextBoldFont()
t.italic = theme.TextItalicFont()
t.boldItalic = theme.TextBoldItalicFont()
t.monospace = theme.TextMonospaceFont()
if regularFontPath != "" {
t.regular = loadCustomFont(regularFontPath, "Regular", t.regular)
t.bold = loadCustomFont(regularFontPath, "Bold", t.bold)
t.italic = loadCustomFont(regularFontPath, "Italic", t.italic)
t.boldItalic = loadCustomFont(regularFontPath, "BoldItalic", t.boldItalic)
}
if monoFontPath != "" {
t.monospace = loadCustomFont(monoFontPath, "Regular", t.monospace)
} else {
t.monospace = t.regular
}
}
func loadCustomFont(env, variant string, fallback fyne.Resource) fyne.Resource {
variantPath := strings.Replace(env, "Regular", variant, -1)
res, err := fyne.LoadResourceFromPath(variantPath)
if err != nil {
fyne.LogError("Error loading specified font", err)
return fallback
}
return res
}
t := &myTheme{}
t.SetFonts("./assets/font/Consolas-with-Yahei Regular Nerd Font.ttf", "")
// 注意"./assets/font"目录下有4个文件:
// Consolas-with-Yahei Bold Nerd Font.ttf
// Consolas-with-Yahei BoldItalic Nerd Font.ttf
// Consolas-with-Yahei Italic Nerd Font.ttf
// Consolas-with-Yahei Regular Nerd Font.ttf
app.Settings().SetTheme(t)
|
感谢,我的按照这个方法设置好了。 |
yeah,its work. the exe application, cannot load the assets file. have anyone can show me how to use go-bindata or else? |
Using relative paths does not work once you distribute applications. Information about our recommended bundling is at https://developer.fyne.io/extend/bundle |
Thanks, Im use the os. Setenv("FYNE_FONT", path) , it works ! bundle assets ways it works too. But the latter is not compatible with development building both environments. have any tutorial about this ? :D |
Just setting the FYNE_FONT environment variables as your font file path will solve this problem. set FYNE_FONT=C:\my_project\font\msyh.ttf |
Set app创建之前设置FYNE_FONT |
when I input Chinese characters ,occur 2 problem 1、in entry lost some Chinese characters which type in typewriting place TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit goroutine 52 [running]: |
I think you are looking at #2777 |
.\main.go:25:26: cannot use t (variable of type *myTheme) as "fyne.io/fyne".Theme value in argument to app.Settings().SetTheme: *myTheme does not implement "fyne.io/fyne".Theme (missing method BackgroundColor) |
Don't mix v2 with older imports |
And please keep questions related to the issues you write them on. Questions should go in into discussions or on Gophers slack |
import (_ "github.com/lengzhao/font/autoload") |
We moved to a new font loader, I believe this is fixed. |
no,i use latest version |
Please expand on your assertion that this issue is not resolved. A new crash dump for example. |
Describe the bug:
To Reproduce:
Steps to reproduce the behaviour:
Screenshots:
Example code:
Device (please complete the following information):
The text was updated successfully, but these errors were encountered: