Arm-2D  
2D Image Processing Library for Cortex-M Processors
arm_2d_helper_font.h
1/*
2 * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/* ----------------------------------------------------------------------
20 * Project: Arm-2D Library
21 * Title: #include "arm_2d_helper_font.h"
22 * Description: the font helper service header file
23 *
24 * $Date: 03. Dec 2024
25 * $Revision: V.2.7.6
26 *
27 * Target Processor: Cortex-M cores
28 * -------------------------------------------------------------------- */
29
30#ifndef __ARM_2D_HELPER_FONT_H__
31#define __ARM_2D_HELPER_FONT_H__
32
33/*============================ INCLUDES ======================================*/
34#include <stdint.h>
35#include "arm_2d_helper.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#if defined(__clang__)
42# pragma clang diagnostic push
43# pragma clang diagnostic ignored "-Wunknown-warning-option"
44# pragma clang diagnostic ignored "-Wreserved-identifier"
45# pragma clang diagnostic ignored "-Wmissing-declarations"
46# pragma clang diagnostic ignored "-Wpadded"
47#elif __IS_COMPILER_ARM_COMPILER_5__
48# pragma diag_suppress 64
49#elif __IS_COMPILER_GCC__
50# pragma GCC diagnostic push
51# pragma GCC diagnostic ignored "-Wformat="
52# pragma GCC diagnostic ignored "-Wpedantic"
53# pragma GCC diagnostic ignored "-Wpadded"
54#endif
55
56
57/*============================ MACROS ========================================*/
58#ifndef __GLCD_CFG_COLOUR_DEPTH__
59# warning Please specify the colour depth by defining the macro __GLCD_CFG_COLOUR_DEPTH__, default value 16 is used for now
60# define __GLCD_CFG_COLOUR_DEPTH__ 16
61#endif
62
63/*!
64 * \addtogroup Deprecated
65 * @{
66 */
67/*! todo: COLOUR_INT_TYPE is deprecated, should be removed in the future */
68#if __GLCD_CFG_COLOUR_DEPTH__ == 8
69# define COLOUR_INT_TYPE uint8_t
70
71#elif __GLCD_CFG_COLOUR_DEPTH__ == 16
72# define COLOUR_INT_TYPE uint16_t
73
74#elif __GLCD_CFG_COLOUR_DEPTH__ == 32
75# define COLOUR_INT_TYPE uint32_t
76
77#else
78# error Unsupported colour depth!
79#endif
80
81/*! @} */
82
83
84#ifndef __GLCD_CFG_SCEEN_WIDTH__
85#warning Please specify the screen width by defining the macro __GLCD_CFG_SCEEN_WIDTH__, default value 320 is used for now
86#define __GLCD_CFG_SCEEN_WIDTH__ 320
87#endif
88
89#ifndef __GLCD_CFG_SCEEN_HEIGHT__
90# warning Please specify the screen height by defining the macro __GLCD_CFG_SCEEN_HEIGHT__, default value 240 is used for now
91# define __GLCD_CFG_SCEEN_HEIGHT__ 320
92#endif
93
94
95/*!
96 * \addtogroup gHelper 8 Helper Services
97 * @{
98 */
99/*============================ MACROFIED FUNCTIONS ===========================*/
100
101#if 0 // TODO in the future version when string alignment feature is available
102#define arm_lcd_banner_printf(__REGION, __FONT_PTR, __FORMAT_STR, ...) \
103 do { \
104 if (NULL != (__FONT_PTR)) { \
105 arm_lcd_text_set_font((const arm_2d_font_t *)(__FONT_PTR)); \
106 } \
107 arm_2d_region_t ARM_2D_SAFE_NAME(tTargetRegion) = (__REGION); \
108 arm_2d_align_centre( \
109 ARM_2D_SAFE_NAME(tTargetRegion), \
110 arm_lcd_get_string_line_box((__STR),(__FONT_PTR))) {\
111 arm_lcd_text_set_draw_region(&__centre_region); \
112 arm_lcd_printf(__FORMAT_STR, ##__VA_ARGS__); \
113 } \
114 } while(0)
115#endif
116
117#define __arm_print_banner3(__STR, __REGION, __FONT_PTR) \
118 do { \
119 if (NULL != (__FONT_PTR)) { \
120 arm_lcd_text_set_font((const arm_2d_font_t *)(__FONT_PTR)); \
121 } \
122 arm_2d_region_t ARM_2D_SAFE_NAME(tTargetRegion) = (__REGION); \
123 arm_2d_align_centre( \
124 ARM_2D_SAFE_NAME(tTargetRegion), \
125 arm_lcd_get_string_line_box((__STR),(__FONT_PTR))) {\
126 arm_lcd_text_set_draw_region(&__centre_region); \
127 arm_lcd_puts(__STR); \
128 } \
129 } while(0)
130
131#define __arm_print_banner2(__STR, __REGION) \
132 __arm_print_banner3(__STR, __REGION, NULL)
133
134#define __arm_print_banner1(__STR) \
135 do { \
136 arm_2d_tile_t *ARM_2D_SAFE_NAME(ptTile) \
137 = arm_2d_get_default_frame_buffer(); \
138 arm_2d_canvas(ARM_2D_SAFE_NAME(ptTile), __banner_canvas) { \
139 __arm_print_banner3(__STR, __banner_canvas, NULL); \
140 } \
141 } while(0)
142
143#define arm_print_banner(...) \
144 ARM_CONNECT2( __arm_print_banner, \
145 __ARM_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
146
147#define arm_lcd_print_banner(...) arm_print_banner(__VA_ARGS__)
148
149#define arm_lcd_get_string_line_box(__STR, ...) \
150 __arm_lcd_get_string_line_box( \
151 (__STR), \
152 (const arm_2d_font_t *)(NULL, ##__VA_ARGS__))
153
154#define IMPL_FONT_DRAW_CHAR(__NAME) \
155 arm_fsm_rt_t __NAME(const arm_2d_tile_t *ptTile, \
156 const arm_2d_region_t *ptRegion, \
157 const arm_2d_font_t *ptFont, \
158 arm_2d_tile_t *ptileChar, \
159 COLOUR_INT tForeColour, \
160 uint_fast8_t chOpacity, \
161 float fScale)
162
163#define IMPL_FONT_GET_CHAR_DESCRIPTOR(__NAME) \
164 arm_2d_char_descriptor_t *__NAME( \
165 const arm_2d_font_t *ptFont, \
166 arm_2d_char_descriptor_t *ptDescriptor, \
167 uint8_t *pchCharCode)
168
169/*============================ TYPES =========================================*/
170
171typedef struct {
172 arm_2d_tile_t tileChar;
173 int16_t iAdvance;
174 int16_t iBearingX;
175 int16_t iBearingY;
176 int8_t chCodeLength;
177 int8_t : 8;
179
180typedef struct arm_2d_font_t arm_2d_font_t;
181
182typedef arm_2d_char_descriptor_t *arm_2d_font_get_char_descriptor_handler_t(
183 const arm_2d_font_t *ptFont,
184 arm_2d_char_descriptor_t *ptDescriptor,
185 uint8_t *pchCharCode);
186
187typedef arm_fsm_rt_t arm_2d_font_draw_char_handler_t(
188 const arm_2d_tile_t *ptTile,
189 const arm_2d_region_t *ptRegion,
190 const arm_2d_font_t *ptFont,
191 arm_2d_tile_t *ptileChar,
192 COLOUR_INT tForeColour,
193 uint_fast8_t chOpacity,
194 float fScale);
195
196/* Font definitions */
198 arm_2d_tile_t tileFont;
200 uint32_t nCount; //!< Character count
201
202 arm_2d_font_get_char_descriptor_handler_t *fnGetCharDescriptor; //!< On-Get-Char-Descriptor event handler
203 arm_2d_font_draw_char_handler_t *fnDrawChar; //!< On-Draw-Char event handler
204};
205
206typedef struct arm_2d_char_idx_t {
207 uint8_t chStartCode[4];
208 uint16_t hwCount;
209 uint16_t hwOffset;
211
212typedef struct arm_2d_user_font_t {
213 implement(arm_2d_font_t);
214 uint16_t hwCount;
215 uint16_t hwDefaultCharIndex;
216 arm_2d_char_idx_t tLookUpTable[];
218
219typedef struct arm_2d_a1_font_t {
220 implement(arm_2d_font_t);
221 uint32_t nOffset; //!< Character offset
223
224/*============================ GLOBAL VARIABLES ==============================*/
225
226extern const arm_2d_a1_font_t ARM_2D_FONT_16x24;
227extern const arm_2d_a1_font_t ARM_2D_FONT_6x8;
228
229extern
230arm_2d_font_get_char_descriptor_handler_t
231 ARM_2D_A1_FONT_GET_CHAR_DESCRIPTOR_HANDLER;
232
233/*============================ PROTOTYPES ====================================*/
234
235/*!
236 * \brief return a valid code length of a given UTF8 char
237 * \param[in] pchChar the start address of an UTF8 char
238 * \retval -1 this isn't a legal UTF8 char
239 * \retval >0 the UTF8 char length
240 */
241ARM_NONNULL(1)
242int8_t arm_2d_helper_get_utf8_byte_valid_length(const uint8_t *pchChar);
243
244/*!
245 * \brief return the code length based on the first byte of a given UTF8 char
246 * \param[in] pchChar the start address of an UTF8 char
247 * \retval -1 this isn't a legal UTF8 char
248 * \retval >0 the UTF8 char length
249 */
250ARM_NONNULL(1)
251int8_t arm_2d_helper_get_utf8_byte_length(const uint8_t *pchChar);
252
253
254/*!
255 * \brief convert an UTF8 char into unicode char
256 *
257 * \param[in] pchUTF8
258 * \return uint32_t generated unicode
259 */
260ARM_NONNULL(1)
261extern
262uint32_t arm_2d_helper_utf8_to_unicode(const uint8_t *pchUTF8);
263
264/*!
265 * \brief get char descriptor
266 * \param[in] ptFont the target font
267 * \param[in] ptDescriptor a buffer to store a char descriptor
268 * \param[in] pchCharCode an UTF8 Char
269 * \return arm_2d_char_descriptor_t * the descriptor
270 */
271ARM_NONNULL(1,2,3)
274 arm_2d_char_descriptor_t *ptDescriptor,
275 uint8_t *pchCharCode);
276
277/*!
278 * \brief initialize lcd text display service
279 * \param[in] ptScreen the default display area
280 */
281extern
283
284extern
285int arm_lcd_printf(const char *format, ...);
286
287extern
288ARM_NONNULL(1)
289void arm_lcd_puts_label( const char *pchString,
290 arm_2d_align_t tAlignment);
291
292
293extern
294ARM_NONNULL(2)
295int arm_lcd_printf_label(arm_2d_align_t tAlignment, const char *format, ...);
296
297extern
298void arm_lcd_puts(const char *str);
299
300extern
301void arm_lcd_text_location(uint8_t chY, uint8_t chX);
302
303extern
304void arm_lcd_text_reset_display_region_tracking(void);
305
306extern
307arm_2d_region_t *arm_lcd_text_get_last_display_region(void);
308
309/*!
310 * \brief draw a char to a given location in the draw region
311 * \param[in] iX the x coordinate
312 * \param[in] iY the y coordinate
313 * \param[in] ppchCharCode a pointer of pointer that points to the string
314 *
315 * \note this function will advance the pointer automatically
316 *
317 * \param[in] chOpacity the opacity of the char
318 *
319 * \note this chOpacity has NO effect on the default monochrome(A1) font
320 *
321 * \return int16_t char advance in pixels
322 */
323extern
324int16_t lcd_draw_char(int16_t iX,
325 int16_t iY,
326 uint8_t **ppchCharCode,
327 uint_fast8_t chOpacity);
328
329extern
330void arm_lcd_putchar(const char *str);
331
332extern
333void arm_lcd_text_set_colour( COLOUR_INT wForeground,
334 COLOUR_INT wBackground);
335
336extern
337void arm_lcd_text_set_opacity(uint8_t chOpacity);
338
339extern
340void arm_lcd_text_set_scale(float fScale);
341
342/*!
343 * \brief Force all char use the same width
344 *
345 * \param[in] bForced force or not
346 * \return boolean the original configuration
347 */
348extern
350
351extern
352void arm_lcd_text_set_target_framebuffer(const arm_2d_tile_t *ptFrameBuffer);
353
354/*!
355 * \brief set the display mode for characters
356 * \param[in] wMode the display mode which could be the combination of following
357 enum values:
358 - ARM_2D_DRW_PATN_MODE_COPY (default) - Copy without background colour
359 - ARM_2D_DRW_PATN_MODE_WITH_BG_COLOR - with background colour
360 - ARM_2D_DRW_PATN_MODE_NO_FG_COLOR - without foreground colour
361 - ARM_2D_DRW_PATH_MODE_COMP_FG_COLOUR - use complement value as the foreground colour
362 */
363
364extern
365void arm_lcd_text_set_display_mode(uint32_t wMode);
366
367extern
368void arm_lcd_text_set_draw_region(arm_2d_region_t *ptRegion);
369
370extern
371arm_2d_err_t arm_lcd_text_set_font(const arm_2d_font_t *ptFont);
372
373extern
374arm_2d_size_t __arm_lcd_get_string_line_box(const char *str, const arm_2d_font_t *ptFont);
375
376extern
377IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a8_font_draw_char);
378
379extern
380IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a4_font_draw_char);
381
382extern
383IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a2_font_draw_char);
384
385extern
386IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a1_font_draw_char);
387
388/*! @} */
389
390#if defined(__clang__)
391# pragma clang diagnostic pop
392#elif __IS_COMPILER_GCC__
393# pragma GCC diagnostic pop
394#endif
395
396#ifdef __cplusplus
397}
398#endif
399
400#endif