microui  14.1.1
microui
ui_font_drawing.h
1 /*
2  * Copyright 2024 MicroEJ Corp. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be found with this software.
4  */
5 
6 #if !defined UI_FONT_DRAWING_H
7 #define UI_FONT_DRAWING_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*
14  * @brief Provides font drawing functions called by ui_drawing.c.
15  *
16  * The default weak functions of ui_drawing.c call the ui_font_drawing.h functions to draw
17  * the font. According to the kind of font (standard or custom), the implementation
18  * of ui_font_drawing.h calls the right font manager functions.
19  *
20  * When the font is a standard font, the implementation calls the Graphics Engine
21  * software algorithms.
22  *
23  * When the font is a custom font, the associated font manager is mandatory (the
24  * Graphics Engine is not able to decode this custom font). The implementation
25  * dispatches the font drawing to this font manager (the custom font manager is
26  * retrieved thanks to the custom font format: MICROUI_FONT_FORMAT_CUSTOM_0 to
27  * MICROUI_FONT_FORMAT_CUSTOM_7).
28  *
29  * Several cases:
30  *
31  * 1- The font manager is available and it is able to draw in the given Graphics
32  * Context: it has to decode the font and draw into the Graphics Context.
33  *
34  * 2- The font manager is available and it is not able to draw in the given Graphics
35  * Context (unknown ouput format) but it is able to draw the font into the Graphics
36  * Context by using the ui_drawing.h functions.
37  *
38  * 3- The font manager is available, it is not able to draw in the given Graphics
39  * Context (unknown ouput format) and it is not able to call standard ui_drawing.h
40  * functions to draw the font: it has to call the stub implementation.
41  *
42  * @author MicroEJ Developer Team
43  * @version 14.1.1
44  */
45 
46 // --------------------------------------------------------------------------------
47 // Includes
48 // --------------------------------------------------------------------------------
49 
50 #include "ui_drawing.h"
51 
52 // --------------------------------------------------------------------------------
53 // Macros and Defines
54 // --------------------------------------------------------------------------------
55 
61 #define MICROUI_FONT_FORMAT_CUSTOM_0_FUNCTIONS_SUFFIX 0
62 #define MICROUI_FONT_FORMAT_CUSTOM_1_FUNCTIONS_SUFFIX 1
63 #define MICROUI_FONT_FORMAT_CUSTOM_2_FUNCTIONS_SUFFIX 2
64 #define MICROUI_FONT_FORMAT_CUSTOM_3_FUNCTIONS_SUFFIX 3
65 #define MICROUI_FONT_FORMAT_CUSTOM_4_FUNCTIONS_SUFFIX 4
66 #define MICROUI_FONT_FORMAT_CUSTOM_5_FUNCTIONS_SUFFIX 5
67 #define MICROUI_FONT_FORMAT_CUSTOM_6_FUNCTIONS_SUFFIX 6
68 #define MICROUI_FONT_FORMAT_CUSTOM_7_FUNCTIONS_SUFFIX 7
69 
74 #define GET_CUSTOM_FONT_FUNCTIONS_SUFFIX(format) CONCAT(format, _FUNCTIONS_SUFFIX)
75 
76 // --------------------------------------------------------------------------------
77 // API
78 // --------------------------------------------------------------------------------
79 
80 /*
81  * @brief Computes the rendered width of a string.
82  * @see UI_DRAWING_stringWidth
83  */
84 jint UI_FONT_DRAWING_stringWidth(jchar *chars, jint length, MICROUI_Font *font);
85 
90 jint UI_FONT_DRAWING_initializeRenderableStringSNIContext(jchar *chars, jint length, MICROUI_Font *font,
91  MICROUI_RenderableString *renderableString);
92 
93 /*
94  * @brief Draws a string.
95  * @see UI_DRAWING_drawString
96  */
97 DRAWING_Status UI_FONT_DRAWING_drawString(MICROUI_GraphicsContext *gc, jchar *chars, jint length, MICROUI_Font *font,
98  jint x, jint y);
99 
104 DRAWING_Status UI_FONT_DRAWING_drawRenderableString(MICROUI_GraphicsContext *gc, jchar *chars, jint length,
105  MICROUI_Font *font, jint width,
106  MICROUI_RenderableString *renderableString, jint x, jint y);
107 
108 /*
109  * @brief Draws a string applying a scaling.
110  * @see UI_DRAWING_drawScaledStringBilinear
111  */
112 DRAWING_Status UI_FONT_DRAWING_drawScaledStringBilinear(MICROUI_GraphicsContext *gc, jchar *chars, jint length,
113  MICROUI_Font *font, jint x, jint y, jfloat xRatio,
114  jfloat yRatio);
115 
116 /*
117  * @brief Draws a renderable string applying a scaling.
118  * @see UI_DRAWING_drawScaledRenderableStringBilinear
119  */
120 DRAWING_Status UI_FONT_DRAWING_drawScaledRenderableStringBilinear(MICROUI_GraphicsContext *gc, jchar *chars,
121  jint length, MICROUI_Font *font, jint width,
122  MICROUI_RenderableString *renderableString, jint x,
123  jint y, jfloat xRatio, jfloat yRatio);
124 
125 /*
126  * @brief Draws a character applying a rotation and an alpha value.
127  * @see UI_DRAWING_drawCharWithRotationBilinear
128  */
129 DRAWING_Status UI_FONT_DRAWING_drawCharWithRotationBilinear(MICROUI_GraphicsContext *gc, jchar c, MICROUI_Font *font,
130  jint x, jint y, jint xRotation, jint yRotation,
131  jfloat angle, jint alpha);
132 
133 /*
134  * @brief Draws a character applying a rotation and an alpha value.
135  * @see UI_DRAWING_drawCharWithRotationNearestNeighbor
136  */
137 DRAWING_Status UI_FONT_DRAWING_drawCharWithRotationNearestNeighbor(MICROUI_GraphicsContext *gc, jchar c,
138  MICROUI_Font *font, jint x, jint y, jint xRotation,
139  jint yRotation, jfloat angle, jint alpha);
140 
141 // --------------------------------------------------------------------------------
142 // EOF
143 // --------------------------------------------------------------------------------
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif // UI_FONT_DRAWING_H