2017-11-23 20:42:14 +01:00
|
|
|
/**
|
2017-11-23 21:28:36 +01:00
|
|
|
* @file lv_font.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2017-11-23 20:42:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2019-03-06 11:14:06 +01:00
|
|
|
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "lv_font.h"
|
2018-07-25 17:57:08 +02:00
|
|
|
#include "lv_log.h"
|
2019-03-18 07:25:20 +01:00
|
|
|
#include "lv_utils.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
static int32_t lv_font_codeCompare(const void * pRef, const void * pElement);
|
2019-03-06 11:14:06 +01:00
|
|
|
|
2017-11-23 20:42:14 +01:00
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
2019-05-01 18:08:56 +02:00
|
|
|
* Initialize the font module
|
2017-11-23 20:42:14 +01:00
|
|
|
*/
|
2017-11-23 21:28:36 +01:00
|
|
|
void lv_font_init(void)
|
2017-11-23 20:42:14 +01:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_font_builtin_init();
|
2017-11-23 20:42:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-13 15:18:06 +01:00
|
|
|
* Add a font to an other to extend the character set.
|
|
|
|
* @param child the font to add
|
|
|
|
* @param parent this font will be extended. Using it later will contain the characters from `child`
|
2017-11-23 20:42:14 +01:00
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
void lv_font_add(lv_font_t * child, lv_font_t * parent)
|
2017-11-23 20:42:14 +01:00
|
|
|
{
|
|
|
|
if(parent == NULL) return;
|
|
|
|
|
|
|
|
while(parent->next_page != NULL) {
|
|
|
|
parent = parent->next_page; /*Got to the last page and add the new font there*/
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->next_page = child;
|
|
|
|
}
|
|
|
|
|
2018-12-13 15:18:06 +01:00
|
|
|
/**
|
|
|
|
* Remove a font from a character set.
|
|
|
|
* @param child the font to remove
|
|
|
|
* @param parent remove `child` from here
|
|
|
|
*/
|
|
|
|
void lv_font_remove(lv_font_t * child, lv_font_t * parent)
|
|
|
|
{
|
|
|
|
if(parent == NULL) return;
|
|
|
|
if(child == NULL) return;
|
|
|
|
|
|
|
|
while(parent->next_page != child) {
|
|
|
|
parent = parent->next_page; /*Got to the last page and add the new font there*/
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->next_page = child->next_page;
|
|
|
|
}
|
|
|
|
|
2017-11-23 20:42:14 +01:00
|
|
|
/**
|
|
|
|
* Return with the bitmap of a font.
|
|
|
|
* @param font_p pointer to a font
|
2018-06-22 23:32:21 +02:00
|
|
|
* @param letter an UNICODE character code
|
2017-11-23 20:42:14 +01:00
|
|
|
* @return pointer to the bitmap of the letter
|
|
|
|
*/
|
2019-04-22 05:21:35 +02:00
|
|
|
const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter)
|
2017-11-23 20:42:14 +01:00
|
|
|
{
|
2017-11-23 21:28:36 +01:00
|
|
|
const lv_font_t * font_i = font_p;
|
2017-11-23 20:42:14 +01:00
|
|
|
while(font_i != NULL) {
|
2019-04-24 17:28:38 +02:00
|
|
|
const uint8_t * bitmap = font_i->get_glyph_bitmap(font_i, letter);
|
2018-02-23 13:56:04 +01:00
|
|
|
if(bitmap) return bitmap;
|
2017-11-23 20:42:14 +01:00
|
|
|
|
|
|
|
font_i = font_i->next_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-01 16:43:32 +02:00
|
|
|
* Get the descriptor of a glyph
|
|
|
|
* @param font_p pointer to font
|
|
|
|
* @param dsc_out store the result descriptor here
|
|
|
|
* @param letter an UNICODE letter code
|
|
|
|
* @return true: descriptor is successfully loaded into `dsc_out`.
|
|
|
|
* false: the letter was not found, no data is loaded to `dsc_out`
|
2017-11-23 20:42:14 +01:00
|
|
|
*/
|
2019-05-01 16:43:32 +02:00
|
|
|
bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter)
|
2018-06-22 23:32:21 +02:00
|
|
|
{
|
|
|
|
const lv_font_t * font_i = font_p;
|
2019-05-01 16:43:32 +02:00
|
|
|
bool ret;
|
2018-06-22 23:32:21 +02:00
|
|
|
while(font_i != NULL) {
|
2019-05-01 16:43:32 +02:00
|
|
|
ret = font_i->get_glyph_dsc(font_i, dsc_out, letter);
|
|
|
|
if(ret) return ret;
|
2018-06-22 23:32:21 +02:00
|
|
|
|
|
|
|
font_i = font_i->next_page;
|
|
|
|
}
|
|
|
|
|
2019-05-01 16:43:32 +02:00
|
|
|
return false;
|
2019-04-24 17:28:38 +02:00
|
|
|
}
|
|
|
|
|
2017-11-23 20:42:14 +01:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|