-
Notifications
You must be signed in to change notification settings - Fork 181
Load fonts dynamically #59
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
Comments
This issue or pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Implemented by lvgl/lvgl#1717 |
Have an example for this? |
@imliubo Actually no. It was implemented as part of LVGL core and I didn't try this on Micropython yet. |
@amirgon I try it now! It seem I need driver the filesystem operation interface first. $ lv_font_conv --size 20 --format bin --bpp 1 --font Alibaba-PuHuiTi-Medium.subset.ttf -o Alibaba-PHT-20.bin --range 0x20-0x9f9f Is this right? |
Yes you would need to implement a filesystem driver. I didn't try to do that either. |
@amirgon It seems successful! (But the Chinese display doesn't seem to work :() English can load your own ttf font file, but you need to use the lvgl font conversion tool to convert it. I use this filesystem driver: file_drv -mhepp def fs_register(fs_drv, letter):
fs_drv.init() # this line
fs_drv.letter = ord(letter)
fs_drv.open_cb = fs_open_cb
fs_drv.read_cb = fs_read_cb
fs_drv.write_cb = fs_write_cb
fs_drv.seek_cb = fs_seek_cb
fs_drv.tell_cb = fs_tell_cb
fs_drv.close_cb = fs_close_cb
fs_drv.register() # this line And the example code: import lvgl as lv
import file_drv
lv.init()
# display driver init...
# FS driver init.
fs_drv = lv.fs_drv_t()
file_drv.fs_register(fs_drv, 'S')
# load the font file from filesystem
myfont = lv.font_load("S:res/PHT-ASCII-20.bin") # Refer here to convert your font file: https://github.com/lvgl/lv_font_conv
scr = lv.scr_act()
scr.clean()
style = lv.style_t()
style.init()
label = lv.label(scr)
style.set_text_font(lv.STATE.DEFAULT, myfont)
label.add_style(label.PART.MAIN, style)
label.set_text("Hi LVGL(Load fonts dynamically)")
label.align(None, lv.ALIGN.CENTER, 0, 0) Result: Continue to check the Chinese font problem. |
@imliubo Nice work! |
@amirgon OK, I will do this! It would be great if ttf font files could be parsed directly :) I will add this example to lv_binding_micropython/examples |
You can use |
@embeddedt It seems that there is no micropython interface (not sure, if there is, please let me know). |
That's true; I think it should be possible to initialize it in C and/or run it through the binding generator, but I'm not familiar with the details. |
@imliubo you are right, currently there is no micropython interface for Do you think |
Today fonts must be compiled into lvgl.
I would be useful to allow loading fonts dynamically on runtime.
This could be implemented by creating native .mpy files from a .elf file.
References:
The text was updated successfully, but these errors were encountered: