SDL_ttf.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts
  3. Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Sam Lantinga
  16. slouken@libsdl.org
  17. */
  18. /* $Id: SDL_ttf.h,v 1.1 2004/01/31 02:31:29 paigoddess Exp $ */
  19. /* This library is a wrapper around the excellent FreeType 2.0 library,
  20. available at:
  21. http://www.freetype.org/
  22. */
  23. #ifndef _SDLttf_h
  24. #define _SDLttf_h
  25. #include "SDL.h"
  26. #include "begin_code.h"
  27. /* Set up for C function definitions, even when using C++ */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
  32. */
  33. #define TTF_MAJOR_VERSION 2
  34. #define TTF_MINOR_VERSION 0
  35. #define TTF_PATCHLEVEL 6
  36. /* This macro can be used to fill a version structure with the compile-time
  37. * version of the SDL_ttf library.
  38. */
  39. #define TTF_VERSION(X) \
  40. { \
  41. (X)->major = TTF_MAJOR_VERSION; \
  42. (X)->minor = TTF_MINOR_VERSION; \
  43. (X)->patch = TTF_PATCHLEVEL; \
  44. }
  45. /* This function gets the version of the dynamically linked SDL_ttf library.
  46. it should NOT be used to fill a version structure, instead you should
  47. use the TTF_VERSION() macro.
  48. */
  49. extern DECLSPEC const SDL_version * SDLCALL TTF_Linked_Version(void);
  50. /* ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) */
  51. #define UNICODE_BOM_NATIVE 0xFEFF
  52. #define UNICODE_BOM_SWAPPED 0xFFFE
  53. /* This function tells the library whether UNICODE text is generally
  54. byteswapped. A UNICODE BOM character in a string will override
  55. this setting for the remainder of that string.
  56. */
  57. extern DECLSPEC void SDLCALL TTF_ByteSwappedUNICODE(int swapped);
  58. /* The internal structure containing font information */
  59. typedef struct _TTF_Font TTF_Font;
  60. /* Initialize the TTF engine - returns 0 if successful, -1 on error */
  61. extern DECLSPEC int SDLCALL TTF_Init(void);
  62. /* Open a font file and create a font of the specified point size.
  63. * Some .fon fonts will have several sizes embedded in the file, so the
  64. * point size becomes the index of choosing which size. If the value
  65. * is too high, the last indexed size will be the default. */
  66. extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, int ptsize);
  67. extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index);
  68. extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize);
  69. extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index);
  70. /* Set and retrieve the font style
  71. This font style is implemented by modifying the font glyphs, and
  72. doesn't reflect any inherent properties of the truetype font file.
  73. */
  74. #define TTF_STYLE_NORMAL 0x00
  75. #define TTF_STYLE_BOLD 0x01
  76. #define TTF_STYLE_ITALIC 0x02
  77. #define TTF_STYLE_UNDERLINE 0x04
  78. extern DECLSPEC int SDLCALL TTF_GetFontStyle(TTF_Font *font);
  79. extern DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, int style);
  80. /* Get the total height of the font - usually equal to point size */
  81. extern DECLSPEC int SDLCALL TTF_FontHeight(TTF_Font *font);
  82. /* Get the offset from the baseline to the top of the font
  83. This is a positive value, relative to the baseline.
  84. */
  85. extern DECLSPEC int SDLCALL TTF_FontAscent(TTF_Font *font);
  86. /* Get the offset from the baseline to the bottom of the font
  87. This is a negative value, relative to the baseline.
  88. */
  89. extern DECLSPEC int SDLCALL TTF_FontDescent(TTF_Font *font);
  90. /* Get the recommended spacing between lines of text for this font */
  91. extern DECLSPEC int SDLCALL TTF_FontLineSkip(TTF_Font *font);
  92. /* Get the number of faces of the font */
  93. extern DECLSPEC long SDLCALL TTF_FontFaces(TTF_Font *font);
  94. /* Get the font face attributes, if any */
  95. extern DECLSPEC int SDLCALL TTF_FontFaceIsFixedWidth(TTF_Font *font);
  96. extern DECLSPEC char * SDLCALL TTF_FontFaceFamilyName(TTF_Font *font);
  97. extern DECLSPEC char * SDLCALL TTF_FontFaceStyleName(TTF_Font *font);
  98. /* Get the metrics (dimensions) of a glyph */
  99. extern DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
  100. int *minx, int *maxx,
  101. int *miny, int *maxy, int *advance);
  102. /* Get the dimensions of a rendered string of text */
  103. extern DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h);
  104. extern DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
  105. extern DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h);
  106. /* Create an 8-bit palettized surface and render the given text at
  107. fast quality with the given font and color. The 0 pixel is the
  108. colorkey, giving a transparent background, and the 1 pixel is set
  109. to the text color.
  110. This function returns the new surface, or NULL if there was an error.
  111. */
  112. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font,
  113. const char *text, SDL_Color fg);
  114. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font,
  115. const char *text, SDL_Color fg);
  116. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font,
  117. const Uint16 *text, SDL_Color fg);
  118. /* Create an 8-bit palettized surface and render the given glyph at
  119. fast quality with the given font and color. The 0 pixel is the
  120. colorkey, giving a transparent background, and the 1 pixel is set
  121. to the text color. The glyph is rendered without any padding or
  122. centering in the X direction, and aligned normally in the Y direction.
  123. This function returns the new surface, or NULL if there was an error.
  124. */
  125. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font,
  126. Uint16 ch, SDL_Color fg);
  127. /* Create an 8-bit palettized surface and render the given text at
  128. high quality with the given font and colors. The 0 pixel is background,
  129. while other pixels have varying degrees of the foreground color.
  130. This function returns the new surface, or NULL if there was an error.
  131. */
  132. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font,
  133. const char *text, SDL_Color fg, SDL_Color bg);
  134. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Shaded(TTF_Font *font,
  135. const char *text, SDL_Color fg, SDL_Color bg);
  136. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Shaded(TTF_Font *font,
  137. const Uint16 *text, SDL_Color fg, SDL_Color bg);
  138. /* Create an 8-bit palettized surface and render the given glyph at
  139. high quality with the given font and colors. The 0 pixel is background,
  140. while other pixels have varying degrees of the foreground color.
  141. The glyph is rendered without any padding or centering in the X
  142. direction, and aligned normally in the Y direction.
  143. This function returns the new surface, or NULL if there was an error.
  144. */
  145. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font,
  146. Uint16 ch, SDL_Color fg, SDL_Color bg);
  147. /* Create a 32-bit ARGB surface and render the given text at high quality,
  148. using alpha blending to dither the font with the given color.
  149. This function returns the new surface, or NULL if there was an error.
  150. */
  151. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font,
  152. const char *text, SDL_Color fg);
  153. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended(TTF_Font *font,
  154. const char *text, SDL_Color fg);
  155. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended(TTF_Font *font,
  156. const Uint16 *text, SDL_Color fg);
  157. /* Create a 32-bit ARGB surface and render the given glyph at high quality,
  158. using alpha blending to dither the font with the given color.
  159. The glyph is rendered without any padding or centering in the X
  160. direction, and aligned normally in the Y direction.
  161. This function returns the new surface, or NULL if there was an error.
  162. */
  163. extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font,
  164. Uint16 ch, SDL_Color fg);
  165. /* For compatibility with previous versions, here are the old functions */
  166. #define TTF_RenderText(font, text, fg, bg) \
  167. TTF_RenderText_Shaded(font, text, fg, bg)
  168. #define TTF_RenderUTF8(font, text, fg, bg) \
  169. TTF_RenderUTF8_Shaded(font, text, fg, bg)
  170. #define TTF_RenderUNICODE(font, text, fg, bg) \
  171. TTF_RenderUNICODE_Shaded(font, text, fg, bg)
  172. /* Close an opened font file */
  173. extern DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font);
  174. /* De-initialize the TTF engine */
  175. extern DECLSPEC void SDLCALL TTF_Quit(void);
  176. /* Check if the TTF engine is initialized */
  177. extern DECLSPEC int SDLCALL TTF_WasInit(void);
  178. /* We'll use SDL for reporting errors */
  179. #define TTF_SetError SDL_SetError
  180. #define TTF_GetError SDL_GetError
  181. /* Ends C function definitions when using C++ */
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185. #include "close_code.h"
  186. #endif /* _SDLttf_h */