MPLABĀ® Harmony Graphics Suite  GFX v3.13.0
Legato API Documentation
legato_font.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries.
3 *
4 * Subject to your compliance with these terms, you may use Microchip software
5 * and any derivatives exclusively with Microchip products. It is your
6 * responsibility to comply with third party license terms applicable to your
7 * use of third party software (including open source software) that may
8 * accompany Microchip software.
9 *
10 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
11 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
12 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
13 * PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
16 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
17 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
18 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
19 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
20 * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
21 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
22 *******************************************************************************/
23 
24 /*******************************************************************************
25  Module for Microchip Graphics Library - Legato User Interface Library
26 
27  Company:
28  Microchip Technology Inc.
29 
30  File Name:
31  legato_font.h
32 
33  Summary:
34  Describes font assets
35 
36  Description:
37  Type definitions.
38 *******************************************************************************/
39 
46 #ifndef LE_FONT_H
47 #define LE_FONT_H
48 
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 // *****************************************************************************
61 typedef enum leFontBPP
62 {
65 } leFontBPP;
66 
67 // *****************************************************************************
68 /* Structure:
69  struct leFontGlyph
70 
71  Summary:
72  Describes a font glyph. A glyph is an individual character of a font.
73  Each glyph contains kerning data and options unique to itself. This
74  data is used for proper glyph positioning when rendering text.
75 
76  leChar codePoint - the code point of the glyph
77  int16_t width - the glyph's overall width
78  int16_t height - the glyph's overall height
79  int16_t advance - the amount the cursor should advance when preparing to
80  render this glyph
81  int16_t bearingX - the X offset from the advance
82  int16_t bearingY - the Y offset from the string baseline
83  uint16_t flags - general purpose flags
84  uint16_t dataRowWidth - the width of one row of glyph data in bytes
85  uint32_t dataOffset - the offset of this glyph in the font glyph table
86 */
93 typedef struct leFontGlyph
94 {
95  leChar codePoint;
96  int16_t width;
97  int16_t height;
98  int16_t advance;
99  int16_t bearingX;
100  int16_t bearingY;
101  uint16_t flags;
102  uint16_t dataRowWidth;
103  uint32_t dataOffset;
104 } leFontGlyph;
105 
106 // *****************************************************************************
107 /* Enumeration:
108  enum leFontType
109 
110  Summary:
111  Defines font types. Currently only raster fonts are supported but this
112  differentiation will allow for future expansion into vector font support.
113 */
119 typedef enum leFontType
120 {
121  LE_RASTER_FONT,
122  LE_VECTOR_FONT
123 } leFontType;
124 
125 // *****************************************************************************
126 /* Enumeration:
127  enum leFontFlags
128 
129  Summary:
130  Defines font attribute flags.
131 */
135 typedef enum leFontFlags
136 {
137  LE_FONT_RIGHTTOLEFT = 0x1, // indicates that the font should be rendered right
138  // to left
139 } leFontFlags;
140 
141 // *****************************************************************************
142 /* Structure:
143  struct leFont
144 
145  Summary:
146  The base definition of a font object.
147 
148  leStreamDescriptor header - describes where the font data is located
149  leFontType type - indicates the type of font
150  uint32_t flags - flags describing the font
151 */
156 typedef struct leFont
157 {
158  leStreamDescriptor header;
159  leFontType type;
160  uint32_t flags;
161 } leFont;
162 
163 // *****************************************************************************
164 /* Structure:
165  leFontAsset
166 
167  Summary:
168  Describes a rasterized font object. A raster font asset is a series of
169  raster images that represent linguistic characters. These characters are
170  referenced by an index called a 'code point'. This code point is 1-2 bytes
171  in length. Code points may be encoded to save space. Fonts also contain
172  general kerning data that describes character positioning data.
173 
174  struct leFont base - base font data
175  uint16_t height - font height in pixels
176  uint16_t baseline - the general font baseline in pixels;
177  leFontBPP bpp - the bits per pixel value of this font.
178  const uint8_t* glyphTable - pointer to the font's glyph data table
179 */
188 typedef struct leRasterFont
189 {
190  struct leFont base;
191  uint16_t height;
192  uint16_t baseline;
193  leFontBPP bpp;
194  const uint8_t* glyphTable;
195 } leRasterFont;
196 
197 #if LE_STREAMING_ENABLED == 1
198 // *****************************************************************************
203 typedef void (*leFontStream_DrawCompleteFn)(uint32_t codepoint);
204 
205 // *****************************************************************************
206 /* Structure:
207  struct leFontStream
208 
209  Summary:
210  A specialized stream object that is capable of streaming and rendering
211  font glyph data
212 
213  leStream stream - base stream data
214  leResult open - function that opens this stream
215  leResult drawGlyph - function that streams and renders font glyph data
216 
217  Arguments:
218  const leFontGlyph* glyph - the glyph to render
219  int32_t x - screen X location to render the glyph
220  int32_t y - screen Y location to render the glyph
221  leColor clr - the glyph render color
222  uint32_t alpha - a global alpha value to apply
223  leFontStream_DrawCompleteFn cb - callback to be called when the glyph
224  finished drawing
225 
226  leBool isDone - function that queries if the stream is finished
227  void close - function that closes the stream
228 
229  leFontStream_DrawCompleteFn cb - callback that indicates when the stream has finished a particular code point
230 */
235 typedef struct leFontStream
236 {
237  leStream stream;
238 
239  leResult (*open)(void);
240  leResult (*drawGlyph)(const leFontGlyph* glyph, int32_t x, int32_t y, leColor clr, uint32_t alpha, const leBlendLookupTable* lookupTable, leFontStream_DrawCompleteFn cb);
241  leBool (*isDone)(void);
242  void (*close)(void);
243 
244  leFontStream_DrawCompleteFn cb;
245 } leFontStream;
246 #endif
247 
248 #if LE_INCLUDE_DEFAULT_1BPP_FONT == 1
249 // *****************************************************************************
250 /* Type:
251  leRasterFont LiberationMono1
252 
253  Summary:
254  A pre-defined 12 point monospaced 1bpp font that includes the standard
255  ASCII range of characters.
256 */
257 extern leRasterFont LiberationMono1;
258 #endif
259 
260 #if LE_INCLUDE_DEFAULT_8BPP_FONT == 1
261 // *****************************************************************************
262 /* Type:
263  lleRasterFont LiberationMono8
264 
265  Summary:
266  A pre-defined 12 point monospaced 8bpp font that includes the standard
267  ASCII range of characters.
268 */
269 extern leRasterFont LiberationMono8;
270 #endif
271 
272 // *****************************************************************************
273 /* Function:
274  leResult leFont_GetGlyphInfo(const leFont* fnt,
275  uint32_t codepoint,
276  leFontGlyph* glyph)
277 
278  Summary:
279  Given a font asset and a codepoint, retrieves the glyph kerning data from
280  the font glyph data table.
281 
282  Parameters:
283  const leFont* fnt - the font to query
284  uint32_t codepoint - the codepoint to lookup
285  leFontGlyph* glyph - the glyph data that was retrieved
286 
287  Returns:
288 
289  Remarks:
290 */
305  uint32_t codepoint,
306  leFontGlyph* glyph);
307 
308 // *****************************************************************************
309 /* Function:
310  leResult leFont_GetGlyphRect(const leFontGlyph* glyph,
311  leRect* rect)
312 
313  Summary:
314  Given a font asset and a codepoint, retrieves the glyph rectangle in pixels.
315 
316  Parameters:
317  const leFontGlyph* glyph - the glyph kerning information
318  leRect* rect - the glyph rectangle in pixels
319 
320  Returns:
321 
322  Remarks:
323 */
338  leRect* rect);
339 
340 // *****************************************************************************
341 /* Function:
342  leResult leFont_DrawGlyph(const leFont* fnt,
343  const leFontGlyph* glyph,
344  int32_t x,
345  int32_t y,
346  leColor clr,
347  uint32_t a)
348 
349  Summary:
350  Draws a glyph
351 
352  Parameters:
353  const leFont* fnt - the font object to draw
354  const leFontGlyph* glyph - the glyph kerning information
355  int32_t x - the screen x location to draw
356  int32_t y - the screen y location to draw
357  leColor clr - the glyph render color
358  uint32_t alpha - a global alpha value to apply
359 
360  Returns:
361 
362  Remarks:
363 */
379 leResult leFont_DrawGlyph(const leFont* fnt,
380  const leFontGlyph* glyph,
381  int32_t x,
382  int32_t y,
383  leColor clr,
384  uint32_t a);
385 
403  const leFontGlyph* glyph,
404  int32_t x,
405  int32_t y,
406  const leBlendLookupTable* tbl);
407 
408 // *****************************************************************************
409 /* Function:
410  leResult leFont_DrawGlyphData(const leFont* fnt,
411  const leFontGlyph* glyph,
412  const uint8_t* data,
413  int32_t x,
414  int32_t y,
415  leColor clr,
416  uint32_t a)
417 
418  Summary:
419  Draws a glyph from a raw data buffer
420 
421  Parameters:
422  const leFont* fnt - the font object to draw
423  const leFontGlyph* glyph - the glyph kerning information
424  const uint8_t* data - the data buffer to reference
425  int32_t x - the screen x location to draw
426  int32_t y - the screen y location to draw
427  leColor clr - the glyph render color
428  uint32_t alpha - a global alpha value to apply
429 
430  Returns:
431 
432  Remarks:
433 */
450  const leFontGlyph* glyph,
451  const uint8_t* data,
452  int32_t x,
453  int32_t y,
454  leColor clr,
455  uint32_t a);
456 
474  const leFontGlyph* glyph,
475  const uint8_t* data,
476  int32_t x,
477  int32_t y,
478  const leBlendLookupTable* tbl);
479 
480 #if LE_STREAMING_ENABLED == 1
481 // *****************************************************************************
482 /* Function:
483  leFontStream* leFont_GetStream(const leFont* fnt)
484 
485  Summary:
486  Creates a font stream for a given font
487 
488  Parameters:
489  const leFont* fnt - the font to stream
490 
491  Returns:
492 
493  Remarks:
494 */
505 leFontStream* leFont_GetStream(const leFont* fnt);
506 #endif
507 
508 #ifdef __cplusplus
509 }
510 #endif
511 
512 #endif /* LE_FONT_H */
leResult leFont_GetGlyphRect(const leFontGlyph *glyph, leRect *rect)
Get glyph rectangle.
Definition: legato_font.c:229
Color definitions and functions.
leResult leFont_DrawGlyphData_Lookup(const leFont *fnt, const leFontGlyph *glyph, const uint8_t *data, int32_t x, int32_t y, const leBlendLookupTable *tbl)
Draws a glyph using a provided font and color lookup table.
Definition: legato_font.c:383
struct leFont leFont
This struct represents a font object.
struct leRasterFont leRasterFont
This struct represents a rasterized font object.
Definition: legato_font.h:64
leFontType
This enum represents a font type.
Definition: legato_font.h:119
This struct represents a font object.
Definition: legato_font.h:156
leResult leFont_DrawGlyph_Lookup(const leFont *fnt, const leFontGlyph *glyph, int32_t x, int32_t y, const leBlendLookupTable *tbl)
Draws a glyph using a provided font and color lookup table.
Definition: legato_font.c:510
Definition: legato_font.h:63
leResult
This enum represents function call results.
Definition: legato_common.h:123
This struct represents a stream descriptor.
Definition: legato_stream.h:60
This struct represents a rectangle.
Definition: legato_common.h:394
leResult leFont_DrawGlyphData(const leFont *fnt, const leFontGlyph *glyph, const uint8_t *data, int32_t x, int32_t y, leColor clr, uint32_t a)
Draws a glyph.
Definition: legato_font.c:300
struct leFontGlyph leFontGlyph
This struct represents a font glyph.
This struct represents a blend color lookup table.
Definition: legato_color.h:293
leResult leFont_DrawGlyph(const leFont *fnt, const leFontGlyph *glyph, int32_t x, int32_t y, leColor clr, uint32_t a)
Draws a glyph.
Definition: legato_font.c:476
This struct represents a rasterized font object.
Definition: legato_font.h:188
leBool
This enum represents booleans.
Definition: legato_common.h:146
leFontFlags
Defines font attribute flags.
Definition: legato_font.h:135
leFontBPP
This enum represents a font.
Definition: legato_font.h:61
This struct represents a font glyph.
Definition: legato_font.h:93
uint16_t leChar
This typedef represents Legato character.
Definition: legato_common.h:414
leResult leFont_GetGlyphInfo(const leFont *fnt, uint32_t codepoint, leFontGlyph *glyph)
Get glyph info.
Definition: legato_font.c:173
Defines a common header for all stream operations.