10000 Load fonts dynamically · Issue #59 · lvgl/lv_binding_micropython · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
amirgon opened this issue Dec 31, 2019 · 13 comments
Closed

Load fonts dynamically #59

amirgon opened this issue Dec 31, 2019 · 13 comments
Labels
enhancement New feature or request pinned

Comments

@amirgon
Copy link
Collaborator
amirgon commented Dec 31, 2019

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:

@amirgon amirgon added the enhancement New feature or request label Dec 31, 2019
@stale
Copy link
stale bot commented Jan 21, 2020

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.

@stale stale bot added the stale This will not be worked on label Jan 21, 2020
@embeddedt embeddedt added pinned and removed stale This will not be worked on labels Jan 21, 2020
@amirgon
Copy link
Collaborator Author
amirgon commented Aug 21, 2020

Implemented by lvgl/lvgl#1717

@amirgon amirgon closed this as completed Aug 21, 2020
@imliubo
Copy link
Contributor
imliubo commented Sep 10, 2020

Have an example for this?

@amirgon
Copy link
Collaborator Author
amirgon commented Sep 10, 2020

@imliubo Actually no. It was implemented as part of LVGL core and I didn't try this on Micropython yet.
You are welcome to be the first who tries this out on Micropython!

@imliubo
Copy link
Contributor
imliubo commented Sep 10, 2020

@amirgon I try it now! It seem I need driver the filesystem operation interface first.
But I have converted my font file.

$ 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?

@amirgon
Copy link
Collaborator Author
amirgon commented Sep 10, 2020

Is this right?

Yes you would need to implement a filesystem driver. I didn't try to do that either.

@imliubo
Copy link
Contributor
imliubo commented Sep 10, 2020

@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
But need change this fs_register function:

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:
Built-in font
image
My font by load, It looks like the space character is missing.
image

Continue to check the Chinese font problem.

@amirgon
Copy link
Collaborator Author
amirgon commented Sep 10, 2020

@imliubo Nice work!
If you want you can contribute the example under examples/ to show how to do it.
The filesystem driver can probably go under lib/.
It would be great if you open a PR and add this!

@imliubo
Copy link
Contributor
imliubo commented Sep 10, 2020

@amirgon OK, I will do this!
Chinese display works
image
Chinese can also be displayed. It may be that the font file I converted for the first time was too large (~200KB). I tried to convert only a few Chinese characters, and there was no problem. I need to confirm the size of the font file supported.

It would be great if ttf font files could be parsed directly :)

I will add this example to lv_binding_micropython/examples

@embeddedt
Copy link
Member

It would be great if ttf font files could be parsed directly :)

You can use lv_lib_freetype for that.

@imliubo
Copy link
Contributor
imliubo commented Sep 10, 2020

@embeddedt It seems that there is no micropython interface (not sure, if there is, please let me know).

@embeddedt
Copy link
Member

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.

@amirgon
Copy link
Collaborator Author
amirgon commented Sep 10, 2020

@imliubo you are right, currently there is no micropython interface for lv_lib_freetype.
Today Micropython interface is generated only for core LVGL, for lodepng (PNG library) and for esp-idf.

Do you think lv_lib_freetype micropython API would be useful?
If you do please open a new issue on lv_binding_micropython to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pinned
Projects
None yet
Development

No branches or pull requests

3 participants
0