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