Closed QuentinWidlocher closed 2 years ago
No problem on my ArchLinux.
what is your result of fc-match -s
?
or
import os.font
font.default()
or you can set font_path: '/path/to/your/favorite_font.ttf'
to app.window
No problem on my ArchLinux.
what is your result of
fc-match -s
? orimport os.font font.default()
or you can set
font_path: '/path/to/your/favorite_font.ttf'
toapp.window
Why I set font_path, still can not display Chinese fonts normally?
Is that /fonts/font.ttf
an absolute path?
Seems a relative path to me.
Or you can use https://modules.vlang.io/os.html#resource_abs_path like fp := os.resource_abs_path(os.join_path('assets/fonts/', 'RobotoMono-Regular.ttf'))
And I don't have Windows, so I could be wrong, but The way to specify the path is like this. https://github.com/vlang/v/blob/d8263171ff21809b6d5514dab481928ee2f3af22/vlib/os/font/font.v#L25
Currently, there are a lot of hard-coded places like this in vlib
.
If you can figure out how to get the system's default fonts on Windows programmatically, please PR it.
If you're using vscode, I'd recommend adding v
and .vmodules
folders to your workspace
, like this.
That way you'll be able to find plenty of examples of vlib
with Search: Find in Files
, ctrl+shift+F
.
Is that
/fonts/font.ttf
an absolute path? Seems a relative path to me.Or you can use https://modules.vlang.io/os.html#resource_abs_path like
fp := os.resource_abs_path(os.join_path('assets/fonts/', 'RobotoMono-Regular.ttf'))
And I don't have Windows, so I could be wrong, but The way to specify the path is like this. https://github.com/vlang/v/blob/d8263171ff21809b6d5514dab481928ee2f3af22/vlib/os/font/font.v#L25
I'm using Windows 10, I've tried many ways but all failed.But the absolute path of font_path printed out is correct.
what is your result of fc-match -s?
font.default()
returns /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
or you can set font_path: '/path/to/your/favorite_font.ttf' to app.window
This works when setting the font.default() to app.window, so thanks !
@tzSharing
hmm.. try and see again change this path to your path and remove app.window.font_path
.
https://github.com/vlang/v/blob/d8263171ff21809b6d5514dab481928ee2f3af22/vlib/os/font/font.v#L32
Are you living in China and discord is banned? https://discord.com/channels/592103645835821068/665558664949530644
@tzSharing hmm.. try and see again change this path to your path and remove
app.window.font_path
. https://github.com/vlang/v/blob/d8263171ff21809b6d5514dab481928ee2f3af22/vlib/os/font/font.v#L32Are you living in China and discord is banned? https://discord.com/channels/592103645835821068/665558664949530644
Wow, with this method, I modified the default()
source code in v/vlib/os/font/font.v
, it was successfully repaired, I didn't even think of this method. thanks.
In addition, regarding discord, my network is completely inaccessible, and GitHub can be accessed normally most of the time, but the speed is very slow.
I feel like this is a bug that needs to be fixed.
Yeah, I almost confirmed that the bug belongs to ui
not vlib
via both of yours.
I don't have time to fix it right now, so I recommend leaving the default()
one as it is.
The VUI_FONT
env variable, exists exactly for easy experimentation / overriding of the default font path.
You can call os.setenv('VUI_FONT', 'C:\\Windows\Fonts\\simfang.ttf', true)
, before your font.default()
and/or gg calls, and then font.default()
will return 'C:\\Windows\Fonts\\simfang.ttf'
without the need for patching the vlib source code.
You can call
os.setenv('VUI_FONT', 'C:\\Windows\Fonts\\simfang.ttf', true)
, before yourfont.default()
and/or gg calls, and thenfont.default()
will return'C:\\Windows\Fonts\\simfang.ttf'
without the need for patching the vlib source code.
I just tried the method you said, and it works. I not only loaded the system fonts, but also successfully loaded the relative path fonts in the project.Thanks!
v doctor output
``` OS: linux, Ubuntu 20.04.3 LTS Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz CC version: cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 getwd: /mnt/809EB2A59EB292E0/Perso/v/test-ui-2 vmodules: /home/quentin/.vmodules vroot: /mnt/809EB2A59EB292E0/Perso/v/v vexe: /mnt/809EB2A59EB292E0/Perso/v/v/v vexe mtime: 2022-01-13 12:54:47 is vroot writable: true is vmodules writable: true V full version: V 0.2.4 7882915.7fbd856 Git version: git version 2.25.1 Git vroot status: weekly.2021.46-534-g7fbd856b .git/config present: true thirdparty/tcc status: thirdparty-linux-amd64 3654d6a8 ```What did you do?
Executed
v run app.v
on this file :app.v
```v import ui const ( win_width = 208 win_height = 46 ) struct App { mut: counter string = '0' window &ui.Window = 0 } fn main() { mut app := &App{} app.window = ui.window( width: win_width height: win_height title: 'Counter' state: app children: [ ui.row( spacing: 5 margin: ui.Margin{5, 5, 5, 5} children: [ ui.textbox( max_len: 20 read_only: true is_numeric: true text: &app.counter ), ui.button( width: 24 height: 24 text: 'Alt' onclick: btn_count_click ), ] ), ] ) ui.run(app.window) } fn btn_count_click(mut app App, btn &ui.Button) { app.counter = (app.counter.int() + 1).str() } ```What did you expect to see?
A nice counter example
What did you see instead?
An ugly counter example without text, and the console logging
gg: draw_text(): font not initialized
repeatedly