acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_font.h (6690B)

      1 /**
      2  * @file lv_font.h
      3  *
      4  */
      5 
      6 #ifndef LV_FONT_H
      7 #define LV_FONT_H
      8 
      9 #ifdef __cplusplus
     10 extern "C" {
     11 #endif
     12 
     13 /*********************
     14  *      INCLUDES
     15  *********************/
     16 #include "../lv_conf_internal.h"
     17 #include <stdint.h>
     18 #include <stddef.h>
     19 #include <stdbool.h>
     20 
     21 #include "lv_symbol_def.h"
     22 #include "../misc/lv_area.h"
     23 
     24 /*********************
     25  *      DEFINES
     26  *********************/
     27 
     28 /* imgfont identifier */
     29 #define LV_IMGFONT_BPP 9
     30 
     31 /**********************
     32  *      TYPEDEFS
     33  **********************/
     34 
     35 /*------------------
     36  * General types
     37  *-----------------*/
     38 
     39 struct _lv_font_t;
     40 /** Describes the properties of a glyph.*/
     41 typedef struct {
     42     const struct _lv_font_t *
     43         resolved_font; /**< Pointer to a font where the glyph was actually found after handling fallbacks*/
     44     uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width.*/
     45     uint16_t box_w; /**< Width of the glyph's bounding box*/
     46     uint16_t box_h; /**< Height of the glyph's bounding box*/
     47     int16_t ofs_x;  /**< x offset of the bounding box*/
     48     int16_t ofs_y;  /**< y offset of the bounding box*/
     49     uint8_t bpp: 4;  /**< Bit-per-pixel: 1, 2, 4, 8*/
     50     uint8_t is_placeholder: 1; /** Glyph is missing. But placeholder will still be displayed */
     51 } lv_font_glyph_dsc_t;
     52 
     53 /** The bitmaps might be upscaled by 3 to achieve subpixel rendering.*/
     54 enum {
     55     LV_FONT_SUBPX_NONE,
     56     LV_FONT_SUBPX_HOR,
     57     LV_FONT_SUBPX_VER,
     58     LV_FONT_SUBPX_BOTH,
     59 };
     60 
     61 typedef uint8_t lv_font_subpx_t;
     62 
     63 /** Describe the properties of a font*/
     64 typedef struct _lv_font_t {
     65     /** Get a glyph's descriptor from a font*/
     66     bool (*get_glyph_dsc)(const struct _lv_font_t *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next);
     67 
     68     /** Get a glyph's bitmap from a font*/
     69     const uint8_t * (*get_glyph_bitmap)(const struct _lv_font_t *, uint32_t);
     70 
     71     /*Pointer to the font in a font pack (must have the same line height)*/
     72     lv_coord_t line_height;         /**< The real line height where any text fits*/
     73     lv_coord_t base_line;           /**< Base line measured from the top of the line_height*/
     74     uint8_t subpx  : 2;             /**< An element of `lv_font_subpx_t`*/
     75 
     76     int8_t underline_position;      /**< Distance between the top of the underline and base line (< 0 means below the base line)*/
     77     int8_t underline_thickness;     /**< Thickness of the underline*/
     78 
     79     const void * dsc;               /**< Store implementation specific or run_time data or caching here*/
     80     const struct _lv_font_t * fallback;   /**< Fallback font for missing glyph. Resolved recursively */
     81 #if LV_USE_USER_DATA
     82     void * user_data;               /**< Custom user data for font.*/
     83 #endif
     84 } lv_font_t;
     85 
     86 /**********************
     87  * GLOBAL PROTOTYPES
     88  **********************/
     89 
     90 /**
     91  * Return with the bitmap of a font.
     92  * @param font_p pointer to a font
     93  * @param letter a UNICODE character code
     94  * @return pointer to the bitmap of the letter
     95  */
     96 const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter);
     97 
     98 /**
     99  * Get the descriptor of a glyph
    100  * @param font_p pointer to font
    101  * @param dsc_out store the result descriptor here
    102  * @param letter a UNICODE letter code
    103  * @param letter_next the next letter after `letter`. Used for kerning
    104  * @return true: descriptor is successfully loaded into `dsc_out`.
    105  *         false: the letter was not found, no data is loaded to `dsc_out`
    106  */
    107 bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter,
    108                            uint32_t letter_next);
    109 
    110 /**
    111  * Get the width of a glyph with kerning
    112  * @param font pointer to a font
    113  * @param letter a UNICODE letter
    114  * @param letter_next the next letter after `letter`. Used for kerning
    115  * @return the width of the glyph
    116  */
    117 uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next);
    118 
    119 /**
    120  * Get the line height of a font. All characters fit into this height
    121  * @param font_p pointer to a font
    122  * @return the height of a font
    123  */
    124 static inline lv_coord_t lv_font_get_line_height(const lv_font_t * font_p)
    125 {
    126     return font_p->line_height;
    127 }
    128 
    129 /**********************
    130  *      MACROS
    131  **********************/
    132 
    133 #define LV_FONT_DECLARE(font_name) extern const lv_font_t font_name;
    134 
    135 #if LV_FONT_MONTSERRAT_8
    136 LV_FONT_DECLARE(lv_font_montserrat_8)
    137 #endif
    138 
    139 #if LV_FONT_MONTSERRAT_10
    140 LV_FONT_DECLARE(lv_font_montserrat_10)
    141 #endif
    142 
    143 #if LV_FONT_MONTSERRAT_12
    144 LV_FONT_DECLARE(lv_font_montserrat_12)
    145 #endif
    146 
    147 #if LV_FONT_MONTSERRAT_14
    148 LV_FONT_DECLARE(lv_font_montserrat_14)
    149 #endif
    150 
    151 #if LV_FONT_MONTSERRAT_16
    152 LV_FONT_DECLARE(lv_font_montserrat_16)
    153 #endif
    154 
    155 #if LV_FONT_MONTSERRAT_18
    156 LV_FONT_DECLARE(lv_font_montserrat_18)
    157 #endif
    158 
    159 #if LV_FONT_MONTSERRAT_20
    160 LV_FONT_DECLARE(lv_font_montserrat_20)
    161 #endif
    162 
    163 #if LV_FONT_MONTSERRAT_22
    164 LV_FONT_DECLARE(lv_font_montserrat_22)
    165 #endif
    166 
    167 #if LV_FONT_MONTSERRAT_24
    168 LV_FONT_DECLARE(lv_font_montserrat_24)
    169 #endif
    170 
    171 #if LV_FONT_MONTSERRAT_26
    172 LV_FONT_DECLARE(lv_font_montserrat_26)
    173 #endif
    174 
    175 #if LV_FONT_MONTSERRAT_28
    176 LV_FONT_DECLARE(lv_font_montserrat_28)
    177 #endif
    178 
    179 #if LV_FONT_MONTSERRAT_30
    180 LV_FONT_DECLARE(lv_font_montserrat_30)
    181 #endif
    182 
    183 #if LV_FONT_MONTSERRAT_32
    184 LV_FONT_DECLARE(lv_font_montserrat_32)
    185 #endif
    186 
    187 #if LV_FONT_MONTSERRAT_34
    188 LV_FONT_DECLARE(lv_font_montserrat_34)
    189 #endif
    190 
    191 #if LV_FONT_MONTSERRAT_36
    192 LV_FONT_DECLARE(lv_font_montserrat_36)
    193 #endif
    194 
    195 #if LV_FONT_MONTSERRAT_38
    196 LV_FONT_DECLARE(lv_font_montserrat_38)
    197 #endif
    198 
    199 #if LV_FONT_MONTSERRAT_40
    200 LV_FONT_DECLARE(lv_font_montserrat_40)
    201 #endif
    202 
    203 #if LV_FONT_MONTSERRAT_42
    204 LV_FONT_DECLARE(lv_font_montserrat_42)
    205 #endif
    206 
    207 #if LV_FONT_MONTSERRAT_44
    208 LV_FONT_DECLARE(lv_font_montserrat_44)
    209 #endif
    210 
    211 #if LV_FONT_MONTSERRAT_46
    212 LV_FONT_DECLARE(lv_font_montserrat_46)
    213 #endif
    214 
    215 #if LV_FONT_MONTSERRAT_48
    216 LV_FONT_DECLARE(lv_font_montserrat_48)
    217 #endif
    218 
    219 #if LV_FONT_MONTSERRAT_12_SUBPX
    220 LV_FONT_DECLARE(lv_font_montserrat_12_subpx)
    221 #endif
    222 
    223 #if LV_FONT_MONTSERRAT_28_COMPRESSED
    224 LV_FONT_DECLARE(lv_font_montserrat_28_compressed)
    225 #endif
    226 
    227 #if LV_FONT_DEJAVU_16_PERSIAN_HEBREW
    228 LV_FONT_DECLARE(lv_font_dejavu_16_persian_hebrew)
    229 #endif
    230 
    231 #if LV_FONT_SIMSUN_16_CJK
    232 LV_FONT_DECLARE(lv_font_simsun_16_cjk)
    233 #endif
    234 
    235 #if LV_FONT_UNSCII_8
    236 LV_FONT_DECLARE(lv_font_unscii_8)
    237 #endif
    238 
    239 #if LV_FONT_UNSCII_16
    240 LV_FONT_DECLARE(lv_font_unscii_16)
    241 #endif
    242 
    243 /*Declare the custom (user defined) fonts*/
    244 #ifdef LV_FONT_CUSTOM_DECLARE
    245 LV_FONT_CUSTOM_DECLARE
    246 #endif
    247 
    248 /**
    249  * Just a wrapper around LV_FONT_DEFAULT because it might be more convenient to use a function in some cases
    250  * @return  pointer to LV_FONT_DEFAULT
    251  */
    252 static inline const lv_font_t * lv_font_default(void)
    253 {
    254     return LV_FONT_DEFAULT;
    255 }
    256 
    257 #ifdef __cplusplus
    258 } /*extern "C"*/
    259 #endif
    260 
    261 #endif /*USE_FONT*/