Some changes to support binary fonts without the kernel table.
This commit is contained in:
1
lvgl.h
1
lvgl.h
@@ -31,6 +31,7 @@ extern "C" {
|
||||
#include "src/lv_themes/lv_theme.h"
|
||||
|
||||
#include "src/lv_font/lv_font.h"
|
||||
#include "src/lv_font/lv_font_loader.h"
|
||||
#include "src/lv_font/lv_font_fmt_txt.h"
|
||||
#include "src/lv_misc/lv_printf.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#if LV_USE_FILESYSTEM
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -15,6 +14,8 @@
|
||||
#include "../lv_misc/lv_fs.h"
|
||||
#include "lv_font_loader.h"
|
||||
|
||||
#if LV_USE_FILESYSTEM
|
||||
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@@ -101,7 +102,7 @@ lv_font_t * lv_font_load(const char * font_name)
|
||||
|
||||
if (!success)
|
||||
{
|
||||
LV_LOG_WARN("Error opening font file: %s\n", font_name);
|
||||
LV_LOG_WARN("Error loading font file: %s\n", font_name);
|
||||
lv_font_free(font);
|
||||
font = NULL;
|
||||
}
|
||||
@@ -220,7 +221,7 @@ static int read_label(lv_fs_file_t *fp, int start, const char *label)
|
||||
if(lv_fs_read(fp, &length, 4, NULL) != LV_FS_RES_OK
|
||||
|| lv_fs_read(fp, buf, 4, NULL) != LV_FS_RES_OK
|
||||
|| memcmp(label, buf, 4) != 0) {
|
||||
LV_LOG_WARN("Error reading '%s'.", label);
|
||||
LV_LOG_WARN("Error reading '%s' label.", label);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -408,20 +409,31 @@ static bool lvgl_load_font(lv_fs_file_t * fp, lv_font_t * font)
|
||||
|
||||
bit_iterator_t bit_it = init_bit_iterator(fp);
|
||||
|
||||
if(font_header.advance_width_bits == 0) {
|
||||
/*
|
||||
* TODO: understand how to interpret advance_width_format
|
||||
* When it is set to zero, in my understanding should be used the default value,
|
||||
* and no data should be written on the advance_width, but it is not occurring.
|
||||
*
|
||||
* The following code is not working for most monospaced fonts.
|
||||
*/
|
||||
|
||||
/*if(font_header.advance_width_bits == 0) {
|
||||
gdsc->adv_w = font_header.default_advance_width;
|
||||
}
|
||||
else {
|
||||
else */ {
|
||||
if(font_header.advance_width_format == 0) { /* uint */
|
||||
gdsc->adv_w = 16 * read_bits(&bit_it, 4, &res); // TODO: review the number of bits that should be read
|
||||
if(res != LV_FS_RES_OK) {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(font_header.advance_width_format == 1) { /* unsigned with 4 bits fractional part */
|
||||
gdsc->adv_w = read_bits(&bit_it, font_header.advance_width_bits, &res);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: understand how to interpret advance_width_format */
|
||||
if(font_header.advance_width_format == 0) { /* uint */
|
||||
}
|
||||
else if(font_header.advance_width_format == 1) { /* unsigned with 4 bits fractional part */
|
||||
}
|
||||
else {
|
||||
LV_LOG_WARN("error unknown advance_width_format");
|
||||
@@ -525,8 +537,11 @@ static bool lvgl_load_font(lv_fs_file_t * fp, lv_font_t * font)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(lv_fs_seek(fp, glyph_start + glyph_length) != LV_FS_RES_OK) {
|
||||
return false;
|
||||
if (font_header.tables_count < 4) {
|
||||
font_dsc->kern_dsc = NULL;
|
||||
font_dsc->kern_classes = 0;
|
||||
font_dsc->kern_scale = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t kern_start = glyph_start + glyph_length;
|
||||
|
||||
@@ -44,8 +44,8 @@ static int compare_fonts(lv_font_t * f1, lv_font_t * f2);
|
||||
|
||||
void lv_test_font_loader(void)
|
||||
{
|
||||
lv_font_t * font = lv_font_load("f:lv_font_montserrat_12.bin");
|
||||
compare_fonts(&lv_font_montserrat_12, font);
|
||||
lv_font_t * montserrat_12_bin = lv_font_load("f:lv_font_montserrat_12.bin");
|
||||
compare_fonts(&lv_font_montserrat_12, montserrat_12_bin);
|
||||
}
|
||||
|
||||
static int compare_fonts(lv_font_t * f1, lv_font_t * f2)
|
||||
@@ -109,7 +109,7 @@ static int compare_fonts(lv_font_t * f1, lv_font_t * f2)
|
||||
// kern_dsc
|
||||
lv_font_fmt_txt_kern_classes_t * kern1 = (lv_font_fmt_txt_kern_classes_t *) dsc1->kern_dsc;
|
||||
lv_font_fmt_txt_kern_classes_t * kern2 = (lv_font_fmt_txt_kern_classes_t *) dsc2->kern_dsc;
|
||||
|
||||
if (kern1 != NULL && kern2 != NULL) {
|
||||
lv_test_assert_int_eq(kern1->right_class_cnt, kern2->right_class_cnt, "right_class_cnt");
|
||||
lv_test_assert_int_eq(kern1->left_class_cnt, kern2->left_class_cnt, "left_class_cnt");
|
||||
|
||||
@@ -126,6 +126,10 @@ static int compare_fonts(lv_font_t * f1, lv_font_t * f2)
|
||||
lv_test_assert_int_eq(kern1->class_pair_values[i],
|
||||
kern2->class_pair_values[i], "class_pair_values");
|
||||
}
|
||||
}
|
||||
else {
|
||||
lv_test_assert_ptr_eq(kern1, kern2, "kern");
|
||||
}
|
||||
|
||||
// TODO: glyph_bitmap
|
||||
|
||||
|
||||
Reference in New Issue
Block a user