Skip to content
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

Color font support for LVGL #2255

Open
MouriNaruto opened this issue May 13, 2021 · 8 comments
Open

Color font support for LVGL #2255

MouriNaruto opened this issue May 13, 2021 · 8 comments

Comments

@MouriNaruto
Copy link

@MouriNaruto MouriNaruto commented May 13, 2021

For more deeper thinking from #2144 (comment).

I also wonder to know how to make the LVGL to support the color font. (I wonder to add support for the color glyphs for Unicode Emoji characters in LVGL and make it looks as good as the app with the modern UI technology.)

The introduction of the color font: https://docs.microsoft.com/en-us/windows/win32/directwrite/color-fonts

@MouriNaruto MouriNaruto changed the title Color font support Color font support for LVGL May 13, 2021
@kisvegabor
Copy link
Member

@kisvegabor kisvegabor commented May 17, 2021

I really like the idea. I'd also allow using color fonts like these.

I think the largest barrier is finding a suitable rendered that can produce an LVGL-digestible simple format. AFAIK FreeType (the rendered we currently use) doesn't support it. 🙁

This comment says FreeType supports only RGB images and vector color fonts.

This gist shows how to load bitmap fonts.

@embeddedt
Copy link
Member

@embeddedt embeddedt commented May 26, 2021

@kisvegabor It appears that FreeType 2.10 (which was released a month after that answer) does in fact support rendering the "Segoe UI Emoji" font, so I assume that it will work for any other emoji fonts as well.

@lvgl-bot
Copy link

@lvgl-bot lvgl-bot commented Jun 9, 2021

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@kisvegabor
Copy link
Member

@kisvegabor kisvegabor commented Jun 9, 2021

Ups, sorry, I forgot to comment here.

Is there someone who has the linking to make some tests with it?
First first just see the output from FreeType.

@kisvegabor
Copy link
Member

@kisvegabor kisvegabor commented Sep 23, 2021

Good to know, thanks!

@guoweilkd
Copy link
Contributor

@guoweilkd guoweilkd commented Sep 26, 2021

Simple support experiments :

add draw color font code in deps/lvgl/src/draw/lv_draw_label.c, like this :

LV_ATTRIBUTE_FAST_MEM static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g,
                                                     const lv_area_t * clip_area,
                                                     const uint8_t * map_p, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode)
{
    const uint8_t * bpp_opa_table_p;
    uint32_t bitmask_init;
    uint32_t bitmask;
    uint32_t bpp = g->bpp;
    uint32_t shades;
    if(bpp == 3) bpp = 4;

    //draw color font 
    if (bpp == 32) {
        lv_area_t fill_area;
        fill_area.x1 = pos_x;
        fill_area.y1 = pos_y;
        fill_area.x2 = pos_x + g->box_w - 1;
        fill_area.y2 = pos_y + g->box_h - 1;
        _lv_blend_map(clip_area, &fill_area, (lv_color_t*)map_p, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, blend_mode);
        return;
    }

in get_glyph_dsc_cb_nocache of lv_lib_freetype, add FT_LOAD_COLOR macro for FT_Load_Glyph(), and Mark color use bpp = 32:

    error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT | FT_LOAD_COLOR);
   .....
    dsc_out->bpp = face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA ? 32 : 8;         /*Bit per pixel: 1/2/4/8*/

result:
image

@kisvegabor
Copy link
Member

@kisvegabor kisvegabor commented Sep 30, 2021

Wow, it was very simple in LVGL. One thing is that we should support 16 bit color depth too.

#2569 will merge lv_lib_freetype into lvgl. After that a PR for it would be very very welcome 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants