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
|
2019-03-17 08:33:03 +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
|
|
|
|
*********************/
|
2019-04-27 19:37:19 +02:00
|
|
|
/*Number of fractional digits in the advanced width (`adv_w`) field of `lv_font_glyph_dsc_t`*/
|
2019-05-01 16:43:32 +02:00
|
|
|
#define LV_FONT_WIDTH_FRACT_DIGIT 4
|
2017-11-23 20:42:14 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
2019-04-24 17:28:38 +02:00
|
|
|
typedef struct {
|
2019-05-01 16:43:32 +02:00
|
|
|
int32_t next_unicode :23;
|
|
|
|
int32_t space :9; /*5 integer, 4 fractional*/
|
|
|
|
}lv_font_kern_t;
|
2019-04-24 17:28:38 +02:00
|
|
|
|
2019-05-01 16:43:32 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint16_t adv_w; /*The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */
|
|
|
|
uint8_t box_w; /*Width of the glyph's bounding box*/
|
|
|
|
uint8_t box_h; /*Height of the glyph's bounding box*/
|
|
|
|
int8_t ofs_x; /*x offset of the bounding box*/
|
|
|
|
int8_t ofs_y; /*y offset of the bounding box*/
|
|
|
|
uint8_t bpp; /*Bit-per-pixel: 1, 2, 4, 8*/
|
|
|
|
const lv_font_kern_t * kern_table;
|
|
|
|
}lv_font_glyph_dsc_t;
|
2019-04-24 17:28:38 +02: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;
|
2019-04-22 05:21:35 +02:00
|
|
|
|
|
|
|
/*Get a glyph's descriptor from a font*/
|
2019-05-01 16:43:32 +02:00
|
|
|
bool (*get_glyph_dsc)(const struct _lv_font_struct *, lv_font_glyph_dsc_t *, uint32_t letter);
|
2019-04-22 05:21:35 +02:00
|
|
|
|
|
|
|
/*Get a glyph's bitmap from a font*/
|
2019-04-24 17:28:38 +02:00
|
|
|
const uint8_t * (*get_glyph_bitmap)(const struct _lv_font_struct *, uint32_t);
|
2019-04-22 05:21:35 +02:00
|
|
|
|
2019-04-24 17:28:38 +02:00
|
|
|
/*Pointer to the font in a font pack (must have the same line height)*/
|
2019-04-22 05:21:35 +02:00
|
|
|
struct _lv_font_struct * next_page;
|
2019-05-01 16:43:32 +02:00
|
|
|
uint8_t size; /*The original size (height)*/
|
2019-04-24 17:28:38 +02:00
|
|
|
uint8_t line_height; /*The real line height where any text fits*/
|
2019-05-01 16:43:32 +02:00
|
|
|
uint8_t base_line; /*Base line measured from the top of the line_height*/
|
2019-04-24 17:28:38 +02:00
|
|
|
void * dsc; /*Store implementation specific data here*/
|
2018-06-18 13:52:14 +03:00
|
|
|
} lv_font_t;
|
2017-11-23 20:42:14 +01:00
|
|
|
|
2019-05-01 16:43:32 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint32_t bitmap_index : 20; /* Start index of the bitmap. A font can be max 1 MB. */
|
|
|
|
uint32_t adv_w :12; /*The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */
|
|
|
|
|
|
|
|
uint8_t box_w; /*Width of the glyph's bounding box*/
|
|
|
|
uint8_t box_h; /*Height of the glyph's bounding box*/
|
|
|
|
int8_t ofs_x; /*x offset of the bounding box*/
|
|
|
|
int8_t ofs_y; /*y offset of the bounding box*/
|
|
|
|
|
|
|
|
const lv_font_kern_t * kern_table;
|
|
|
|
}lv_font_glyph_dsc_built_in_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const uint8_t * glyph_bitmap;
|
|
|
|
const lv_font_glyph_dsc_built_in_t * glyph_dsc;
|
|
|
|
const uint16_t * unicode_list;
|
|
|
|
uint16_t glyph_cnt; /*Number of glyphs in the font. */
|
|
|
|
uint8_t bpp; /*Bit per pixel: 1, 2, 4 or 8*/
|
|
|
|
}lv_font_dsc_built_in_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
|
|
|
*/
|
2019-04-04 07:15:40 +02: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);
|
|
|
|
|
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
|
|
|
|
2019-04-24 17:28:38 +02:00
|
|
|
/**
|
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`
|
2019-04-24 17:28:38 +02: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);
|
2019-04-24 17:28:38 +02:00
|
|
|
|
2018-06-22 23:32:21 +02:00
|
|
|
/**
|
2019-05-01 16:43:32 +02:00
|
|
|
* Get the width of a glyph with kerning
|
|
|
|
* @param font pointer to a font
|
|
|
|
* @param letter an UNICODE letter
|
|
|
|
* @param letter_next the next letter after `letter`. Used for kerning
|
|
|
|
* @return the width of the glyph
|
2018-06-22 23:32:21 +02:00
|
|
|
*/
|
2019-05-01 16:43:32 +02:00
|
|
|
uint8_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next);
|
2018-07-07 12:21:36 +02:00
|
|
|
|
2017-11-23 20:42:14 +01:00
|
|
|
/**
|
2019-04-23 15:56:59 +02:00
|
|
|
* Get the line height of a font. All characters fit into this height
|
2017-11-23 20:42:14 +01:00
|
|
|
* @param font_p pointer to a font
|
|
|
|
* @return the height of a font
|
|
|
|
*/
|
2019-04-23 15:56:59 +02:00
|
|
|
static inline uint8_t lv_font_get_line_height(const lv_font_t * font_p)
|
2017-11-23 20:42:14 +01:00
|
|
|
{
|
2019-05-01 16:43:32 +02:00
|
|
|
return font_p->line_height;
|
2017-11-23 20:42:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-01 16:43:32 +02:00
|
|
|
* Used as `get_glyph_bitmap` callback in LittelvGL's native font format if the font is uncompressed.
|
2018-02-09 12:40:00 +01:00
|
|
|
* @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
|
|
|
|
*/
|
2019-05-01 16:43:32 +02:00
|
|
|
const uint8_t * lv_font_get_glyph_bitmap_plain(const lv_font_t * font, uint32_t letter);
|
2018-02-09 12:40:00 +01:00
|
|
|
|
2018-02-23 13:56:04 +01:00
|
|
|
/**
|
2019-05-01 16:43:32 +02:00
|
|
|
* Used as `get_glyph_dsc` callback in LittelvGL's native font format if the font is uncompressed.
|
|
|
|
* @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`
|
2018-02-23 13:56:04 +01:00
|
|
|
*/
|
2019-05-01 16:43:32 +02:00
|
|
|
bool lv_font_get_glyph_dsc_plain(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, 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
|
|
|
|
2019-05-01 16:43:32 +02:00
|
|
|
#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))
|
2019-04-27 19:37:19 +02: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*/
|