Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.     SDL_ttf:  A companion library to SDL for working with TrueType (tm) fonts
  3.     Copyright (C) 1997  Sam Lantinga
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19.     Sam Lantinga
  20.     5635-34 Springhouse Dr.
  21.     Pleasanton, CA 94588 (USA)
  22.     slouken@devolution.com
  23. */
  24.  
  25. /* This library is a wrapper around the excellent FreeType 1.0 library,
  26.    available at:
  27.         http://www.physiol.med.tu-muenchen.de/~robert/freetype.html
  28. */
  29.  
  30. #ifndef _SDLttf_h
  31. #define _SDLttf_h
  32.  
  33. #include "SDL.h"
  34. #include "begin_code.h"
  35.  
  36. /* Set up for C function definitions, even when using C++ */
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.  
  41. /* The internal structure containing font information */
  42. typedef struct _TTF_Font TTF_Font;
  43.  
  44. /* Initialize the TTF engine - returns 0 if successful, -1 on error */
  45. extern DECLSPEC int TTF_Init(void);
  46.  
  47. /* Open a font file and create a font of the specified point size */
  48. extern DECLSPEC TTF_Font *TTF_OpenFont(const char *file, int ptsize);
  49.  
  50. /* Set and retrieve the font style
  51.    This font style is implemented by modifying the font glyphs, and
  52.    doesn't reflect any inherent properties of the truetype font file.
  53. */
  54. #define TTF_STYLE_NORMAL        0x00
  55. #define TTF_STYLE_BOLD          0x01
  56. #define TTF_STYLE_ITALIC        0x02
  57. #define TTF_STYLE_UNDERLINE     0x04
  58. extern DECLSPEC int TTF_GetFontStyle(TTF_Font *font);
  59. extern DECLSPEC void TTF_SetFontStyle(TTF_Font *font, int style);
  60.  
  61. /* Get the total height of the font - usually equal to point size */
  62. extern DECLSPEC int TTF_FontHeight(TTF_Font *font);
  63.  
  64. /* Get the offset from the baseline to the top of the font
  65.    This is a positive value, relative to the baseline.
  66.  */
  67. extern DECLSPEC int TTF_FontAscent(TTF_Font *font);
  68.  
  69. /* Get the offset from the baseline to the bottom of the font
  70.    This is a negative value, relative to the baseline.
  71.  */
  72. extern DECLSPEC int TTF_FontDescent(TTF_Font *font);
  73.  
  74. /* Get the recommended spacing between lines of text for this font */
  75. extern DECLSPEC int TTF_FontLineSkip(TTF_Font *font);
  76.  
  77. /* Get the metrics (dimensions) of a glyph */
  78. extern DECLSPEC int TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
  79.                                      int *minx, int *maxx,
  80.                                      int *miny, int *maxy, int *advance);
  81.  
  82. /* Get the dimensions of a rendered string of text */
  83. extern DECLSPEC int TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h);
  84. extern DECLSPEC int TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
  85. extern DECLSPEC int TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h);
  86.  
  87. /* Create an 8-bit palettized surface and render the given text at
  88.    fast quality with the given font and color.  The 0 pixel is the
  89.    colorkey, giving a transparent background, and the 1 pixel is set
  90.    to the text color.
  91.    This function returns the new surface, or NULL if there was an error.
  92. */
  93. extern DECLSPEC SDL_Surface *TTF_RenderText_Solid(TTF_Font *font,
  94.                                 const char *text, SDL_Color fg);
  95. extern DECLSPEC SDL_Surface *TTF_RenderUTF8_Solid(TTF_Font *font,
  96.                                 const char *text, SDL_Color fg);
  97. extern DECLSPEC SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
  98.                                 const Uint16 *text, SDL_Color fg);
  99.  
  100. /* Create an 8-bit palettized surface and render the given glyph at
  101.    fast quality with the given font and color.  The 0 pixel is the
  102.    colorkey, giving a transparent background, and the 1 pixel is set
  103.    to the text color.  The glyph is rendered without any padding or
  104.    centering in the X direction, and aligned normally in the Y direction.
  105.    This function returns the new surface, or NULL if there was an error.
  106. */
  107. extern DECLSPEC SDL_Surface *TTF_RenderGlyph_Solid(TTF_Font *font,
  108.                                         Uint16 ch, SDL_Color fg);
  109.  
  110. /* Create an 8-bit palettized surface and render the given text at
  111.    high quality with the given font and colors.  The 0 pixel is background,
  112.    while other pixels have varying degrees of the foreground color.
  113.    This function returns the new surface, or NULL if there was an error.
  114. */
  115. extern DECLSPEC SDL_Surface *TTF_RenderText_Shaded(TTF_Font *font,
  116.                                 const char *text, SDL_Color fg, SDL_Color bg);
  117. extern DECLSPEC SDL_Surface *TTF_RenderUTF8_Shaded(TTF_Font *font,
  118.                                 const char *text, SDL_Color fg, SDL_Color bg);
  119. extern DECLSPEC SDL_Surface *TTF_RenderUNICODE_Shaded(TTF_Font *font,
  120.                                 const Uint16 *text, SDL_Color fg, SDL_Color bg);
  121.  
  122. /* Create an 8-bit palettized surface and render the given glyph at
  123.    high quality with the given font and colors.  The 0 pixel is background,
  124.    while other pixels have varying degrees of the foreground color.
  125.    The glyph is rendered without any padding or centering in the X
  126.    direction, and aligned normally in the Y direction.
  127.    This function returns the new surface, or NULL if there was an error.
  128. */
  129. extern DECLSPEC SDL_Surface *TTF_RenderGlyph_Shaded(TTF_Font *font,
  130.                                 Uint16 ch, SDL_Color fg, SDL_Color bg);
  131.  
  132. /* Create a 32-bit ARGB surface and render the given text at high quality,
  133.    using alpha blending to dither the font with the given color.
  134.    This function returns the new surface, or NULL if there was an error.
  135. */
  136. extern DECLSPEC SDL_Surface *TTF_RenderText_Blended(TTF_Font *font,
  137.                                 const char *text, SDL_Color fg);
  138. extern DECLSPEC SDL_Surface *TTF_RenderUTF8_Blended(TTF_Font *font,
  139.                                 const char *text, SDL_Color fg);
  140. extern DECLSPEC SDL_Surface *TTF_RenderUNICODE_Blended(TTF_Font *font,
  141.                                 const Uint16 *text, SDL_Color fg);
  142.  
  143. /* Create a 32-bit ARGB surface and render the given glyph at high quality,
  144.    using alpha blending to dither the font with the given color.
  145.    The glyph is rendered without any padding or centering in the X
  146.    direction, and aligned normally in the Y direction.
  147.    This function returns the new surface, or NULL if there was an error.
  148. */
  149. extern DECLSPEC SDL_Surface *TTF_RenderGlyph_Blended(TTF_Font *font,
  150.                                                 Uint16 ch, SDL_Color fg);
  151.  
  152. /* For compatibility with previous versions, here are the old functions */
  153. #define TTF_RenderText(font, text, fg, bg)      \
  154.         TTF_RenderText_Shaded(font, text, fg, bg)
  155. #define TTF_RenderUTF8(font, text, fg, bg)      \
  156.         TTF_RenderUTF8_Shaded(font, text, fg, bg)
  157. #define TTF_RenderUNICODE(font, text, fg, bg)   \
  158.         TTF_RenderUNICODE_Shaded(font, text, fg, bg)
  159.  
  160. /* Close an opened font file */
  161. extern DECLSPEC void TTF_CloseFont(TTF_Font *font);
  162.  
  163. /* De-initialize the TTF engine */
  164. extern DECLSPEC void TTF_Quit(void);
  165.  
  166. /* We'll use SDL for reporting errors */
  167. #define TTF_SetError    SDL_SetError
  168. #define TTF_GetError    SDL_GetError
  169.  
  170. /* Ends C function definitions when using C++ */
  171. #ifdef __cplusplus
  172. };
  173. #endif
  174. #include "close_code.h"
  175.  
  176. #endif /* _SDLttf_h */
  177.