2017-11-23 20:42:14 +01:00
|
|
|
/**
|
2017-11-23 21:28:36 +01:00
|
|
|
* @file lv_font.h
|
2018-06-18 13:52:14 +03:00
|
|
|
*
|
2017-11-23 20:42:14 +01:00
|
|
|
*/
|
|
|
|
|
2017-11-23 21:28:36 +01:00
|
|
|
#ifndef LV_FONT_H
|
|
|
|
#define LV_FONT_H
|
2017-11-23 20:42:14 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 12:21:36 +02:00
|
|
|
#ifdef LV_CONF_INCLUDE_SIMPLE
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_conf.h"
|
|
|
|
#else
|
2017-11-26 23:57:39 +01:00
|
|
|
#include "../../lv_conf.h"
|
2018-07-07 11:53:22 +02:00
|
|
|
#endif
|
2017-11-23 20:42:14 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
2018-06-22 23:32:21 +02:00
|
|
|
#include <stdbool.h>
|
2017-11-23 20:42:14 +01:00
|
|
|
|
2018-07-07 12:41:56 +02:00
|
|
|
#include "lv_symbol_def.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
2018-02-05 11:27:08 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint32_t w_px :8;
|
|
|
|
uint32_t glyph_index :24;
|
2018-06-18 13:52:14 +03:00
|
|
|
} lv_font_glyph_dsc_t;
|
2018-02-05 11:27:08 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint32_t unicode :21;
|
|
|
|
uint32_t glyph_dsc_index :11;
|
2018-06-18 13:52:14 +03:00
|
|
|
} lv_font_unicode_map_t;
|
2018-02-05 11:27:08 +01:00
|
|
|
|
2017-11-23 21:28:36 +01:00
|
|
|
typedef struct _lv_font_struct
|
2017-11-23 20:42:14 +01:00
|
|
|
{
|
2018-02-05 11:27:08 +01:00
|
|
|
uint32_t unicode_first;
|
|
|
|
uint32_t unicode_last;
|
|
|
|
const uint8_t * glyph_bitmap;
|
|
|
|
const lv_font_glyph_dsc_t * glyph_dsc;
|
2018-02-09 12:40:00 +01:00
|
|
|
const uint32_t * unicode_list;
|
2018-06-18 13:52:14 +03:00
|
|
|
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*/
|
2017-11-23 21:28:36 +01:00
|
|
|
struct _lv_font_struct * next_page; /*Pointer to a font extension*/
|
2018-09-21 14:02:51 +02:00
|
|
|
uint32_t h_px :8;
|
2018-10-05 17:22:49 +02:00
|
|
|
uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/
|
|
|
|
uint32_t monospace :8; /*Fix width (0: normal width)*/
|
2018-10-05 16:00:48 +02:00
|
|
|
uint16_t glyph_cnt; /*Number of glyphs (letters) in the font*/
|
2018-06-18 13:52:14 +03:00
|
|
|
} lv_font_t;
|
2017-11-23 20:42:14 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
2018-07-07 12:41:56 +02:00
|
|
|
* Initialize the fonts
|
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-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
|
|
|
*/
|
2017-11-23 21:28:36 +01:00
|
|
|
void lv_font_add(lv_font_t *child, lv_font_t *parent);
|
2017-11-23 20:42:14 +01:00
|
|
|
|
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);
|
|
|
|
|
2018-06-22 23:32:21 +02:00
|
|
|
/**
|
|
|
|
* Tells if font which contains `letter` is monospace or not
|
|
|
|
* @param font_p point to font
|
|
|
|
* @param letter an UNICODE character code
|
|
|
|
* @return true: the letter is monospace; false not monospace
|
|
|
|
*/
|
|
|
|
bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter);
|
|
|
|
|
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
|
|
|
|
*/
|
2017-11-23 21:28:36 +01:00
|
|
|
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter);
|
2017-11-23 20:42:14 +01:00
|
|
|
|
2018-06-22 23:32:21 +02:00
|
|
|
/**
|
|
|
|
* Get the width of a letter in a font. If `monospace` is set then return with it.
|
|
|
|
* @param font_p pointer to a font
|
|
|
|
* @param letter an UNICODE character code
|
|
|
|
* @return the width of a letter
|
|
|
|
*/
|
|
|
|
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter);
|
|
|
|
|
|
|
|
|
2018-07-07 12:21:36 +02:00
|
|
|
/**
|
|
|
|
* Get the width of the letter without overwriting it with the `monospace` attribute
|
|
|
|
* @param font_p pointer to a font
|
|
|
|
* @param letter an UNICODE character code
|
|
|
|
* @return the width of a letter
|
|
|
|
*/
|
|
|
|
uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter);
|
|
|
|
|
2017-11-23 20:42:14 +01:00
|
|
|
/**
|
|
|
|
* Get the height of a font
|
|
|
|
* @param font_p pointer to a font
|
|
|
|
* @return the height of a font
|
|
|
|
*/
|
2017-11-23 21:28:36 +01:00
|
|
|
static inline uint8_t lv_font_get_height(const lv_font_t * font_p)
|
2017-11-23 20:42:14 +01:00
|
|
|
{
|
2018-02-05 11:27:08 +01:00
|
|
|
return font_p->h_px;
|
2017-11-23 20:42:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-09 12:40:00 +01:00
|
|
|
* Get the bit-per-pixel of font
|
|
|
|
* @param font pointer to font
|
|
|
|
* @param letter a letter from font (font extensions can have different bpp)
|
|
|
|
* @return bpp of the font (or font extension)
|
2017-11-23 20:42:14 +01:00
|
|
|
*/
|
2018-02-23 13:56:04 +01:00
|
|
|
uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter);
|
2018-02-09 12:40:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range
|
|
|
|
* @param font pointer to font
|
|
|
|
* @param unicode_letter an unicode letter which bitmap should be get
|
|
|
|
* @return pointer to the bitmap or NULL if not found
|
|
|
|
*/
|
|
|
|
const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
|
|
|
|
* @param font pointer to font
|
|
|
|
* @param unicode_letter an unicode letter which bitmap should be get
|
|
|
|
* @return pointer to the bitmap or NULL if not found
|
|
|
|
*/
|
|
|
|
const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter);
|
2018-02-23 13:56:04 +01:00
|
|
|
/**
|
|
|
|
* Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range
|
|
|
|
* @param font pointer to font
|
|
|
|
* @param unicode_letter an unicode letter which width should be get
|
|
|
|
* @return width of the gylph or -1 if not found
|
|
|
|
*/
|
2018-04-09 12:39:58 +02:00
|
|
|
int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter);
|
2018-02-23 13:56:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
|
|
|
|
* @param font pointer to font
|
|
|
|
* @param unicode_letter an unicode letter which width should be get
|
|
|
|
* @return width of the glyph or -1 if not found
|
|
|
|
*/
|
2018-04-09 12:39:58 +02:00
|
|
|
int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter);
|
2017-11-23 20:42:14 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
2018-02-09 12:40:00 +01:00
|
|
|
|
2018-07-07 12:41:56 +02:00
|
|
|
#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
|
2018-02-09 12:40:00 +01:00
|
|
|
|
|
|
|
|
2018-07-07 12:41:56 +02:00
|
|
|
/**********************
|
|
|
|
* ADD BUILT IN FONTS
|
|
|
|
**********************/
|
|
|
|
#include "../lv_fonts/lv_font_builtin.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
|
2018-07-07 11:26:24 +02:00
|
|
|
/*Declare the custom (user defined) fonts*/
|
2018-07-13 13:54:41 +02:00
|
|
|
#ifdef LV_FONT_CUSTOM_DECLARE
|
2018-07-07 11:26:24 +02:00
|
|
|
LV_FONT_CUSTOM_DECLARE
|
2018-07-13 13:54:41 +02:00
|
|
|
#endif
|
2018-07-07 11:26:24 +02:00
|
|
|
|
2017-11-23 20:42:14 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
2017-11-26 23:57:39 +01:00
|
|
|
#endif /*USE_FONT*/
|
|
|
|
|