citro2d
font.h
Go to the documentation of this file.
1 /**
2  * @file font.h
3  * @brief Font loading and management
4  */
5 #pragma once
6 #include "base.h"
7 
8 struct C2D_Font_s;
9 typedef struct C2D_Font_s* C2D_Font;
10 
11 /** @defgroup Font Font functions
12  * @{
13  */
14 
15 /** @brief Load a font from a file
16  * @param[in] filename Name of the font file (.bcfnt)
17  * @returns Font handle
18  * @retval NULL Error
19  */
20 C2D_Font C2D_FontLoad(const char* filename);
21 
22 /** @brief Load a font from memory
23  * @param[in] data Data to load
24  * @param[in] size Size of the data to load
25  * @returns Font handle
26  * @retval NULL Error
27  */
28 C2D_Font C2D_FontLoadFromMem(const void* data, size_t size);
29 
30 /** @brief Load a font from file descriptor
31  * @param[in] fd File descriptor used to load data
32  * @returns Font handle
33  * @retval NULL Error
34  */
35 C2D_Font C2D_FontLoadFromFD(int fd);
36 
37 /** @brief Load font from stdio file handle
38  * @param[in] f File handle used to load data
39  * @returns Font handle
40  * @retval NULL Error
41  */
42 C2D_Font C2D_FontLoadFromHandle(FILE* f);
43 
44 /** @brief Load corresponding font from system archive
45  * @param[in] region Region to get font from
46  * @returns Font handle
47  * @retval NULL Error
48  * @remark JPN, USA, EUR, and AUS all use the same font.
49  */
50 C2D_Font C2D_FontLoadSystem(CFG_Region region);
51 
52 /** @brief Free a font
53  * @param[in] font Font handle
54  */
55 void C2D_FontFree(C2D_Font font);
56 
57 /** @brief Find the glyph index of a codepoint, or returns the default
58  * @param[in] font Font to search, or NULL for system font
59  * @param[in] codepoint Codepoint to search for
60  * @returns Glyph index
61  * @retval font->cfnt->finf.alterCharIndex The codepoint does not exist in the font
62  */
63 int C2D_FontGlyphIndexFromCodePoint(C2D_Font font, u32 codepoint);
64 
65 /** @brief Get character width info for a given index
66  * @param[in] font Font to read from, or NULL for system font
67  * @param[in] glyphIndex Index to get the width of
68  * @returns Width info for glyph
69  */
70 charWidthInfo_s* C2D_FontGetCharWidthInfo(C2D_Font font, int glyphIndex);
71 
72 /** @brief Calculate glyph position of given index
73  * @param[in] font Font to read from, or NULL for system font
74  * @param[out] out Glyph position
75  * @param[in] glyphIndex Index to get position of
76  * @param[in] flags Misc flags
77  * @param[in] scaleX Size to scale in X
78  * @param[in] scaleY Size to scale in Y
79  */
80 void C2D_FontCalcGlyphPos(C2D_Font font, fontGlyphPos_s* out, int glyphIndex, u32 flags, float scaleX, float scaleY);
81 
82 /** @brief Get the font info structure associated with the font
83  * @param[in] font Font to read from, or NULL for the system font
84  * @returns FINF associated with the font
85  */
86 FINF_s* C2D_FontGetInfo(C2D_Font font);
87 
88 /** @} */
C2D_Font C2D_FontLoadSystem(CFG_Region region)
Load corresponding font from system archive.
C2D_Font C2D_FontLoad(const char *filename)
Load a font from a file.
void C2D_FontFree(C2D_Font font)
Free a font.
void C2D_FontCalcGlyphPos(C2D_Font font, fontGlyphPos_s *out, int glyphIndex, u32 flags, float scaleX, float scaleY)
Calculate glyph position of given index.
C2D_Font C2D_FontLoadFromHandle(FILE *f)
Load font from stdio file handle.
C2D_Font C2D_FontLoadFromMem(const void *data, size_t size)
Load a font from memory.
FINF_s * C2D_FontGetInfo(C2D_Font font)
Get the font info structure associated with the font.
Basic citro2d initialization and drawing API.
charWidthInfo_s * C2D_FontGetCharWidthInfo(C2D_Font font, int glyphIndex)
Get character width info for a given index.
int C2D_FontGlyphIndexFromCodePoint(C2D_Font font, u32 codepoint)
Find the glyph index of a codepoint, or returns the default.
C2D_Font C2D_FontLoadFromFD(int fd)
Load a font from file descriptor.