SDL_ttf.h 13 KB

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