hal_gfx_font.h
Go to the documentation of this file.
1 /** @addtogroup GRAPHICS_SDK Graphics
2  * @{
3  */
4 
5 /** @defgroup HAL_GFX_FONT Graphics Font
6  * @brief Graphics Font function definition.
7  * @{
8  */
9 
10 #ifndef HAL_GFX_FONT_H__
11 #define HAL_GFX_FONT_H__
12 
13 #include "hal_gfx_hal.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /** @defgroup HAL_GFX_FONT_DEFINITION Defines
20  * @{
21  */
22 #define HAL_GFX_ALIGNX_LEFT (0x00U) /**< Align horizontally to the left */
23 #define HAL_GFX_ALIGNX_RIGHT (0x01U) /**< Align horizontally to the right */
24 #define HAL_GFX_ALIGNX_CENTER (0x02U) /**< Align horizontally centered */
25 #define HAL_GFX_ALIGNX_JUSTIFY (0x03U) /**< Justify horizontally */
26 #define HAL_GFX_ALIGNX_MASK (0x03U) /**< Horizontal alignment mask */
27 #define HAL_GFX_ALIGNY_TOP (0x00U) /**< Align vertically to the top */
28 #define HAL_GFX_ALIGNY_BOTTOM (0x04U) /**< Align vertically to the bottom */
29 #define HAL_GFX_ALIGNY_CENTER (0x08U) /**< Align vertically centered */
30 #define HAL_GFX_ALIGNY_JUSTIFY (0x0cU) /**< Justify vertically */
31 #define HAL_GFX_ALIGNY_MASK (0x0cU) /**< Vertical alignment mask */
32 #define HAL_GFX_TEXT_WRAP (0x10U) /**< Use text wrapping */
33 /** @} */
34 
35 /** @defgroup HAL_GFX_FONT_STRUCT Structures
36  * @{
37  */
38 
39 /**
40  * @brief Font Kerning setting Structure
41  */
42 typedef struct {
43  uint32_t left; /**< Neighbor character to the left of the current one (Unicode value) */
44  int8_t x_offset; /**< Kerning offset (horizontally) */
46 
47 /**
48  * @brief Font glyph setting Structure
49  */
50 typedef struct {
51  uint32_t bitmapOffset; /**< glyph bitmap offset address */
52  uint8_t width; /**< glyph width */
53  uint8_t xAdvance; /**< glyph advanced setting */
54  int8_t xOffset; /**< horizontal offset */
55  int8_t yOffset; /**< vertical offset */
56  uint32_t kern_offset; /**< Kerning offset */
57  uint8_t kern_length; /**< Kerning length */
59 
60 /**
61  * @brief Font range setting Structure
62  */
63 typedef struct {
64  uint32_t first; /**< first font to apply glyphs */
65  uint32_t last; /**< last font to apply glyphs */
66  const hal_gfx_glyph_t *glyphs; /**< pointer to glyphs */
68 
69 /**
70  * @brief Font setting Structure
71  */
72 typedef struct {
73  hal_gfx_buffer_t bo; /**< the base object */
74  const hal_gfx_font_range_t *ranges; /**< the font range */
75  const int bitmap_size; /**< bitmap size */
76  const uint8_t *bitmap; /**< pointer to bitmap */
77  uint32_t flags; /**< specify the flag */
78  uint8_t xAdvance; /**< horizontal advance setting */
79  uint8_t yAdvance; /**< vertical advance setting */
80  uint8_t max_ascender; /**< max ascender setting */
81  uint8_t bpp; /**< bits per pixel setting */
82  const hal_gfx_kern_pair_t *kern_pairs; /**< pointer to kern pair */
84 /** @} */
85 
86 /** @defgroup HAL_GFX_FONT_FUNCTION Functions
87  * @{
88  */
89 
90 
91 /**
92  *****************************************************************************************
93  * @brief Bind the font to use in future hal_gfx_print() calls.
94  *
95  * @param[in] font: Pointer to font
96  *****************************************************************************************
97  */
99 
100 
101 /**
102  *****************************************************************************************
103  * @brief Get the bounding box's width and height of a string.
104  *
105  * @param[in] str: Pointer to string
106  * @param[in] w: Pointer to variable where width should be written
107  * @param[in] h: Pointer to variable where height should be written
108  * @param[in] max_w: Max allowed width
109  * @param[in] wrap: warp mode
110  *
111  * @return Number of carriage returns
112  *****************************************************************************************
113  */
114 int hal_gfx_string_get_bbox(const char *str, int *w, int *h, int max_w, uint32_t wrap);
115 
116 
117 /**
118  *****************************************************************************************
119  * @brief Print pre-formatted text.
120  *
121  * @param[in] str: Pointer to string
122  * @param[in] x: X coordinate of text-area's top-left corner
123  * @param[in] y: Y coordinate of text-area's top-left corner
124  * @param[in] w: Width of the text area
125  * @param[in] h: Height of the text area
126  * @param[in] fg_col: Foreground color of text
127  * @param[in] align: Alignment and wrapping mode
128  *
129  * @return
130  *****************************************************************************************
131  */
132 void hal_gfx_print(const char *str, int x, int y, int w, int h, uint32_t fg_col, uint32_t align);
133 
134 
135 /**
136  *****************************************************************************************
137  * @brief Print pre-formatted text.
138  *
139  * @param[in] str: Pointer to string
140  * @param[in] pos_x: X position of next character to be drawn. Usually initialized to 0 by the user and then updated internally by the library
141  * @param[in] pos_y: Y position of next character to be drawn. Usually initialized to 0 by the user and then updated internally by the library
142  * @param[in] x: X coordinate of text-area's top-left corner
143  * @param[in] y: Y coordinate of text-area's top-left corner
144  * @param[in] w: Width of the text area
145  * @param[in] h: Height of the text area
146  * @param[in] fg_col: Foreground color of text
147  * @param[in] align: Alignment and wrapping mode
148  *
149  * @return
150  *****************************************************************************************
151  */
152 void hal_gfx_print_to_position(const char *str, int *pos_x, int *pos_y, int x, int y, int w, int h, uint32_t fg_col, uint32_t align);
153 
154 /** @} */
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif // HAL_GFX_FONT_H__
161 
162 /** @} */
163 /** @} */
hal_gfx_font_t::bpp
uint8_t bpp
Definition: hal_gfx_font.h:81
hal_gfx_font_t::bitmap_size
const int bitmap_size
Definition: hal_gfx_font.h:75
hal_gfx_font_t::ranges
const hal_gfx_font_range_t * ranges
Definition: hal_gfx_font.h:74
hal_gfx_glyph_t::xAdvance
uint8_t xAdvance
Definition: hal_gfx_font.h:53
hal_gfx_font_t
Font setting Structure.
Definition: hal_gfx_font.h:72
hal_gfx_glyph_t::yOffset
int8_t yOffset
Definition: hal_gfx_font.h:55
hal_gfx_font_t::yAdvance
uint8_t yAdvance
Definition: hal_gfx_font.h:79
hal_gfx_glyph_t::bitmapOffset
uint32_t bitmapOffset
Definition: hal_gfx_font.h:51
hal_gfx_kern_pair_t
Font Kerning setting Structure.
Definition: hal_gfx_font.h:42
hal_gfx_font_range_t
Font range setting Structure.
Definition: hal_gfx_font.h:63
hal_gfx_font_range_t::glyphs
const hal_gfx_glyph_t * glyphs
Definition: hal_gfx_font.h:66
hal_gfx_buffer_t_
The base structure of gpu memory.
Definition: hal_gfx_hal.h:36
hal_gfx_glyph_t::xOffset
int8_t xOffset
Definition: hal_gfx_font.h:54
hal_gfx_print
void hal_gfx_print(const char *str, int x, int y, int w, int h, uint32_t fg_col, uint32_t align)
Print pre-formatted text.
hal_gfx_font_range_t::first
uint32_t first
Definition: hal_gfx_font.h:64
hal_gfx_glyph_t::kern_offset
uint32_t kern_offset
Definition: hal_gfx_font.h:56
hal_gfx_glyph_t
Font glyph setting Structure.
Definition: hal_gfx_font.h:50
hal_gfx_glyph_t::width
uint8_t width
Definition: hal_gfx_font.h:52
hal_gfx_glyph_t::kern_length
uint8_t kern_length
Definition: hal_gfx_font.h:57
hal_gfx_string_get_bbox
int hal_gfx_string_get_bbox(const char *str, int *w, int *h, int max_w, uint32_t wrap)
Get the bounding box's width and height of a string.
hal_gfx_kern_pair_t::left
uint32_t left
Definition: hal_gfx_font.h:43
hal_gfx_font_t::kern_pairs
const hal_gfx_kern_pair_t * kern_pairs
Definition: hal_gfx_font.h:82
hal_gfx_font_t::max_ascender
uint8_t max_ascender
Definition: hal_gfx_font.h:80
hal_gfx_font_t::flags
uint32_t flags
Definition: hal_gfx_font.h:77
hal_gfx_print_to_position
void hal_gfx_print_to_position(const char *str, int *pos_x, int *pos_y, int x, int y, int w, int h, uint32_t fg_col, uint32_t align)
Print pre-formatted text.
hal_gfx_kern_pair_t::x_offset
int8_t x_offset
Definition: hal_gfx_font.h:44
hal_gfx_font_range_t::last
uint32_t last
Definition: hal_gfx_font.h:65
hal_gfx_bind_font
void hal_gfx_bind_font(hal_gfx_font_t *font)
Bind the font to use in future hal_gfx_print() calls.
hal_gfx_font_t::xAdvance
uint8_t xAdvance
Definition: hal_gfx_font.h:78
hal_gfx_font_t::bo
hal_gfx_buffer_t bo
Definition: hal_gfx_font.h:73
hal_gfx_font_t::bitmap
const uint8_t * bitmap
Definition: hal_gfx_font.h:76
hal_gfx_hal.h