add a default font

This commit is contained in:
Gabor Kiss-Vamosi 2019-06-02 11:56:57 +02:00
parent f692e00ffe
commit ff65ecd102
13 changed files with 2662 additions and 4110 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,44 @@
import argparse
import os
import sys
parser = argparse.ArgumentParser(description='Create fonts for LittelvGL including the built-in symbols. lv_font_conv needs to be installed. See https://github.com/littlevgl/lv_font_conv')
parser.add_argument('-s', '--size',
type=int,
metavar = 'px',
nargs='?',
help='Size of the font in px')
parser.add_argument('-bpp',
type=int,
metavar = '1,2,4',
nargs='?',
help='Bit per pixel')
parser.add_argument('-r', '--range',
nargs='+',
metavar = 'start-end',
default=['0x20-0x7F'],
help='Ranges and/or characters to include. Default is 0x20-7F (ASCII). E.g. -r 0x20-0x7F 0x200 324')
parser.add_argument('-o', '--output',
nargs='?',
metavar='file',
help='Output file name. E.g. my_font_20.c')
parser.add_argument('--compressed', action='store_true',
help='Compress the bitmaps')
args = parser.parse_args()
if args.compressed == False:
compr = "--no-compress --no-prefilter"
else:
compr = ""
r_str = ""
for r in args.range:
r_str = r_str + "-r " + r + " ";
#Built in symbols
syms = "-r 61441 -r 61448 -r 61451 -r 61452 -r 61453 -r 61457 -r 61459 -r 61460 -r 61461 -r 61465 -r 61468 -r 61473 -r 61478 -r 61479 -r 61480 -r 61502 -r 61504 -r 61512 -r 61515 -r 61516 -r 61517 -r 61521 -r 61522 -r 61523 -r 61524 -r 61543 -r 61544 -r 61553 -r 61556 -r 61559 -r 61560 -r 61561 -r 61563 -r 61587 -r 61589 -r 61636 -r 61637 -r 61639 -r 61671 -r 61683 -r 61724 -r 61732 -r 61787 -r 61931 -r 62016 -r 62017 -r 62018 -r 62019 -r 62020 -r 62099"
#Run the command
cmd = "lv_font_conv {} --bpp {} --size {} --font ./Roboto-Regular.woff {} --font FontAwesome.ttf {} --format lvgl -o {}".format(compr, args.bpp, args.size, r_str, syms, args.output)
os.system(cmd)

View File

@ -88,7 +88,6 @@ void lv_init(void)
lv_fs_init();
#endif
lv_font_init();
#if LV_USE_ANIMATION
lv_anim_core_init();
#endif

View File

@ -250,8 +250,8 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv
bool g_ret = lv_font_get_glyph_dsc(font_p, &g, letter, '\0');
if(g_ret == false) return;
lv_coord_t pos_x = pos_p->x + g.ofs_x;
lv_coord_t pos_y = pos_p->y + g.ofs_y;
lv_coord_t pos_x = pos_p->x;
lv_coord_t pos_y = pos_p->y + (font_p->line_height - font_p->base_line) - g.box_h - g.ofs_y;
const uint8_t * bpp_opa_table;
uint8_t bitmask_init;
@ -277,10 +277,6 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv
default: return; /*Invalid bpp. Can't render the letter*/
}
if(letter == 0xf817) {
char x = 1;
}
const uint8_t * map_p = lv_font_get_glyph_bitmap(font_p, letter);
if(map_p == NULL) return;

View File

@ -1,45 +0,0 @@
/**
* @file lv_font_built_in.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_font_builtin.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the built-in fonts
*/
void lv_font_builtin_init(void)
{
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -1,125 +0,0 @@
/**
* @file lv_font_builtin.h
*
*/
#ifndef LV_FONT_BUILTIN_H
#define LV_FONT_BUILTIN_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../../lv_conf.h"
#endif
#include "../lv_misc/lv_font.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the built-in fonts
*/
void lv_font_builtin_init(void);
/**********************
* MACROS
**********************/
/**********************
* FONT DECLARATIONS
**********************/
/*10 px */
#if LV_USE_FONT_DEJAVU_10
LV_FONT_DECLARE(lv_font_dejavu_10)
#endif
#if LV_USE_FONT_DEJAVU_10_LATIN_SUP
LV_FONT_DECLARE(lv_font_dejavu_10_latin_sup)
#endif
#if LV_USE_FONT_DEJAVU_10_CYRILLIC
LV_FONT_DECLARE(lv_font_dejavu_10_cyrillic)
#endif
#if LV_USE_FONT_SYMBOL_10
LV_FONT_DECLARE(lv_font_symbol_10)
#endif
/*20 px */
#if LV_USE_FONT_DEJAVU_20
LV_FONT_DECLARE(lv_font_dejavu_20)
#endif
#if LV_USE_FONT_DEJAVU_20_LATIN_SUP
LV_FONT_DECLARE(lv_font_dejavu_20_latin_sup)
#endif
#if LV_USE_FONT_DEJAVU_20_CYRILLIC
LV_FONT_DECLARE(lv_font_dejavu_20_cyrillic)
#endif
#if LV_USE_FONT_SYMBOL_20
LV_FONT_DECLARE(lv_font_symbol_20)
#endif
/*30 px */
#if LV_USE_FONT_DEJAVU_30
LV_FONT_DECLARE(lv_font_dejavu_30)
#endif
#if LV_USE_FONT_DEJAVU_30_LATIN_SUP
LV_FONT_DECLARE(lv_font_dejavu_30_latin_sup)
#endif
#if LV_USE_FONT_DEJAVU_30_CYRILLIC
LV_FONT_DECLARE(lv_font_dejavu_30_cyrillic)
#endif
#if LV_USE_FONT_SYMBOL_30
LV_FONT_DECLARE(lv_font_symbol_30)
#endif
/*40 px */
#if LV_USE_FONT_DEJAVU_40
LV_FONT_DECLARE(lv_font_dejavu_40)
#endif
#if LV_USE_FONT_DEJAVU_40_LATIN_SUP
LV_FONT_DECLARE(lv_font_dejavu_40_latin_sup)
#endif
#if LV_USE_FONT_DEJAVU_40_CYRILLIC
LV_FONT_DECLARE(lv_font_dejavu_40_cyrillic)
#endif
#if LV_USE_FONT_SYMBOL_40
LV_FONT_DECLARE(lv_font_symbol_40)
#endif
#if LV_USE_FONT_MONOSPACE_8
LV_FONT_DECLARE(lv_font_monospace_8)
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_FONT_BUILTIN_H*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -39,14 +39,6 @@
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the font module
*/
void lv_font_init(void)
{
lv_font_builtin_init();
}
/**
* Return with the bitmap of a font.
* @param font_p pointer to a font

View File

@ -72,11 +72,6 @@ typedef struct _lv_font_struct
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the font module
*/
void lv_font_init(void);
/**
* Return with the bitmap of a font.
* @param font_p pointer to a font
@ -120,15 +115,6 @@ static inline uint8_t lv_font_get_line_height(const lv_font_t * font_p)
#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
#define LV_FONT_SET_WIDTH(_integer, _fract) ((_integer << LV_FONT_WIDTH_FRACT_DIGIT) + _fract)
#define LV_FONT_GET_WIDTH_INT(_w) (_w >> LV_FONT_WIDTH_FRACT_DIGIT)
#define LV_FONT_GET_WIDTH_FRACT(_w) (_w & ((1 << LV_FONT_WIDTH_FRACT_DIGIT) -1))
/**********************
* ADD BUILT IN FONTS
**********************/
#include "../lv_fonts/lv_font_builtin.h"
/*Declare the custom (user defined) fonts*/
#ifdef LV_FONT_CUSTOM_DECLARE
LV_FONT_CUSTOM_DECLARE

View File

@ -24,7 +24,7 @@
* STATIC PROTOTYPES
**********************/
static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter);
static uint32_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t gid_right);
static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t gid_right);
static int32_t lv_font_codeCompare(const void * pRef, const void * pElement);
/**********************
@ -77,7 +77,7 @@ bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t *
uint32_t gid = get_glyph_dsc_id(font, unicode_letter);
if(!gid) return false;
uint32_t kvalue = 0;
int8_t kvalue = 0;
if(fdsc->kern_dsc) {
uint32_t gid_next = get_glyph_dsc_id(font, unicode_letter_next);
if(gid_next) {
@ -88,7 +88,7 @@ bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t *
/*Put together a glyph dsc*/
const lv_font_fmt_txt_glyph_dsc_t * gdsc = &fdsc->glyph_dsc[gid];
uint32_t adw_w = gdsc->adv_w + ((kvalue * fdsc->kern_scale) >> 4);
uint32_t adw_w = gdsc->adv_w + ((int32_t)((int32_t)kvalue * fdsc->kern_scale) >> 4);
adw_w = (adw_w + (1 << 3)) >> 4;
dsc_out->adv_w = adw_w;
@ -122,12 +122,26 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
glyph_id = fdsc->cmaps[i].glyph_id_start + rcp;
}
else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL) {
const uint8_t * gid_ofs_16 = fdsc->cmaps[i].glyph_id_ofs_list;
glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_16[rcp];
const uint8_t * gid_ofs_8 = fdsc->cmaps[i].glyph_id_ofs_list;
glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_8[rcp];
}
else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL) {
else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_TINY) {
uint32_t u;
for(u = 0; u < 50 /*fdsc->cmaps[i].list_length*/; u++) {
if(fdsc->cmaps[i].unicode_list[u] == rcp) {
glyph_id = fdsc->cmaps[i].glyph_id_start + u;
}
}
}
else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_TINY) {
const uint8_t * gid_ofs_16 = fdsc->cmaps[i].glyph_id_ofs_list;
glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_16[rcp];
uint32_t u;
for(u = 0; u < 50 /*fdsc->cmaps[i].list_length*/; u++) {
if(fdsc->cmaps[i].unicode_list[u] == rcp) {
glyph_id = fdsc->cmaps[i].glyph_id_start + u;
}
glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_16[u];
}
}
return glyph_id;
@ -137,48 +151,48 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
}
static uint32_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t gid_right)
static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t gid_right)
{
lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *) font->dsc;
uint32_t value = 0;
uint32_t k;
if(fdsc->kern_classes == 0) {
/*Kern pairs*/
const lv_font_fmt_txt_kern_pair_t * kdsc = fdsc->kern_dsc;
if(kdsc->glyph_ids_size == 1) {
const uint8_t * g_ids = kdsc->glyph_ids;
for(k = 0; k < (uint32_t)kdsc->pair_cnt * 2; k += 2) {
if(g_ids[k] == gid_left &&
g_ids[k+1] == gid_right) {
value = kdsc->values[k >> 1];
break;
}
}
} else {
const uint16_t * g_ids = kdsc->glyph_ids;
for(k = 0; k < (uint32_t)kdsc->pair_cnt * 2; k += 2) {
if(g_ids[k] == gid_left &&
g_ids[k+1] == gid_right) {
value = kdsc->values[k >> 1];
break;
}
}
}
} else {
/*Kern classes*/
const lv_font_fmt_txt_kern_classes_t * kdsc = fdsc->kern_dsc;
uint8_t left_class = kdsc->left_class_mapping[gid_left];
uint8_t right_class = kdsc->left_class_mapping[gid_right];
int8_t value = 0;
uint32_t k;
if(fdsc->kern_classes == 0) {
/*Kern pairs*/
const lv_font_fmt_txt_kern_pair_t * kdsc = fdsc->kern_dsc;
if(kdsc->glyph_ids_size == 1) {
const uint8_t * g_ids = kdsc->glyph_ids;
for(k = 0; k < (uint32_t)kdsc->pair_cnt * 2; k += 2) {
if(g_ids[k] == gid_left &&
g_ids[k+1] == gid_right) {
value = kdsc->values[k >> 1];
break;
}
}
} else {
const uint16_t * g_ids = kdsc->glyph_ids;
for(k = 0; k < (uint32_t)kdsc->pair_cnt * 2; k += 2) {
if(g_ids[k] == gid_left &&
g_ids[k+1] == gid_right) {
value = kdsc->values[k >> 1];
break;
}
}
}
} else {
/*Kern classes*/
const lv_font_fmt_txt_kern_classes_t * kdsc = fdsc->kern_dsc;
uint8_t left_class = kdsc->left_class_mapping[gid_left];
uint8_t right_class = kdsc->left_class_mapping[gid_right];
/* If class = 0, kerning not exist for that glyph
* else got the value form `class_pair_values` 2D array*/
if(left_class > 0 && right_class > 0) {
value = kdsc->class_pair_values[(left_class-1)* kdsc->right_class_cnt + (right_class-1)];
}
/* If class = 0, kerning not exist for that glyph
* else got the value form `class_pair_values` 2D array*/
if(left_class > 0 && right_class > 0) {
value = kdsc->class_pair_values[(left_class-1)* kdsc->right_class_cnt + (right_class-1)];
}
}
return value;
}
return value;
}

View File

@ -12,60 +12,61 @@ extern "C" {
#endif
#define LV_SYMBOL_GLYPH_FIRST 0xF800
#define LV_SYMBOL_AUDIO "\xEF\xA0\x80"
#define LV_SYMBOL_VIDEO "\xEF\xA0\x81"
#define LV_SYMBOL_LIST "\xEF\xA0\x82"
#define LV_SYMBOL_OK "\xEF\xA0\x83"
#define LV_SYMBOL_CLOSE "\xEF\xA0\x84"
#define LV_SYMBOL_POWER "\xEF\xA0\x85"
#define LV_SYMBOL_SETTINGS "\xEF\xA0\x86"
#define LV_SYMBOL_TRASH "\xEF\xA0\x87"
#define LV_SYMBOL_HOME "\xEF\xA0\x88"
#define LV_SYMBOL_DOWNLOAD "\xEF\xA0\x89"
#define LV_SYMBOL_DRIVE "\xEF\xA0\x8A"
#define LV_SYMBOL_REFRESH "\xEF\xA0\x8B"
#define LV_SYMBOL_MUTE "\xEF\xA0\x8C"
#define LV_SYMBOL_VOLUME_MID "\xEF\xA0\x8D"
#define LV_SYMBOL_VOLUME_MAX "\xEF\xA0\x8E"
#define LV_SYMBOL_IMAGE "\xEF\xA0\x8F"
#define LV_SYMBOL_EDIT "\xEF\xA0\x90"
#define LV_SYMBOL_PREV "\xEF\xA0\x91"
#define LV_SYMBOL_PLAY "\xEF\xA0\x92"
#define LV_SYMBOL_PAUSE "\xEF\xA0\x93"
#define LV_SYMBOL_STOP "\xEF\xA0\x94"
#define LV_SYMBOL_NEXT "\xEF\xA0\x95"
#define LV_SYMBOL_EJECT "\xEF\xA0\x96"
#define LV_SYMBOL_LEFT "\xEF\xA0\x97"
#define LV_SYMBOL_RIGHT "\xEF\xA0\x98"
#define LV_SYMBOL_PLUS "\xEF\xA0\x99"
#define LV_SYMBOL_MINUS "\xEF\xA0\x9A"
#define LV_SYMBOL_WARNING "\xEF\xA0\x9B"
#define LV_SYMBOL_SHUFFLE "\xEF\xA0\x9C"
#define LV_SYMBOL_UP "\xEF\xA0\x9D"
#define LV_SYMBOL_DOWN "\xEF\xA0\x9E"
#define LV_SYMBOL_LOOP "\xEF\xA0\x9F"
#define LV_SYMBOL_DIRECTORY "\xEF\xA0\xA0"
#define LV_SYMBOL_UPLOAD "\xEF\xA0\xA1"
#define LV_SYMBOL_CALL "\xEF\xA0\xA2"
#define LV_SYMBOL_CUT "\xEF\xA0\xA3"
#define LV_SYMBOL_COPY "\xEF\xA0\xA4"
#define LV_SYMBOL_SAVE "\xEF\xA0\xA5"
#define LV_SYMBOL_CHARGE "\xEF\xA0\xA6"
#define LV_SYMBOL_BELL "\xEF\xA0\xA7"
#define LV_SYMBOL_KEYBOARD "\xEF\xA0\xA8"
#define LV_SYMBOL_GPS "\xEF\xA0\xA9"
#define LV_SYMBOL_FILE "\xEF\xA0\xAA"
#define LV_SYMBOL_WIFI "\xEF\xA0\xAB"
#define LV_SYMBOL_BATTERY_FULL "\xEF\xA0\xAC"
#define LV_SYMBOL_BATTERY_3 "\xEF\xA0\xAD"
#define LV_SYMBOL_BATTERY_2 "\xEF\xA0\xAE"
#define LV_SYMBOL_BATTERY_1 "\xEF\xA0\xAF"
#define LV_SYMBOL_BATTERY_EMPTY "\xEF\xA0\xB0"
#define LV_SYMBOL_BLUETOOTH "\xEF\xA0\xB1"
#define LV_SYMBOL_GLYPH_LAST 0xF831
#define LV_SYMBOL_AUDIO "\xef\x80\x81"
#define LV_SYMBOL_VIDEO "\xef\x80\x88"
#define LV_SYMBOL_LIST "\xef\x80\x8b"
#define LV_SYMBOL_OK "\xef\x80\x8c"
#define LV_SYMBOL_CLOSE "\xef\x80\x8d"
#define LV_SYMBOL_POWER "\xef\x80\x91"
#define LV_SYMBOL_SETTINGS "\xef\x80\x93"
#define LV_SYMBOL_TRASH "\xef\x80\x94"
#define LV_SYMBOL_HOME "\xef\x80\x95"
#define LV_SYMBOL_DOWNLOAD "\xef\x80\x99"
#define LV_SYMBOL_DRIVE "\xef\x80\x9c"
#define LV_SYMBOL_REFRESH "\xef\x80\xa1"
#define LV_SYMBOL_MUTE "\xef\x80\xa6"
/*Invalid symbol at (U+F831). If written before a string then `lv_img` will show it as a label*/
#define LV_SYMBOL_VOLUME_MID "\xef\x80\xa7"
#define LV_SYMBOL_VOLUME_MAX "\xef\x80\xa8"
#define LV_SYMBOL_IMAGE "\xef\x80\xbe"
#define LV_SYMBOL_EDIT "\xef\x81\x80"
#define LV_SYMBOL_PREV "\xef\x81\x88"
#define LV_SYMBOL_PLAY "\xef\x81\x8b"
#define LV_SYMBOL_PAUSE "\xef\x81\x8c"
#define LV_SYMBOL_STOP "\xef\x81\x8d"
#define LV_SYMBOL_NEXT "\xef\x81\x91"
#define LV_SYMBOL_EJECT "\xef\x81\x92"
#define LV_SYMBOL_LEFT "\xef\x81\x93"
#define LV_SYMBOL_RIGHT "\xef\x81\x94"
#define LV_SYMBOL_PLUS "\xef\x81\xa7"
#define LV_SYMBOL_MINUS "\xef\x81\xa8"
#define LV_SYMBOL_WARNING "\xef\x81\xb1"
#define LV_SYMBOL_SHUFFLE "\xef\x81\xb4"
#define LV_SYMBOL_UP "\xef\x81\xb7"
#define LV_SYMBOL_DOWN "\xef\x81\xb8"
#define LV_SYMBOL_LOOP "\xef\x81\xb9"
#define LV_SYMBOL_DIRECTORY "\xef\x81\xbb"
#define LV_SYMBOL_UPLOAD "\xef\x82\x93"
#define LV_SYMBOL_CALL "\xef\x82\x95"
#define LV_SYMBOL_CUT "\xef\x83\x84"
#define LV_SYMBOL_COPY "\xef\x83\x85"
#define LV_SYMBOL_SAVE "\xef\x83\x87"
#define LV_SYMBOL_CHARGE "\xef\x83\xa7"
#define LV_SYMBOL_BELL "\xef\x83\xb3"
#define LV_SYMBOL_KEYBOARD "\xef\x84\x9c"
#define LV_SYMBOL_GPS "\xef\x84\xa4"
#define LV_SYMBOL_FILE "\xef\x85\x9b"
#define LV_SYMBOL_WIFI "\xef\x87\xab"
#define LV_SYMBOL_BATTERY_FULL "\xef\x89\x80"
#define LV_SYMBOL_BATTERY_3 "\xef\x89\x81"
#define LV_SYMBOL_BATTERY_2 "\xef\x89\x82"
#define LV_SYMBOL_BATTERY_1 "\xef\x89\x83"
#define LV_SYMBOL_BATTERY_EMPTY "\xef\x89\x84"
#define LV_SYMBOL_BLUETOOTH "\xef\x8a\x93"
/*Invalid symbol at (U+F8FF). If written before a string then `lv_img` will show it as a label*/
#define LV_SYMBOL_DUMMY "\xEF\xA3\xBF"
/*