hal_gfx_font.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file hal_gfx_font.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of Graphics library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup GRAPHICS_SDK Graphics
39  * @{
40  */
41 
42 /** @addtogroup HAL_GFX HAL GFX
43  * @{
44  */
45 
46 /** @defgroup HAL_GFX_FONT GFX FONT
47  * @brief Graphics Font function definition.
48  * @{
49  */
50 
51 #ifndef HAL_GFX_FONT_H__
52 #define HAL_GFX_FONT_H__
53 
54 #include "hal_gfx_hal.h"
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 /** @defgroup HAL_GFX_FONT_DEFINITION Defines
61  * @{
62  */
63 #define HAL_GFX_ALIGNX_LEFT (0x00U) /**< Align horizontally to the left */
64 #define HAL_GFX_ALIGNX_RIGHT (0x01U) /**< Align horizontally to the right */
65 #define HAL_GFX_ALIGNX_CENTER (0x02U) /**< Align horizontally centered */
66 #define HAL_GFX_ALIGNX_JUSTIFY (0x03U) /**< Justify horizontally */
67 #define HAL_GFX_ALIGNX_MASK (0x03U) /**< Horizontal alignment mask */
68 #define HAL_GFX_ALIGNY_TOP (0x00U) /**< Align vertically to the top */
69 #define HAL_GFX_ALIGNY_BOTTOM (0x04U) /**< Align vertically to the bottom */
70 #define HAL_GFX_ALIGNY_CENTER (0x08U) /**< Align vertically centered */
71 #define HAL_GFX_ALIGNY_JUSTIFY (0x0cU) /**< Justify vertically */
72 #define HAL_GFX_ALIGNY_MASK (0x0cU) /**< Vertical alignment mask */
73 #define HAL_GFX_TEXT_WRAP (0x10U) /**< Use text wrapping */
74 /** @} */
75 
76 /** @defgroup HAL_GFX_FONT_STRUCT Structures
77  * @{
78  */
79 
80 /**
81  * @brief Font Kerning setting Structure
82  */
83 typedef struct {
84  uint32_t left; /**< Neighbor character to the left of the current one (Unicode value) */
85  int8_t x_offset; /**< Kerning offset (horizontally) */
87 
88 /**
89  * @brief Font glyph setting Structure
90  */
91 typedef struct {
92  uint32_t bitmapOffset; /**< glyph bitmap offset address */
93  uint8_t width; /**< glyph width */
94  uint8_t xAdvance; /**< glyph advanced setting */
95  int8_t xOffset; /**< horizontal offset */
96  int8_t yOffset; /**< vertical offset */
97  uint32_t kern_offset; /**< Kerning offset */
98  uint8_t kern_length; /**< Kerning length */
100 
101 /**
102  * @brief Font range setting Structure
103  */
104 typedef struct {
105  uint32_t first; /**< first font to apply glyphs */
106  uint32_t last; /**< last font to apply glyphs */
107  const hal_gfx_glyph_t *glyphs; /**< pointer to glyphs */
109 
110 /**
111  * @brief Font setting Structure
112  */
113 typedef struct {
114  hal_gfx_buffer_t bo; /**< the base object */
115  const hal_gfx_font_range_t *ranges; /**< the font range */
116  const int bitmap_size; /**< bitmap size */
117  const uint8_t *bitmap; /**< pointer to bitmap */
118  uint32_t flags; /**< specify the flag */
119  uint8_t xAdvance; /**< horizontal advance setting */
120  uint8_t yAdvance; /**< vertical advance setting */
121  uint8_t max_ascender; /**< max ascender setting */
122  uint8_t bpp; /**< bits per pixel setting */
123  const hal_gfx_kern_pair_t *kern_pairs; /**< pointer to kern pair */
125 /** @} */
126 
127 /** @defgroup HAL_GFX_FONT_FUNCTION Functions
128  * @{
129  */
130 
131 
132 /**
133  *****************************************************************************************
134  * @brief Bind the font to use in future hal_gfx_print() calls.
135  *
136  * @param[in] font: Pointer to font
137  *****************************************************************************************
138  */
140 
141 
142 /**
143  *****************************************************************************************
144  * @brief Get the bounding box's width and height of a string.
145  *
146  * @param[in] str: Pointer to string
147  * @param[in] w: Pointer to variable where width should be written
148  * @param[in] h: Pointer to variable where height should be written
149  * @param[in] max_w: Max allowed width
150  * @param[in] wrap: warp mode
151  *
152  * @return Number of carriage returns
153  *****************************************************************************************
154  */
155 int hal_gfx_string_get_bbox(const char *str, int *w, int *h, int max_w, uint32_t wrap);
156 
157 
158 /**
159  *****************************************************************************************
160  * @brief Print pre-formatted text.
161  *
162  * @param[in] str: Pointer to string
163  * @param[in] x: X coordinate of text-area's top-left corner
164  * @param[in] y: Y coordinate of text-area's top-left corner
165  * @param[in] w: Width of the text area
166  * @param[in] h: Height of the text area
167  * @param[in] fg_col: Foreground color of text
168  * @param[in] align: Alignment and wrapping mode
169  *
170  * @return
171  *****************************************************************************************
172  */
173 void hal_gfx_print(const char *str, int x, int y, int w, int h, uint32_t fg_col, uint32_t align);
174 
175 
176 /**
177  *****************************************************************************************
178  * @brief Print pre-formatted text.
179  *
180  * @param[in] str: Pointer to string
181  * @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
182  * @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
183  * @param[in] x: X coordinate of text-area's top-left corner
184  * @param[in] y: Y coordinate of text-area's top-left corner
185  * @param[in] w: Width of the text area
186  * @param[in] h: Height of the text area
187  * @param[in] fg_col: Foreground color of text
188  * @param[in] align: Alignment and wrapping mode
189  *
190  * @return
191  *****************************************************************************************
192  */
193 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);
194 
195 /** @} */
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif // HAL_GFX_FONT_H__
202 
203 /** @} */
204 /** @} */
205 /** @} */
206 
hal_gfx_font_t::bpp
uint8_t bpp
bits per pixel setting
Definition: hal_gfx_font.h:122
hal_gfx_font_t::bitmap_size
const int bitmap_size
bitmap size
Definition: hal_gfx_font.h:116
hal_gfx_font_t::ranges
const hal_gfx_font_range_t * ranges
the font range
Definition: hal_gfx_font.h:115
hal_gfx_glyph_t::xAdvance
uint8_t xAdvance
glyph advanced setting
Definition: hal_gfx_font.h:94
hal_gfx_font_t
Font setting Structure.
Definition: hal_gfx_font.h:113
hal_gfx_glyph_t::yOffset
int8_t yOffset
vertical offset
Definition: hal_gfx_font.h:96
hal_gfx_font_t::yAdvance
uint8_t yAdvance
vertical advance setting
Definition: hal_gfx_font.h:120
hal_gfx_glyph_t::bitmapOffset
uint32_t bitmapOffset
glyph bitmap offset address
Definition: hal_gfx_font.h:92
hal_gfx_kern_pair_t
Font Kerning setting Structure.
Definition: hal_gfx_font.h:83
hal_gfx_font_range_t
Font range setting Structure.
Definition: hal_gfx_font.h:104
hal_gfx_font_range_t::glyphs
const hal_gfx_glyph_t * glyphs
pointer to glyphs
Definition: hal_gfx_font.h:107
hal_gfx_buffer_t_
The base structure of gpu memory.
Definition: hal_gfx_hal.h:75
hal_gfx_glyph_t::xOffset
int8_t xOffset
horizontal offset
Definition: hal_gfx_font.h:95
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
first font to apply glyphs
Definition: hal_gfx_font.h:105
hal_gfx_glyph_t::kern_offset
uint32_t kern_offset
Kerning offset.
Definition: hal_gfx_font.h:97
hal_gfx_glyph_t
Font glyph setting Structure.
Definition: hal_gfx_font.h:91
hal_gfx_glyph_t::width
uint8_t width
glyph width
Definition: hal_gfx_font.h:93
hal_gfx_glyph_t::kern_length
uint8_t kern_length
Kerning length.
Definition: hal_gfx_font.h:98
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
Neighbor character to the left of the current one (Unicode value)
Definition: hal_gfx_font.h:84
hal_gfx_font_t::kern_pairs
const hal_gfx_kern_pair_t * kern_pairs
pointer to kern pair
Definition: hal_gfx_font.h:123
hal_gfx_font_t::max_ascender
uint8_t max_ascender
max ascender setting
Definition: hal_gfx_font.h:121
hal_gfx_font_t::flags
uint32_t flags
specify the flag
Definition: hal_gfx_font.h:118
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
Kerning offset (horizontally)
Definition: hal_gfx_font.h:85
hal_gfx_font_range_t::last
uint32_t last
last font to apply glyphs
Definition: hal_gfx_font.h:106
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
horizontal advance setting
Definition: hal_gfx_font.h:119
hal_gfx_font_t::bo
hal_gfx_buffer_t bo
the base object
Definition: hal_gfx_font.h:114
hal_gfx_font_t::bitmap
const uint8_t * bitmap
pointer to bitmap
Definition: hal_gfx_font.h:117
hal_gfx_hal.h
Header file containing functions prototypes of Graphics library.