SDL_ttf.h

Go to the documentation of this file.
00001 /*
00002     SDL_ttf:  A companion library to SDL for working with TrueType (tm) fonts
00003     Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003  Sam Lantinga
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019     Sam Lantinga
00020     slouken@libsdl.org
00021 */
00022 
00023 /* $Id: SDL_ttf.h,v 1.2 2007/03/10 21:07:51 macbishop Exp $ */
00024 
00025 /* This library is a wrapper around the excellent FreeType 2.0 library,
00026    available at:
00027      http://www.freetype.org/
00028 */
00029 
00030 #ifndef _SDL_TTF_H
00031 #define _SDL_TTF_H
00032 
00033 #include "SDL.h"
00034 #include "begin_code.h"
00035 #include "config.h"
00036 
00037 /* Set up for C function definitions, even when using C++ */
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
00043 */
00044 #define SDL_TTF_MAJOR_VERSION 2
00045 #define SDL_TTF_MINOR_VERSION 0
00046 #define SDL_TTF_PATCHLEVEL    7
00047 
00048 /* This macro can be used to fill a version structure with the compile-time
00049  * version of the SDL_ttf library.
00050  */
00051 #define SDL_TTF_VERSION(X)                             \
00052 {                                            \
00053      (X)->major = SDL_TTF_MAJOR_VERSION;                    \
00054      (X)->minor = SDL_TTF_MINOR_VERSION;                    \
00055      (X)->patch = SDL_TTF_PATCHLEVEL;                  \
00056 }
00057 
00058 /* Backwards compatibility */
00059 #define TTF_MAJOR_VERSION     SDL_TTF_MAJOR_VERSION
00060 #define TTF_MINOR_VERSION     SDL_TTF_MINOR_VERSION
00061 #define TTF_PATCHLEVEL        SDL_TTF_PATCHLEVEL
00062 #define TTF_VERSION(X)        SDL_TTF_VERSION(X)
00063 
00064 /* This function gets the version of the dynamically linked SDL_ttf library.
00065    it should NOT be used to fill a version structure, instead you should
00066    use the SDL_TTF_VERSION() macro.
00067  */
00068 extern DECLSPEC const SDL_version * SDLCALL TTF_Linked_Version(void);
00069 
00070 /* ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) */
00071 #define UNICODE_BOM_NATIVE    0xFEFF
00072 #define UNICODE_BOM_SWAPPED   0xFFFE
00073 
00074 /* This function tells the library whether UNICODE text is generally
00075    byteswapped.  A UNICODE BOM character in a string will override
00076    this setting for the remainder of that string.
00077 */
00078 extern DECLSPEC void SDLCALL TTF_ByteSwappedUNICODE(int swapped);
00079 
00080 /* The internal structure containing font information */
00081 typedef struct _TTF_Font TTF_Font;
00082 
00083 /* Initialize the TTF engine - returns 0 if successful, -1 on error */
00084 extern DECLSPEC int SDLCALL TTF_Init(void);
00085 
00086 /* Open a font file and create a font of the specified point size.
00087  * Some .fon fonts will have several sizes embedded in the file, so the
00088  * point size becomes the index of choosing which size.  If the value
00089  * is too high, the last indexed size will be the default. */
00090 extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, int ptsize);
00091 extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index);
00092 extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize);
00093 extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index);
00094 
00095 /* Set and retrieve the font style
00096    This font style is implemented by modifying the font glyphs, and
00097    doesn't reflect any inherent properties of the truetype font file.
00098 */
00099 #define TTF_STYLE_NORMAL 0x00
00100 #define TTF_STYLE_BOLD        0x01
00101 #define TTF_STYLE_ITALIC 0x02
00102 #define TTF_STYLE_UNDERLINE   0x04
00103 extern DECLSPEC int SDLCALL TTF_GetFontStyle(TTF_Font *font);
00104 extern DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, int style);
00105 
00106 /* Get the total height of the font - usually equal to point size */
00107 extern DECLSPEC int SDLCALL TTF_FontHeight(TTF_Font *font);
00108 
00109 /* Get the offset from the baseline to the top of the font
00110    This is a positive value, relative to the baseline.
00111  */
00112 extern DECLSPEC int SDLCALL TTF_FontAscent(TTF_Font *font);
00113 
00114 /* Get the offset from the baseline to the bottom of the font
00115    This is a negative value, relative to the baseline.
00116  */
00117 extern DECLSPEC int SDLCALL TTF_FontDescent(TTF_Font *font);
00118 
00119 /* Get the recommended spacing between lines of text for this font */
00120 extern DECLSPEC int SDLCALL TTF_FontLineSkip(TTF_Font *font);
00121 
00122 /* Get the number of faces of the font */
00123 extern DECLSPEC long SDLCALL TTF_FontFaces(TTF_Font *font);
00124 
00125 /* Get the font face attributes, if any */
00126 extern DECLSPEC int SDLCALL TTF_FontFaceIsFixedWidth(TTF_Font *font);
00127 extern DECLSPEC char * SDLCALL TTF_FontFaceFamilyName(TTF_Font *font);
00128 extern DECLSPEC char * SDLCALL TTF_FontFaceStyleName(TTF_Font *font);
00129 
00130 /* Get the metrics (dimensions) of a glyph */
00131 extern DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
00132                          int *minx, int *maxx,
00133                                      int *miny, int *maxy, int *advance);
00134 
00135 /* Get the dimensions of a rendered string of text */
00136 extern DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h);
00137 extern DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
00138 extern DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h);
00139 
00140 /* Create an 8-bit palettized surface and render the given text at
00141    fast quality with the given font and color.  The 0 pixel is the
00142    colorkey, giving a transparent background, and the 1 pixel is set
00143    to the text color.
00144    This function returns the new surface, or NULL if there was an error.
00145 */
00146 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font,
00147                     const char *text, SDL_Color fg);
00148 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font,
00149                     const char *text, SDL_Color fg);
00150 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font,
00151                     const Uint16 *text, SDL_Color fg);
00152 
00153 /* Create an 8-bit palettized surface and render the given glyph at
00154    fast quality with the given font and color.  The 0 pixel is the
00155    colorkey, giving a transparent background, and the 1 pixel is set
00156    to the text color.  The glyph is rendered without any padding or
00157    centering in the X direction, and aligned normally in the Y direction.
00158    This function returns the new surface, or NULL if there was an error.
00159 */
00160 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font,
00161                          Uint16 ch, SDL_Color fg);
00162 
00163 /* Create an 8-bit palettized surface and render the given text at
00164    high quality with the given font and colors.  The 0 pixel is background,
00165    while other pixels have varying degrees of the foreground color.
00166    This function returns the new surface, or NULL if there was an error.
00167 */
00168 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font,
00169                     const char *text, SDL_Color fg, SDL_Color bg);
00170 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Shaded(TTF_Font *font,
00171                     const char *text, SDL_Color fg, SDL_Color bg);
00172 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Shaded(TTF_Font *font,
00173                     const Uint16 *text, SDL_Color fg, SDL_Color bg);
00174 
00175 /* Create an 8-bit palettized surface and render the given glyph at
00176    high quality with the given font and colors.  The 0 pixel is background,
00177    while other pixels have varying degrees of the foreground color.
00178    The glyph is rendered without any padding or centering in the X
00179    direction, and aligned normally in the Y direction.
00180    This function returns the new surface, or NULL if there was an error.
00181 */
00182 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font,
00183                     Uint16 ch, SDL_Color fg, SDL_Color bg);
00184 
00185 /* Create a 32-bit ARGB surface and render the given text at high quality,
00186    using alpha blending to dither the font with the given color.
00187    This function returns the new surface, or NULL if there was an error.
00188 */
00189 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font,
00190                     const char *text, SDL_Color fg);
00191 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended(TTF_Font *font,
00192                     const char *text, SDL_Color fg);
00193 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended(TTF_Font *font,
00194                     const Uint16 *text, SDL_Color fg);
00195 
00196 /* Create a 32-bit ARGB surface and render the given glyph at high quality,
00197    using alpha blending to dither the font with the given color.
00198    The glyph is rendered without any padding or centering in the X
00199    direction, and aligned normally in the Y direction.
00200    This function returns the new surface, or NULL if there was an error.
00201 */
00202 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font,
00203                               Uint16 ch, SDL_Color fg);
00204 
00205 /* For compatibility with previous versions, here are the old functions */
00206 #define TTF_RenderText(font, text, fg, bg)   \
00207      TTF_RenderText_Shaded(font, text, fg, bg)
00208 #define TTF_RenderUTF8(font, text, fg, bg)   \
00209      TTF_RenderUTF8_Shaded(font, text, fg, bg)
00210 #define TTF_RenderUNICODE(font, text, fg, bg)     \
00211      TTF_RenderUNICODE_Shaded(font, text, fg, bg)
00212 
00213 /* Close an opened font file */
00214 extern DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font);
00215 
00216 /* De-initialize the TTF engine */
00217 extern DECLSPEC void SDLCALL TTF_Quit(void);
00218 
00219 /* Check if the TTF engine is initialized */
00220 extern DECLSPEC int SDLCALL TTF_WasInit(void);
00221 
00222 /* We'll use SDL for reporting errors */
00223 #define TTF_SetError     SDL_SetError
00224 #define TTF_GetError     SDL_GetError
00225 
00226 /* Ends C function definitions when using C++ */
00227 #ifdef __cplusplus
00228 }
00229 #endif
00230 #include "close_code.h"
00231 
00232 #endif /* _SDL_TTF_H */

Generated on Sun Mar 11 15:33:23 2007 for MetalWarriors by  doxygen 1.4.7