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 Set a font's texture filter
58  * @param[in] font Font handle
59  * @param[in] magFilter the magnification filter
60  * @param[in] minFilter the minification filter
61  */
62 void C2D_FontSetFilter(C2D_Font font, GPU_TEXTURE_FILTER_PARAM magFilter, GPU_TEXTURE_FILTER_PARAM minFilter);
63 
64 /** @brief Find the glyph index of a codepoint, or returns the default
65  * @param[in] font Font to search, or NULL for system font
66  * @param[in] codepoint Codepoint to search for
67  * @returns Glyph index
68  * @retval font->cfnt->finf.alterCharIndex The codepoint does not exist in the font
69  */
70 int C2D_FontGlyphIndexFromCodePoint(C2D_Font font, u32 codepoint);
71 
72 /** @brief Get character width info for a given index
73  * @param[in] font Font to read from, or NULL for system font
74  * @param[in] glyphIndex Index to get the width of
75  * @returns Width info for glyph
76  */
77 charWidthInfo_s* C2D_FontGetCharWidthInfo(C2D_Font font, int glyphIndex);
78 
79 /** @brief Calculate glyph position of given index
80  * @param[in] font Font to read from, or NULL for system font
81  * @param[out] out Glyph position
82  * @param[in] glyphIndex Index to get position of
83  * @param[in] flags Misc flags
84  * @param[in] scaleX Size to scale in X
85  * @param[in] scaleY Size to scale in Y
86  */
87 void C2D_FontCalcGlyphPos(C2D_Font font, fontGlyphPos_s* out, int glyphIndex, u32 flags, float scaleX, float scaleY);
88 
89 /** @brief Get the font info structure associated with the font
90  * @param[in] font Font to read from, or NULL for the system font
91  * @returns FINF associated with the font
92  */
93 FINF_s* C2D_FontGetInfo(C2D_Font font);
94 
95 /** @} */
C2D_Font C2D_FontLoadSystem(CFG_Region region)
Load corresponding font from system archive.
void C2D_FontSetFilter(C2D_Font font, GPU_TEXTURE_FILTER_PARAM magFilter, GPU_TEXTURE_FILTER_PARAM minFilter)
Set a font's texture filter.
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.