Plutonium framework API  0.3
Simple UI framework for libnx and SDL2
ttf_SDL_ttf.h
Go to the documentation of this file.
1 /*
2  SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts
3  Copyright (C) 2001-2013 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 /* This library is a wrapper around the excellent FreeType 2.0 library,
23  available at:
24  http://www.freetype.org/
25 */
26 
27 #ifndef _SDL_TTF_H
28 #define _SDL_TTF_H
29 
30 #include <SDL2/SDL.h>
31 #include <SDL2/begin_code.h>
32 
33 #include <switch.h>
34 
35 /* Set up for C function definitions, even when using C++ */
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
41 */
42 #define SDL_TTF_MAJOR_VERSION 2
43 #define SDL_TTF_MINOR_VERSION 0
44 #define SDL_TTF_PATCHLEVEL 12
45 
46 /* This macro can be used to fill a version structure with the compile-time
47  * version of the SDL_ttf library.
48  */
49 #define SDL_TTF_VERSION(X) \
50 { \
51  (X)->major = SDL_TTF_MAJOR_VERSION; \
52  (X)->minor = SDL_TTF_MINOR_VERSION; \
53  (X)->patch = SDL_TTF_PATCHLEVEL; \
54 }
55 
56 /* Backwards compatibility */
57 #define TTF_MAJOR_VERSION SDL_TTF_MAJOR_VERSION
58 #define TTF_MINOR_VERSION SDL_TTF_MINOR_VERSION
59 #define TTF_PATCHLEVEL SDL_TTF_PATCHLEVEL
60 #define TTF_VERSION(X) SDL_TTF_VERSION(X)
61 
62 /* This function gets the version of the dynamically linked SDL_ttf library.
63  it should NOT be used to fill a version structure, instead you should
64  use the SDL_TTF_VERSION() macro.
65  */
66 extern DECLSPEC const SDL_version * SDLCALL TTF_Linked_Version(void);
67 
68 /* ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) */
69 #define UNICODE_BOM_NATIVE 0xFEFF
70 #define UNICODE_BOM_SWAPPED 0xFFFE
71 
72 /* This function tells the library whether UNICODE text is generally
73  byteswapped. A UNICODE BOM character in a string will override
74  this setting for the remainder of that string.
75 */
76 extern DECLSPEC void SDLCALL TTF_ByteSwappedUNICODE(int swapped);
77 
78 /* The internal structure containing font information */
79 typedef struct _TTF_Font TTF_Font;
80 
81 /* Initialize the TTF engine - returns 0 if successful, -1 on error */
82 extern DECLSPEC int SDLCALL TTF_Init(void);
83 
84 /* Open a font file and create a font of the specified point size.
85  * Some .fon fonts will have several sizes embedded in the file, so the
86  * point size becomes the index of choosing which size. If the value
87  * is too high, the last indexed size will be the default. */
88 extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, int ptsize);
89 extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index);
90 extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize);
91 extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index);
92 
93 /* Set and retrieve the font style */
94 #define TTF_STYLE_NORMAL 0x00
95 #define TTF_STYLE_BOLD 0x01
96 #define TTF_STYLE_ITALIC 0x02
97 #define TTF_STYLE_UNDERLINE 0x04
98 #define TTF_STYLE_STRIKETHROUGH 0x08
99 extern DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font);
100 extern DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, int style);
101 extern DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font);
102 extern DECLSPEC void SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline);
103 
104 /* Set and retrieve FreeType hinter settings */
105 #define TTF_HINTING_NORMAL 0
106 #define TTF_HINTING_LIGHT 1
107 #define TTF_HINTING_MONO 2
108 #define TTF_HINTING_NONE 3
109 extern DECLSPEC int SDLCALL TTF_GetFontHinting(const TTF_Font *font);
110 extern DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, int hinting);
111 
112 /* Get the total height of the font - usually equal to point size */
113 extern DECLSPEC int SDLCALL TTF_FontHeight(const TTF_Font *font);
114 
115 /* Get the offset from the baseline to the top of the font
116  This is a positive value, relative to the baseline.
117  */
118 extern DECLSPEC int SDLCALL TTF_FontAscent(const TTF_Font *font);
119 
120 /* Get the offset from the baseline to the bottom of the font
121  This is a negative value, relative to the baseline.
122  */
123 extern DECLSPEC int SDLCALL TTF_FontDescent(const TTF_Font *font);
124 
125 /* Get the recommended spacing between lines of text for this font */
126 extern DECLSPEC int SDLCALL TTF_FontLineSkip(const TTF_Font *font);
127 
128 /* Get/Set whether or not kerning is allowed for this font */
129 extern DECLSPEC int SDLCALL TTF_GetFontKerning(const TTF_Font *font);
130 extern DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, int allowed);
131 
132 /* Get the number of faces of the font */
133 extern DECLSPEC long SDLCALL TTF_FontFaces(const TTF_Font *font);
134 
135 /* Get the font face attributes, if any */
136 extern DECLSPEC int SDLCALL TTF_FontFaceIsFixedWidth(const TTF_Font *font);
137 extern DECLSPEC char * SDLCALL TTF_FontFaceFamilyName(const TTF_Font *font);
138 extern DECLSPEC char * SDLCALL TTF_FontFaceStyleName(const TTF_Font *font);
139 
140 /* Check wether a glyph is provided by the font or not */
141 extern DECLSPEC int SDLCALL TTF_GlyphIsProvided(const TTF_Font *font, Uint16 ch);
142 
143 /* Get the metrics (dimensions) of a glyph
144  To understand what these metrics mean, here is a useful link:
145  http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
146  */
147 extern DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
148  int *minx, int *maxx,
149  int *miny, int *maxy, int *advance);
150 
151 /* Get the dimensions of a rendered string of text */
152 extern DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h);
153 extern DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
154 extern DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h);
155 
156 /* Create an 8-bit palettized surface and render the given text at
157  fast quality with the given font and color. The 0 pixel is the
158  colorkey, giving a transparent background, and the 1 pixel is set
159  to the text color.
160  This function returns the new surface, or NULL if there was an error.
161 */
162 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font,
163  const char *text, SDL_Color fg);
164 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font,
165  const char *text, SDL_Color fg);
166 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font,
167  const Uint16 *text, SDL_Color fg);
168 
169 /* Create an 8-bit palettized surface and render the given glyph at
170  fast quality with the given font and color. The 0 pixel is the
171  colorkey, giving a transparent background, and the 1 pixel is set
172  to the text color. The glyph is rendered without any padding or
173  centering in the X direction, and aligned normally in the Y direction.
174  This function returns the new surface, or NULL if there was an error.
175 */
176 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font,
177  Uint16 ch, SDL_Color fg);
178 
179 /* Create an 8-bit palettized surface and render the given text at
180  high quality with the given font and colors. The 0 pixel is background,
181  while other pixels have varying degrees of the foreground color.
182  This function returns the new surface, or NULL if there was an error.
183 */
184 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font,
185  const char *text, SDL_Color fg, SDL_Color bg);
186 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Shaded(TTF_Font *font,
187  const char *text, SDL_Color fg, SDL_Color bg);
188 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Shaded(TTF_Font *font,
189  const Uint16 *text, SDL_Color fg, SDL_Color bg);
190 
191 /* Create an 8-bit palettized surface and render the given glyph at
192  high quality with the given font and colors. The 0 pixel is background,
193  while other pixels have varying degrees of the foreground color.
194  The glyph is rendered without any padding or centering in the X
195  direction, and aligned normally in the Y direction.
196  This function returns the new surface, or NULL if there was an error.
197 */
198 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font,
199  Uint16 ch, SDL_Color fg, SDL_Color bg);
200 
201 /* Create a 32-bit ARGB surface and render the given text at high quality,
202  using alpha blending to dither the font with the given color.
203  This function returns the new surface, or NULL if there was an error.
204 */
205 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font,
206  const char *text, SDL_Color fg);
207 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended(TTF_Font *font,
208  const char *text, SDL_Color fg);
209 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended(TTF_Font *font,
210  const Uint16 *text, SDL_Color fg);
211 
212 
213 /* Create a 32-bit ARGB surface and render the given text at high quality,
214  using alpha blending to dither the font with the given color.
215  Text is wrapped to multiple lines on line endings and on word boundaries
216  if it extends beyond wrapLength in pixels.
217  This function returns the new surface, or NULL if there was an error.
218 */
219 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font,
220  const char *text, SDL_Color fg, Uint32 wrapLength);
221 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended_Wrapped(TTF_Font *font,
222  const char *text, SDL_Color fg, Uint32 wrapLength);
223 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended_Wrapped(TTF_Font *font,
224  const Uint16 *text, SDL_Color fg, Uint32 wrapLength);
225 
226 /* Create a 32-bit ARGB surface and render the given glyph at high quality,
227  using alpha blending to dither the font with the given color.
228  The glyph is rendered without any padding or centering in the X
229  direction, and aligned normally in the Y direction.
230  This function returns the new surface, or NULL if there was an error.
231 */
232 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font,
233  Uint16 ch, SDL_Color fg);
234 
235 /* For compatibility with previous versions, here are the old functions */
236 #define TTF_RenderText(font, text, fg, bg) \
237  TTF_RenderText_Shaded(font, text, fg, bg)
238 #define TTF_RenderUTF8(font, text, fg, bg) \
239  TTF_RenderUTF8_Shaded(font, text, fg, bg)
240 #define TTF_RenderUNICODE(font, text, fg, bg) \
241  TTF_RenderUNICODE_Shaded(font, text, fg, bg)
242 
243 /* Close an opened font file */
244 extern DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font);
245 
246 /* De-initialize the TTF engine */
247 extern DECLSPEC void SDLCALL TTF_Quit(void);
248 
249 /* Check if the TTF engine is initialized */
250 extern DECLSPEC int SDLCALL TTF_WasInit(void);
251 
252 /* Get the kerning size of two glyphs */
253 extern DECLSPEC int TTF_GetFontKerningSize(TTF_Font *font, int prev_index, int index);
254 
255 /* Code present in C++ code */
256 TTF_Font *TTF_CppWrap_FindValidFont(TTF_Font *font, Uint16 ch);
257 
258 /* Get the pointer to the C++ data */
260 
261 /* Set the pointer to the C++ data */
262 void TTF_CppWrap_SetCppPtrRef(TTF_Font *font, void *cpp_ptr_ref);
263 
264 /* We'll use SDL for reporting errors */
265 #define TTF_SetError SDL_SetError
266 #define TTF_GetError SDL_GetError
267 
268 #define TMP_LOG(str) { const char *cstr = str; svcOutputDebugString(cstr, strlen(cstr)); }
269 
270 /* Ends C function definitions when using C++ */
271 #ifdef __cplusplus
272 }
273 #endif
274 #include <SDL2/close_code.h>
275 
276 #endif /* _SDL_TTF_H */
DECLSPEC SDL_Surface *SDLCALL TTF_RenderText_Shaded(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg)
DECLSPEC void SDLCALL TTF_Quit(void)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderUTF8_Blended(TTF_Font *font, const char *text, SDL_Color fg)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font, Uint16 ch, SDL_Color fg)
void * TTF_CppWrap_GetCppPtrRef(TTF_Font *font)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderUNICODE_Shaded(TTF_Font *font, const Uint16 *text, SDL_Color fg, SDL_Color bg)
DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h)
DECLSPEC void SDLCALL TTF_ByteSwappedUNICODE(int swapped)
DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, int style)
DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, Uint16 ch, SDL_Color fg)
DECLSPEC int TTF_GetFontKerningSize(TTF_Font *font, int prev_index, int index)
DECLSPEC int SDLCALL TTF_WasInit(void)
TTF_Font * TTF_CppWrap_FindValidFont(TTF_Font *font, Uint16 ch)
DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h)
DECLSPEC char *SDLCALL TTF_FontFaceStyleName(const TTF_Font *font)
DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderUNICODE_Blended(TTF_Font *font, const Uint16 *text, SDL_Color fg)
DECLSPEC int SDLCALL TTF_FontDescent(const TTF_Font *font)
struct _TTF_Font TTF_Font
Definition: ttf_SDL_ttf.h:79
DECLSPEC int SDLCALL TTF_FontHeight(const TTF_Font *font)
DECLSPEC char *SDLCALL TTF_FontFaceFamilyName(const TTF_Font *font)
DECLSPEC int SDLCALL TTF_FontLineSkip(const TTF_Font *font)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderUNICODE_Blended_Wrapped(TTF_Font *font, const Uint16 *text, SDL_Color fg, Uint32 wrapLength)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, SDL_Color fg)
DECLSPEC const SDL_version *SDLCALL TTF_Linked_Version(void)
DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h)
DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, int allowed)
DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font)
DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance)
DECLSPEC long SDLCALL TTF_FontFaces(const TTF_Font *font)
DECLSPEC int SDLCALL TTF_GlyphIsProvided(const TTF_Font *font, Uint16 ch)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength)
DECLSPEC int SDLCALL TTF_GetFontHinting(const TTF_Font *font)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font, Uint16 ch, SDL_Color fg, SDL_Color bg)
DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, int hinting)
DECLSPEC TTF_Font *SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderUTF8_Shaded(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font, const Uint16 *text, SDL_Color fg)
DECLSPEC int SDLCALL TTF_FontFaceIsFixedWidth(const TTF_Font *font)
DECLSPEC TTF_Font *SDLCALL TTF_OpenFont(const char *file, int ptsize)
DECLSPEC void SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline)
void TTF_CppWrap_SetCppPtrRef(TTF_Font *font, void *cpp_ptr_ref)
DECLSPEC int SDLCALL TTF_FontAscent(const TTF_Font *font)
DECLSPEC TTF_Font *SDLCALL TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize)
DECLSPEC TTF_Font *SDLCALL TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index)
DECLSPEC int SDLCALL TTF_GetFontKerning(const TTF_Font *font)
DECLSPEC int SDLCALL TTF_Init(void)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderUTF8_Blended_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength)
DECLSPEC SDL_Surface *SDLCALL TTF_RenderText_Blended(TTF_Font *font, const char *text, SDL_Color fg)