lvgl / lv_utils

Convert images or system fonts to C arrays. Written for LVGL embedded GUI library
https://littlevgl.com
54 stars 38 forks source link

Font generator generates lv_font_t initialisation in wrong order #22

Closed harrymander closed 5 years ago

harrymander commented 5 years ago

The font generator generates the initialisation for the lv_font_t object in the wrong order, causing a compiler error.

Generated order:

lv_font_t arial_bold_15 = 
{
    .unicode_first = 32,    /*First Unicode letter in this font*/
    .unicode_last = 126,    /*Last Unicode letter in this font*/
    .h_px = 15,             /*Font height in pixels*/
    .glyph_bitmap = arial_bold_15_glyph_bitmap, /*Bitmap of glyphs*/
    .glyph_dsc = arial_bold_15_glyph_dsc,       /*Description of glyphs*/
    .glyph_cnt = 95,            /*Number of glyphs in the font*/
    .unicode_list = NULL,   /*Every character in the font from 'unicode_first' to 'unicode_last'*/
    .get_bitmap = lv_font_get_bitmap_continuous,    /*Function pointer to get glyph's bitmap*/
    .get_width = lv_font_get_width_continuous,  /*Function pointer to get glyph's width*/
#if USE_ARIAL_BOLD_15 == 1
    .bpp = 1,               /*Bit per pixel*/
 #elif USE_ARIAL_BOLD_15 == 2
    .bpp = 2,               /*Bit per pixel*/
 #elif USE_ARIAL_BOLD_15 == 4
    .bpp = 4,               /*Bit per pixel*/
 #elif USE_ARIAL_BOLD_15 == 8
    .bpp = 8,               /*Bit per pixel*/
#endif
    .monospace = 0,             /*Fix width (0: if not used)*/
    .next_page = NULL,      /*Pointer to a font extension*/
};

Correct order from lv_font.h:

typedef struct _lv_font_struct
{
    uint32_t unicode_first;
    uint32_t unicode_last;
    const uint8_t * glyph_bitmap;
    const lv_font_glyph_dsc_t * glyph_dsc;
    const uint32_t * unicode_list;
    const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,uint32_t);     /*Get a glyph's  bitmap from a font*/
    int16_t (*get_width)(const struct _lv_font_struct *,uint32_t);        /*Get a glyph's with with a given font*/
    struct _lv_font_struct * next_page;    /*Pointer to a font extension*/
    uint32_t h_px       :8;
    uint32_t bpp        :4;                /*Bit per pixel: 1, 2 or 4*/
    uint32_t monospace  :8;                /*Fix width (0: normal width)*/
    uint16_t glyph_cnt;                    /*Number of glyphs (letters) in the font*/
} lv_font_t;
embeddedt commented 5 years ago

@HarryManderTait If you're using C99 this should work fine. LittlevGL requires a C99 compiler. Exactly what error does it give you?

From https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html:

In ISO C99 you can give the elements in any order, specifying the array indices or structure field names they apply to.

harrymander commented 5 years ago

It looks like the problem was that I had written some of the code in C++ but was using the C++ compiler to compile all the files including the C files. Compiled the C files with a C compiler and the issue was fixed. Thanks for your help.