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
How can I to set the font size? #609
Comments
All right, I see. Thanks~. This method is not elegant enough maybe. |
@tianyoung Why isn't this method elegant? If you want dynamic font size support, generate more static fonts using https://littlevgl.com/ttf-font-to-c-array and choose between them at runtime. TTF/vector fonts are not currently supported. |
Thank you so much. @embeddedt |
@tianyoung To generate any font with any sizes for real, try to port FreeType library. Ofcourse you will need a lot amount of some storage size (in case we are talking about chinese fonts :-) ) to store *.ttf binary files of fonts and memory to alocate generated by FreeType library bitmaps in sram/sdram ... THere a lot of free fonts, just Google it For example - Free Unicde Chinese Fonts |
@BesitzeRuf Hi~ I ported the FreeType library, But how to merge it into lvgl. it seems difficult. |
@tianyoung yes, additional functionality should be implemented...
|
@tianyoung You should initialize an I created a quick example: const uint8_t * my_bitmap_get(const lv_font_t * f,uint32_t unicode)
{
memset(bitmap_buf, 0, sizeof(bitmap_buf));
int16_t w = f->get_width(f, unicode);
uint8_t x;
uint8_t y;
/*Draw a stripped bitmap*/
for(y = 0; y < f->h_px; y+=2) {
for(x = 0; x < w; x++) {
bitmap_buf[y * w + x] = 0xFF;
printf("set: %d\n", y * w + x);
}
}
return bitmap_buf;
}
int16_t my_width_get(const lv_font_t * f,uint32_t unicode)
{
/*Dummy example: '1' -> 1 px wide, '2' -> 2 px wide etc.*/
if(unicode >= '0' && unicode <= '9') {
return unicode - '0'; /*0..9*/
}
return -1;
}
...
/*Initialize the font*/
static lv_font_t dummy_font;
dummy_font.get_bitmap = my_bitmap_get;
dummy_font.get_width = my_width_get;
dummy_font.h_px = 20;
dummy_font.unicode_first = 0x30; /*'0'*/
dummy_font.unicode_last = 0x39; /*'9'*/
dummy_font.monospace = 0;
dummy_font.unicode_list = NULL;
dummy_font.bpp = 8; /*8 bit per pixel for simplicity. 1 byte -> 1 pixel*/
/*Used by "normal" converted fonts. Just set them to zero*/
dummy_font.glyph_cnt = 0;
dummy_font.glyph_dsc = NULL;
/*Create a style with the font*/
static lv_style_t font_test_style;
lv_style_copy(&font_test_style, &lv_style_plain);
font_test_style.text.font = &dummy_font;
/*Create a label with the style*/
lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label, "123456789");
lv_label_set_style(label, &font_test_style); |
How do you mean "deleting font"? Fonts are just global (or static) |
@kisvegabor With FreeType library we can create raster from vector fonts dynamically in run-time, but it requires extra memory to keep generated font bitmaps (in ram or ext. ram). There is a function for adding a font as child to parent font (sorry, here I don't clearly understand the meaning of "charter set", if shouldn't it be a "character set"? ) |
@BesitzeRuf I see, thank you for the explanation. A Yes, "charter set" is a typo, but I don't find it in the project. Where is it? EDIT: |
@kisvegabor thank you too :) |
@BesitzeRuf |
I close this issue because there was no activity here for a while. If you have remarks about this topic feel free to comment here and reopen the issue. |
No description provided.
The text was updated successfully, but these errors were encountered: