This is an unofficial document for the SDL_ttf library API.

Copyright © 2003-2005 Jonathan Atkins

Permission is granted to distribute freely, or in a distribution of any kind. All distributions of this file must be in an unaltered state, except for corrections.

The latest copy of this document can be found at http://jcatki.no-ip.org/SDL_ttf

SDL_ttf 2.0.7
*************

Overview
********

A Little Bit About Me

I am currently, as I write this document, a programmer for Raytheon.  There I do all sorts of communications, network, GUI, and other general programming tasks in C/C++ on the Solaris and sometimes Linux Operating Systems.  I've used SDL_ttf as one of the many methods of putting text on my SDL applications, and use it in my own SDL GUI code as well.  While this document doesn't explain how and where to get fonts to use, it will explain how to use them with SDL_ttf.

Feel free to contact me: jcatki@jcatki.no-ip.org

The latest version of this library is available from:

SDL_ttf Homepage (http://www.libsdl.org/projects/SDL_ttf/)

I am also usually on IRC at irc.freenode.net in the #SDL channel as LIM

This is the README in the SDL_ttf source archive.

This library is a wrapper around the excellent FreeType 1.2 library, available at: Freetype Homepage (http://www.freetype.org/)

WARNING: There may be patent issues with using the FreeType library. Check the FreeType website for up-to-date details.

This library allows you to use TrueType fonts to render text in SDL applications.

To make the library, first install the FreeType library, then type 'make' to build the SDL truetype library and 'make all' to build the demo application.

Be careful when including fonts with your application, as many of them are copyrighted.  The Microsoft fonts, for example, are not freely redistributable and even the free "web" fonts they provide are only redistributable in their special executable installer form (May 1998). There are plenty of freeware and shareware fonts available on the Internet though, and may suit your purposes.

Please see the file "COPYING" for license information for this library.

Enjoy! -Sam Lantinga slouken@devolution.com       (5/1/98)

Getting Started
***************

This assumes you have gotten SDL_ttf and installed it on your system. SDL_ttf has an INSTALL document in the source distribution to help you get it compiled and installed.

Generally, installation consists of:

     ./configure
     make
     make install

SDL_ttf supports loading fonts from TrueType font files, normally ending in .ttf, though some .fon files are also valid for use.  Note that most fonts are copyrighted, check the license on the font before you use and redistribute.

Some free font sources are:

  * Free UCS Outline Fonts (http://www.nongnu.org/freefont/)

  * Fonthead Design (http://www.fonthead.com/freeware.html)

  * Bitstream Vera Fonts (http://www.gnome.org/fonts/)

  * FreeUniFont (http://sf.net/projects/freeunifont/)

  * 1001 Fonts (http://www.1001fonts.com/)

  * Google! (http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=truetype+free+redistribute&btnG=Google+Search)

You may also want to look at some demonstration code which may be downloaded from:

http://jcatki.no-ip.org/SDL_ttf/

Includes
========

To use SDL_ttf functions in a C/C++ source code file, you must use the SDL_ttf.h include file:

  #include "SDL_ttf.h"

Compiling
=========

To link with SDL_ttf you should use sdl-config to get the required SDL compilation options.  After that, compiling with SDL_ttf is quite easy.

Note: Some systems may not have the SDL_ttf library and include file in the same place as the SDL library and includes are located, in that case you will need to add more -I and -L paths to these command lines.

Simple Example for compiling an object file:

  cc -c `sdl-config --cflags` mysource.c

Simple Example for compiling an object file:

  cc -o myprogram mysource.o `sdl-config --libs` -lSDL_ttf

Now myprogram is ready to run.

Functions
*********

These are the functions in the SDL_ttf API.

General
=======

These functions are useful, as they are the only/best ways to work with SDL_ttf.

TTF_Linked_Version
------------------

const SDL_version *TTF_Linked_Version()

void TTF_VERSION(SDL_version *compile_version)

This works similar to SDL_Linked_Version and SDL_VERSION.

Using these you can compare the runtime version to the version that you compiled with.

     SDL_version compile_version, *link_version;
     TTF_VERSION(&compile_version);
     printf("compiled with SDL_ttf version: %d.%d.%d\n",
             compile_version.major,
             compile_version.minor,
             compile_version.patch);
     link_version=TTF_Linked_Version();
     printf("running with SDL_ttf version: %d.%d.%d\n",
             link_version->major,
             link_version->minor,
             link_version->patch);

See Also:

TTF_Init

TTF_Init
--------

int TTF_Init()

Initialize the truetype font API.

This must be called before using other functions in this library, excepting TTF_WasInit.

SDL does not have to be initialized before this call.

Returns: 0 on success, -1 on errors

     if(TTF_Init()==-1) {
         printf("TTF_Init: %s\n", TTF_GetError());
         exit(2);
     }

See Also:

TTF_Quit, TTF_WasInit

TTF_WasInit
-----------

int TTF_WasInit()

Query the initilization status of the truetype font API.

You may, of course, use this before TTF_Init to avoid initilizing twice in a row. Or use this to determine if you need to call TTF_Quit.

     if(!TTF_WasInit() && TTF_Init()==-1) {
         printf("TTF_Init: %s\n", TTF_GetError());
         exit(1);
     }

See Also:

TTF_Init, TTF_Quit

TTF_Quit
--------

void TTF_Quit()

Shutdown and cleanup the truetype font API.

After calling this the SDL_ttf functions should not be used, excepting TTF_WasInit. You may, of course, use TTF_Init to use the functionality again.

     TTF_Quit();
     // you could SDL_Quit(); here...or not.

See Also:

TTF_Init, TTF_WasInit

TTF_SetError
------------

void TTF_SetError(const char *FMT, ...)

This is the same as SDL_SetError, which sets the error string which may be fetched with TTF_GetError (or SDL_GetError). This functions acts like printf, except that it is limited to SDL_ERRBUFIZE(1024) chars in length.  It only accepts the following format types: %s, %d, %f, %p.  No variations are supported, like %.2f would not work. For any more specifics read the SDL docs.

     int myfunc(int i) {
         TTF_SetError("myfunc is not implemented! %d was passed in.",i);
         return(-1);
     }

See Also:

TTF_GetError

TTF_GetError
------------

char *TTF_GetError()

This is the same as SDL_GetError, which returns the last error set as a string which you may use to tell the user what happened when an error status has been returned from an SDL_ttf function call.

Returns: a char pointer (string) containing a human readable version or the reason for the last error that occured.

     printf("Oh My Goodness, an error : %s", TTF_GetError());

See Also:

TTF_SetError

Management
==========

These functions deal with loading and freeing a TTF_Font.

TTF_OpenFont
------------

TTF_Font *TTF_OpenFont(const char *FILE, int PTSIZE)

file
     File name to load font from.

ptsize
     Point size (based on 72DPI) to load font as. This basically translates to pixel height.

Load FILE for use as a font, at PTSIZE size.  This is actually TTF_OpenFontIndex(FILE, PTSIZE, 0).  This can load TTF and FON files.

Returns: a pointer to the font as a TTF_Font.  NULL is returned on errors.

     // load font.ttf at size 16 into font
     TTF_Font *font;
     font=TTF_OpenFont("font.ttf", 16);
     if(!font) {
         printf("TTF_OpenFont: %s\n", TTF_GetError());
         // handle error
     }

See Also:

TTF_OpenFontIndex, TTF_OpenFontRW, TTF_CloseFont

TTF_OpenFontRW
--------------

TTF_Font *TTF_OpenFontRW(SDL_RWops *SRC, int FREESRC, int PTSIZE)

src
     The source SDL_RWops as a pointer.  The font is loaded from this.

freesrc
     A non-zero value mean is will automatically close/free the SRC for you.

ptsize
     Point size (based on 72DPI) to load font as. This basically translates to pixel height.

Load SRC for use as a font, at PTSIZE size. This is actually TTF_OpenFontIndexRW(SRC, FREESRC, PTSIZE, 0) This can load TTF and FON formats. Using SDL_RWops is not covered here, but they enable you to load from almost any source.

NOTE: SRC is not checked for NULL, so be careful.

Returns: a pointer to the font as a TTF_Font.  NULL is returned on errors.

     // load font.ttf at size 16 into font
     TTF_Font *font;
     font=TTF_OpenFontRW(SDL_RWFromFile("font.ttf"), 1, 16);
     if(!font) {
         printf("TTF_OpenFontRW: %s\n", TTF_GetError());
         // handle error
     }

Note that this is unsafe because we don't check the validity of the SDL_RWFromFile's returned pointer.

See Also:

TTF_OpenFontIndexRW, TTF_OpenFont, TTF_CloseFont

TTF_OpenFontIndex
-----------------

TTF_Font *TTF_OpenFontIndex(const char *FILE, int PTSIZE, long INDEX)

file
     File name to load font from.

ptsize
     Point size (based on 72DPI) to load font as. This basically translates to pixel height.

index
     choose a font face from a multiple font face containing file. The first face is always index 0.

Load FILE, face INDEX, for use as a font, at PTSIZE size.  This is actually TTF_OpenFontIndexRW(SDL_RWFromFile(FILE), PTSIZE, INDEX), but checks that the RWops it creates is not NULL.  This can load TTF and FON files.

Returns: a pointer to the font as a TTF_Font.  NULL is returned on errors.

     // load font.ttf, face 0, at size 16 into font
     TTF_Font *font;
     font=TTF_OpenFontIndex("font.ttf", 16, 0);
     if(!font) {
         printf("TTF_OpenFontIndex: %s\n", TTF_GetError());
         // handle error
     }

See Also:

TTF_OpenFontIndexRW, TTF_OpenFont, TTF_CloseFont

TTF_OpenFontIndexRW
-------------------

TTF_Font *TTF_OpenFontIndexRW(SDL_RWops *SRC, int FREESRC, int PTSIZE, long INDEX)

src
     The source SDL_RWops as a pointer.  The font is loaded from this.

freesrc
     A non-zero value mean is will automatically close/free the SRC for you.

ptsize
     Point size (based on 72DPI) to load font as. This basically translates to pixel height.

index
     choose a font face from a multiple font face containing file. The first face is always index 0.

Load SRC, face INDEX, for use as a font, at PTSIZE size. This can load TTF and FON formats.

Using SDL_RWops is not covered here, but they enable you to load from almost any source.

NOTE: SRC is not checked for NULL, so be careful.

Returns: a pointer to the font as a TTF_Font.  NULL is returned on errors.

     // load font.ttf, face 0, at size 16 into font
     TTF_Font *font;
     font=TTF_OpenFontRW(SDL_RWFromFile("font.ttf"), 1, 16, 0);
     if(!font) {
         printf("TTF_OpenFontIndexRW: %s\n", TTF_GetError());
         // handle error
     }

Note that this is unsafe because we don't check the validity of the SDL_RWFromFile's returned pointer.

See Also:

TTF_OpenFontIndex, TTF_OpenFontRW, TTF_CloseFont

TTF_CloseFont
-------------

void TTF_CloseFont(TTF_Font *FONT)

font
     Pointer to the TTF_Font to free.

Free the memory used by FONT, and free FONT itself as well. Do not use FONT after this without loading a new font to it.

     // free the font
     // TTF_Font *font;
     TTF_CloseFont(font);
     font=NULL; // to be safe...

See Also:

TTF_OpenFont, TTF_OpenFontRW, TTF_OpenFontIndex, TTF_OpenFontIndexRW

Attributes
==========

These functions deal with TTF_Font, and global, attributes.

See the end of TTF_GlyphMetrics for info on how the metrics work.

TTF_ByteSwappedUNICODE
----------------------

void TTF_ByteSwappedUNICODE(int SWAPPED)

swapped
     if non-zero then UNICODE data is byte swapped relative to the CPU's native endianess.

     if zero, then do not swap UNICODE data, use the CPU's native endianess.

This function tells SDL_ttf whether UNICODE (Uint16 per character) text is generally byteswapped.  A UNICODE_BOM_NATIVE or UNICODE_BOM_SWAPPED character in a string will temporarily override this setting for the remainder of that string, however this setting will be restored for the next one. The default mode is non-swapped, native endianess of the CPU.

     // Turn on byte swapping for UNICODE text
     TTF_ByteSwappedUNICODE(1);

See Also:

Defines

TTF_GetFontStyle
----------------

int TTF_GetFontStyle(TTF_Font *FONT)

font
     The loaded font to get the style of

Get the rendering style of the loaded FONT.

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: The style as a bitmask composed of the following masks:

TTF_STYLE_BOLD

TTF_STYLE_ITALIC

TTF_STYLE_UNDERLINE

If no style is set then TTF_STYLE_NORMAL is returned.

     // get the loaded font's style
     //TTF_Font *font;
     int style;
     style=TTF_GetFontStyle(font);
     printf("The font style is:");
     if(style==TTF_STYLE_NORMAL)
         printf(" normal");
     else {
         if(style&TTF_STYLE_BOLD)
             printf(" bold");
         if(style&TTF_STYLE_ITALIC)
             printf(" italic");
         if(style&TTF_STYLE_UNDERLINE)
             printf(" underline");
     }
     printf("\n");

See Also:

TTF_SetFontStyle,

Defines

TTF_SetFontStyle
----------------

void TTF_SetFontStyle(TTF_Font *FONT, int STYLE)

font
     The loaded font to get the style of

style
     A bitmask of the desired style composed from the TTF_STYLE_* defined values

Set the rendering style of the loaded FONT.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: This will flush the internal cache of previously rendered glyphs, even if there is no change in style, so it may be best to check the current style using TTF_GetFontStyle first.

NOTE: I've seen that combining TTF_STYLE_UNDERLINE with anything can cause a segfault, other combinations may also do this.  Some brave soul may find the cause of this and fix it...

     // set the loaded font's style to bold italics
     //TTF_Font *font;
     TTF_SetFontStyle(font, TTF_STYLE_BOLD|TTF_STYLE_ITALIC);

     // render some text in bold italics...

     // set the loaded font's style back to normal
     TTF_SetFontStyle(font, TTF_STYLE_NORMAL);

See Also:

TTF_GetFontStyle,

Defines

TTF_FontHeight
--------------

int TTF_FontHeight(TTF_Font *FONT)

font
     The loaded font to get the max height of

Get the maximum pixel height of all glyphs of the loaded FONT. You may use this height for rendering text as close together vertically as possible, though adding at least one pixel height to it will space it so they can't touch. Remember that SDL_ttf doesn't handle multiline printing, so you are responsible for line spacing, see the TTF_FontLineSkip as well.

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: The maximum pixel height of all glyphs in the font.

     // get the loaded font's max height
     //TTF_Font *font;
     printf("The font max height is: %d\n", TTF_FontHeight(font));

See Also:

TTF_FontAscent,

TTF_FontDescent,

TTF_FontLineSkip,

TTF_GlyphMetrics

TTF_FontAscent
--------------

int TTF_FontAscent(TTF_Font *FONT)

font
     The loaded font to get the ascent (height above baseline) of

Get the maximum pixel ascent of all glyphs of the loaded FONT. This can also be interpreted as the distance from the top of the font to the baseline.

It could be used when drawing an individual glyph relative to a top point, by combining it with the glyph's maxy metric to resolve the top of the rectangle used when blitting the glyph on the screen.

rect.y = top + TTF_FontAscent(font) - glyph_metric.maxy;

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: The maximum pixel ascent of all glyphs in the font.

     // get the loaded font's max ascent
     //TTF_Font *font;

     printf("The font ascent is: %d\n", TTF_FontAscent(font));

See Also:

TTF_FontHeight,

TTF_FontDescent,

TTF_FontLineSkip,

TTF_GlyphMetrics

TTF_FontDescent
---------------

int TTF_FontDescent(TTF_Font *FONT)

font
     The loaded font to get the descent (height below baseline) of

Get the maximum pixel descent of all glyphs of the loaded FONT. This can also be interpreted as the distance from the baseline to the bottom of the font.

It could be used when drawing an individual glyph relative to a bottom point, by combining it with the glyph's maxy metric to resolve the top of the rectangle used when blitting the glyph on the screen.

rect.y = bottom - TTF_FontDescent(font) - glyph_metric.maxy;

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: The maximum pixel height of all glyphs in the font.

     // get the loaded font's max descent
     //TTF_Font *font;

     printf("The font descent is: %d\n", TTF_FontDescent(font));

See Also:

TTF_FontHeight,

TTF_FontAscent,

TTF_FontLineSkip,

TTF_GlyphMetrics

TTF_FontLineSkip
----------------

int TTF_FontLineSkip(TTF_Font *FONT)

font
     The loaded font to get the line skip height of

Get the reccomended pixel height of a rendered line of text of the loaded FONT. This is usually larger than the TTF_FontHeight of the FONT.

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: The maximum pixel height of all glyphs in the font.

     // get the loaded font's max descent
     //TTF_Font *font;

     printf("The font descent is: %d\n", TTF_FontDescent(font));

See Also:

TTF_FontHeight,

TTF_FontAscent,

TTF_FontDescent,

TTF_GlyphMetrics

TTF_FontFaces
-------------

long TTF_FontFaces(TTF_Font *FONT)

font
     The loaded font to get the number of available faces from.

Get the number of faces ("sub-fonts") available in the loaded FONT. This is a count of the number of specific fonts (based on size and style and ???) contained in the font itself.  It seems to be a useless fact to know, since it can't be applied in any other SDL_ttf functions. NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: The number of faces in the FONT.

     // get the loaded font's number of faces
     //TTF_Font *font;

     printf("The number of faces in the font is: %ld\n", TTF_FontFaces(font));

See Also:

TTF_FontFaceIsFixedWidth,

TTF_FontFaceFamilyName,

TTF_FontFaceStyleName

TTF_FontFaceIsFixedWidth
------------------------

int TTF_FontFaceIsFixedWidth(TTF_Font *FONT)

font
     The loaded font to get the fixed width status of.

Test if the current font face of the loaded FONT is a fixed width font. Fixed width fonts are monospace, meaning every character that exists in the font is the same width, thus you can assume that a rendered string's width is going to be the result of a simple calculation: glyph_width * string_length

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: >0 if FONT is a fixed width font.  0 if not a fixed width font.

     // get the loaded font's face fixed status
     //TTF_Font *font;

     if(TTF_FontFaceIsFixedWidth(font))
         printf("The font is fixed width.\n");
     else
         printf("The font is not fixed width.\n");

See Also:

TTF_FontFaces,

TTF_FontFaceFamilyName,

TTF_FontFaceStyleName,

TTF_GlyphMetrics

TTF_FontFaceFamilyName
----------------------

char * TTF_FontFaceFamilyName(TTF_Font *FONT)

font
     The loaded font to get the current face family name of.

Get the current font face family name from the loaded FONT. This function may return a NULL pointer, in which case the information is not available. NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: The current family name of of the face of the FONT, or NULL perhaps.

     // get the loaded font's face name
     //TTF_Font *font;

     char *familyname=TTF_FontFaceFamilyName(font);
     if(familyname)
         printf("The family name of the face in the font is: %s\n", familyname);

See Also:

TTF_FontFaces,

TTF_FontFaceIsFixedWidth,

TTF_FontFaceStyleName

TTF_FontFaceStyleName
---------------------

char * TTF_FontFaceStyleName(TTF_Font *FONT)

font
     The loaded font to get the current face style name of.

Get the current font face style name from the loaded FONT. This function may return a NULL pointer, in which case the information is not available. NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: The current style name of of the face of the FONT, or NULL perhaps.

     // get the loaded font's face style name
     //TTF_Font *font;

     char *stylename=TTF_FontFaceStyleName(font);
     if(stylename)
         printf("The name of the face in the font is: %s\n", stylename);

See Also:

TTF_FontFaces,

TTF_FontFaceIsFixedWidth,

TTF_FontFaceFamilyName

TTF_GlyphMetrics
----------------

int TTF_GlyphMetrics(TTF_Font *FONT, Uint16 CH, int *MINX, int *MAXX, int *MINY, int *MAXY, int *ADVANCE)

font
     The loaded font from which to get the glyph metrics of CH from

ch
     the UNICODE char of which to get the glyph metrics for

minx
     poiter to int to store the retuned minimum X offset into, or NULL when no return value desired.

maxx
     poiter to int to store the retuned maximum X offset into, or NULL when no return value desired.

miny
     poiter to int to store the retuned minimum Y offset into, or NULL when no return value desired.

maxy
     poiter to int to store the retuned maximum Y offset into, or NULL when no return value desired.

advance
     poiter to int to store the retuned advance offset into, or NULL when no return value desired.

Get desired glyph metrics of the UNICODE chargiven in CH from the loaded FONT. NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: 0 on success, with all non-NULL parameters set to the glyph metric as appropriate. -1 on errors, such as when the glyph named by CH does not exist in the font.

     // get the glyph metric for the letter 'g' in a loaded font
     //TTF_Font *font;
     int minx,maxx,miny,maxy,advance;
     if(TTF_GlyphMetrics(font,'g',&minx,&maxx,&miny,&maxy,&advance)==-1)
         printf("%s\n",TTF_GetError());
     else {
         printf("minx    : %d\n",minx);
         printf("maxx    : %d\n",maxx);
         printf("miny    : %d\n",miny);
         printf("maxy    : %d\n",maxy);
         printf("advance : %d\n",advance);
     }

This digram shows the relationships between the values:

Glyph Metrics Diagram

Here's how the numbers look:

     TTF_FontHeight       : 33
     TTF_FontAscent       : 26
     TTF_FontDescent      : -6
     TTF_FontLineSkip     : 33
     TTF_GlyphMetrics('g'):
             minx=0
             maxx=21
             miny=0
             maxy=21
             advance=24

We see from the Line Skip that each line of text is 33 pixels high, including spacing.

The Ascent-Descent=32, so there seems to be one pixel worth of space minimum between lines.

Let's say we want to draw the surface of glyph 'g' (retrived via TTF_RenderGlyph_Solid or a similar function), at coordinates (X,Y) for the top left corner of the desired location. Here's the math using glyph metrics:

     //SDL_Surface *glyph,*screen;
     SDL_Rect rect;
     int minx,miny,advance;
     TTF_GlyphMetrics(font,'g',&minx,NULL,&miny,NULL,&advance);
     rect.x=X+minx;
     rect.y=Y+miny;
     SDL_BlitSurface(glyph,NULL,screen,&rect);
     X+=advance;

Let's say we want to draw the same glyph at coordinates (X,Y) for the origin (on the baseline) of the desired location. Here's the math using glyph metrics:

     //TTF_Font *font;
     //SDL_Surface *glyph,*screen;
     SDL_Rect rect;
     int minx,miny,advance;
     TTF_GlyphMetrics(font,'g',&minx,NULL,&miny,NULL,&advance);
     rect.x=X+minx;
     rect.y=Y-TTF_FontAscent(font)+miny;
     SDL_BlitSurface(glyph,NULL,screen,&rect);
     X+=advance;

NOTE: These examples assume that 'g' is present in the font!

See the web page at The FreeType2 Documentation Tutorial (http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html) for more.

Any glyph based rendering calculations will not result in accurate kerning between adjacent glyphs. (see Kerning)

See Also:

TTF_FontHeight,

TTF_FontAscent,

TTF_FontDescent,

TTF_FontLineSkip,

TTF_SizeText,

TTF_SizeUTF8,

TTF_SizeUNICODE,

TTF_SizeText
------------

int TTF_SizeText(TTF_Font *FONT, const char *TEXT, int *W, int *H)

font
     The loaded font to use to calculate the size of the string with.

text
     The LATIN1 null terminated string to size up.

w
     pointer to int in which to fill the text width, or NULL for no desired return value.

h
     pointer to int in which to fill the text height, or NULL for no desired return value.

Calculate the resulting surface size of the LATIN1 encoded TEXT rendered using FONT.  No actual rendering it done, however correct kerning is done to getthe actual width.  The height returned in W is the same as you can get using TTF_FontHeight. NOTE: Passing a NULL FONT into this function will cause a segfault. NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: 0 on success with the ints pointed to by W and H set as appropriate, if they are not NULL.  -1 is returned on errors, such as a glyph in the string not being found.

     // get the width and height of a string as it would be rendered in a loaded font
     //TTF_Font *font;
     int w,h;
     if(TTF_SizeText(font,"Hello World!",&w,&h)) {
         // perhaps print the current TTF_GetError(), the string can't be rendered...
     } else {
         printf("width=%d height=%d\n",w,h);
     }

See Also:

TTF_SizeUTF8,

TTF_SizeUNICODE,

TTF_RenderText_Solid,

TTF_RenderText_Shaded,

TTF_RenderText_Blended

TTF_SizeUTF8
------------

int TTF_SizeUTF8(TTF_Font *FONT, const char *TEXT, int *W, int *H)

font
     The loaded font to use to calculate the size of the string with.

text
     The UTF8 null terminated string to size up.

w
     pointer to int in which to fill the text width, or NULL for no desired return value.

h
     pointer to int in which to fill the text height, or NULL for no desired return value.

Calculate the resulting surface size of the UTF8 encoded TEXT rendered using FONT.  No actual rendering it done, however correct kerning is done to getthe actual width.  The height returned in W is the same as you can get using TTF_FontHeight. NOTE: Passing a NULL FONT into this function will cause a segfault. NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: 0 on success with the ints pointed to by W and H set as appropriate, if they are not NULL.  -1 is returned on errors, such as a glyph in the string not being found.

Note that this example uses the same text as in the LATIN1 example, that is because plain ASCII is UTF8 compatible.

     // get the width and height of a string as it would be rendered in a loaded font
     //TTF_Font *font;
     int w,h;
     if(TTF_SizeUTF8(font,"Hello World!",&w,&h)) {
         // perhaps print the current TTF_GetError(), the string can't be rendered...
     } else {
         printf("width=%d height=%d\n",w,h);
     }

See Also:

TTF_SizeText,

TTF_SizeUNICODE,

TTF_RenderUTF8_Solid,

TTF_RenderUTF8_Shaded,

TTF_RenderUTF8_Blended

TTF_SizeUNICODE
---------------

int TTF_SizeUNICODE(TTF_Font *FONT, const Unit16 *TEXT, int *W, int *H)

font
     The loaded font to use to calculate the size of the string with.

text
     The UNICODE null terminated string to size up.

w
     pointer to int in which to fill the text width, or NULL for no desired return value.

h
     pointer to int in which to fill the text height, or NULL for no desired return value.

Calculate the resulting surface size of the UNICODE encoded TEXT rendered using FONT.  No actual rendering it done, however correct kerning is done to getthe actual width.  The height returned in W is the same as you can get using TTF_FontHeight. NOTE: Passing a NULL FONT into this function will cause a segfault. NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: 0 on success with the ints pointed to by W and H set as appropriate, if they are not NULL.  -1 is returned on errors, such as a glyph in the string not being found.

     // get the width and height of a string as it would be rendered in a loaded font
     //TTF_Font *font;
     int w,h;
     Uint16 text[]={'H','e','l','l','o',' ',
                    'W','o','r','l','d','!'};
     if(TTF_SizeUNICODE(font,text,&w,&h)) {
         // perhaps print the current TTF_GetError(), the string can't be rendered...
     } else {
         printf("width=%d height=%d\n",w,h);
     }

See Also:

TTF_SizeText,

TTF_SizeUTF8,

TTF_RenderUNICODE_Solid,

TTF_RenderUNICODE_Shaded,

TTF_RenderUNICODE_Blended

Render
======

These functions render text using a TTF_Font.

There are three modes of rendering:

Solid
     Quick and Dirty

     Create an 8-bit palettized surface and render the given text at fast quality with the given font and color.  The 0 pixel value is the colorkey, giving a transparent background, and the 1 pixel value is set to the text color. The colormap is set to have the desired foreground color at index 1, this allows you to change the color without having to render the text again. Colormap index 0 is of course not drawn, since it is the colorkey, and thus transparent, though it's actual color is 255 minus each RGB component of the foreground. This is the fastest rendering speed of all the rendering modes. This results in no box around the text, but the text is not as smooth. The resulting surface should blit faster than the Blended one. Use this mode for FPS and other fast changing updating text displays.

Shaded
     Slow and Nice, but with a Solid Box

     Create an 8-bit palettized surface and render the given text at high quality with the given font and colors.  The 0 pixel value is background, while other pixels have varying degrees of the foreground color from the background color. This results in a box of the background color around the text in the foreground color. The text is antialiased. This will render slower than Solid, but in about the same time as Blended mode. The resulting surface should blit as fast as Solid, once it is made. Use this when you need nice text, and can live with a box...

Blended
     Slow Slow Slow, but Ultra Nice over another image

     Create a 32-bit ARGB surface and render the given text at high quality, using alpha blending to dither the font with the given color. This results in a surface with alpha transparency, so you don't have a solid colored box around the text. The text is antialiased. This will render slower than Solid, but in about the same time as Shaded mode. The resulting surface will blit slower than if you had used Solid or Shaded. Use this when you want high quality, and the text isn't changing too fast.

TTF_RenderText_Solid
--------------------

SDL_Surface *TTF_RenderText_Solid(TTF_Font *FONT, const char *TEXT, SDL_Color FG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The LATIN1 null terminated string to render.

fg
     The color to render the text in.  This becomes colormap index 1.

Render the LATIN1 encoded TEXT using FONT with FG color onto a new surface, using the Solid mode (see Solid).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

     // Render some text in solid black to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0};
     SDL_Surface *text_surface;
     if(!(text_surface=TTF_RenderText_Solid(font,"Hello World!",color))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeText,

TTF_RenderUTF8_Solid,

TTF_RenderUNICODE_Solid,

TTF_RenderGlyph_Solid,

TTF_RenderText_Shaded,

TTF_RenderText_Blended

TTF_RenderUTF8_Solid
--------------------

SDL_Surface *TTF_RenderUTF8_Solid(TTF_Font *FONT, const char *TEXT, SDL_Color FG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The UTF8 null terminated string to render.

fg
     The color to render the text in.  This becomes colormap index 1.

Render the UTF8 encoded TEXT using FONT with FG color onto a new surface, using the Solid mode (see Solid).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

Note that this example uses the same text as in the LATIN1 example, that is because plain ASCII is UTF8 compatible.

     // Render some UTF8 text in solid black to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0};
     SDL_Surface *text_surface;
     if(!(text_surface=TTF_RenderUTF8_Solid(font,"Hello World!",color))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeUTF8,

TTF_RenderText_Solid,

TTF_RenderUNICODE_Solid,

TTF_RenderGlyph_Solid,

TTF_RenderUTF8_Shaded,

TTF_RenderUTF8_Blended

TTF_RenderUNICODE_Solid
-----------------------

SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *FONT, const Uint16 *TEXT, SDL_Color FG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The UNICODE null terminated string to render.

fg
     The color to render the text in.  This becomes colormap index 1.

Render the UNICODE encoded TEXT using FONT with FG color onto a new surface, using the Solid mode (see Solid).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

     // Render some UNICODE text in solid black to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0};
     SDL_Surface *text_surface;
     Uint16 text[]={'H','e','l','l','o',' ',
                    'W','o','r','l','d','!'};
     if(!(text_surface=TTF_RenderUNICODE_Solid(font,text,color))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeUNICODE,

TTF_RenderText_Solid,

TTF_RenderUTF8_Solid,

TTF_RenderGlyph_Solid,

TTF_RenderUNICODE_Shaded,

TTF_RenderUNICODE_Blended

TTF_RenderGlyph_Solid
---------------------

SDL_Surface *TTF_RenderGlyph_Solid(TTF_Font *FONT, Uint16 CH, SDL_Color FG)

font
     Font to render the glyph with.  A NULL pointer is not checked.

text
     The UNICODE character to render.

fg
     The color to render the glyph in.  This becomes colormap index 1.

Render the glyph for the UNICODE CH using FONT with FG color onto a new surface, using the Solid mode (see Solid).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors, such as when the glyph not available in the font.

     // Render and cache all printable ASCII characters in solid black
     //SDL_Surface *screen;
     SDL_Color color={0,0,0};
     SDL_Surface *glyph_cache[128-20];
     Uint16 ch;
     for(ch=20; ch<128; ++ch)
         glyph_cache[ch-20]=TTF_RenderGlyph_Solid(font,ch,color);

Combined with a cache of the glyph metrics (minx, miny, and advance), you might make a fast text rendering routine that prints directly to the screen, but with inaccurate kerning. (see Kerning)

See Also:

TTF_RenderGlyph_Shaded,

TTF_RenderGlyph_Blended,

TTF_RenderText_Solid,

TTF_RenderUTF8_Solid,

TTF_RenderGlyph_Solid,

TTF_GlyphMetrics

TTF_RenderText_Shaded
---------------------

SDL_Surface *TTF_RenderText_Shaded(TTF_Font *FONT, const char *TEXT, SDL_Color FG, SDL_Color BG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The LATIN1 null terminated string to render.

fg
     The color to render the text in.  This becomes colormap index 1.

bg
     The color to render the background box in.  This becomes colormap index 0.

Render the LATIN1 encoded TEXT using FONT with FG color onto a new surface filled with the BG color, using the Shaded mode (see Shaded).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

     // Render some text in shaded black on white to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0}, bgcolor={0xff,0xff,0xff};
     SDL_Surface *text_surface;
     if(!(text_surface=TTF_RenderText_Shaded(font,"Hello World!",color,bgcolor))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeText,

TTF_RenderUTF8_Shaded,

TTF_RenderUNICODE_Shaded,

TTF_RenderGlyph_Shaded,

TTF_RenderText_Solid,

TTF_RenderText_Blended

TTF_RenderUTF8_Shaded
---------------------

SDL_Surface *TTF_RenderUTF8_Shaded(TTF_Font *FONT, const char *TEXT, SDL_Color FG, SDL_Color BG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The UTF8 null terminated string to render.

fg
     The color to render the text in.  This becomes colormap index 1.

bg
     The color to render the background box in.  This becomes colormap index 0.

Render the UTF8 encoded TEXT using FONT with FG color onto a new surface filled with the BG color, using the Shaded mode (see Shaded).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

Note that this example uses the same text as in the LATIN1 example, that is because plain ASCII is UTF8 compatible.

     // Render some UTF8 text in shaded black on white to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0}, bgcolor={0xff,0xff,0xff};
     SDL_Surface *text_surface;
     if(!(text_surface=TTF_RenderUTF8_Shaded(font,"Hello World!",color,bgcolor))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeUTF8,

TTF_RenderText_Shaded,

TTF_RenderUNICODE_Shaded,

TTF_RenderGlyph_Shaded,

TTF_RenderUTF8_Solid,

TTF_RenderUTF8_Blended

TTF_RenderUNICODE_Shaded
------------------------

SDL_Surface *TTF_RenderUNICODE_Shaded(TTF_Font *FONT, const Uint16 *TEXT, SDL_Color FG, SDL_Color BG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The UNICODE null terminated string to render.

fg
     The color to render the text in.  This becomes colormap index 1.

bg
     The color to render the background box in.  This becomes colormap index 0.

Render the UNICODE encoded TEXT using FONT with FG color onto a new surface filled with the BG color, using the Shaded mode (see Shaded).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

     // Render some UNICODE text in shaded black on white to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0}, bgcolor={0xff,0xff,0xff};
     SDL_Surface *text_surface;
     Uint16 text[]={'H','e','l','l','o',' ',
                    'W','o','r','l','d','!'};
     if(!(text_surface=TTF_RenderUNICODE_Shaded(font,text,color,bgcolor))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeUNICODE,

TTF_RenderText_Shaded,

TTF_RenderUTF8_Shaded,

TTF_RenderGlyph_Shaded,

TTF_RenderUNICODE_Solid,

TTF_RenderUNICODE_Blended

TTF_RenderGlyph_Shaded
----------------------

SDL_Surface *TTF_RenderGlyph_Shaded(TTF_Font *FONT, Uint16 CH, SDL_Color FG, SDL_Color BG)

font
     Font to render the glyph with.  A NULL pointer is not checked.

text
     The UNICODE character to render.

fg
     The color to render the glyph in.  This becomes colormap index 1.

bg
     The color to render the background box in.  This becomes colormap index 0.

Render the glyph for the UNICODE CH using FONT with FG color onto a new surface filled with the BG color, using the Shaded mode (see Shaded).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors, such as when the glyph not available in the font.

     // Render and cache all printable ASCII characters in shaded black on white
     //SDL_Surface *screen;
     SDL_Color color={0,0,0}, bgcolor={0xff,0xff,0xff};
     SDL_Surface *glyph_cache[128-20];
     Uint16 ch;
     for(ch=20; ch<128; ++ch)
         glyph_cache[ch-20]=TTF_RenderGlyph_Shaded(font,ch,color,bgcolor);

Combined with a cache of the glyph metrics (minx, miny, and advance), you might make a fast text rendering routine that prints directly to the screen, but with inaccurate kerning. (see Kerning)

See Also:

TTF_RenderGlyph_Solid,

TTF_RenderGlyph_Blended,

TTF_RenderText_Shaded,

TTF_RenderUTF8_Shaded,

TTF_RenderGlyph_Shaded,

TTF_GlyphMetrics

TTF_RenderText_Blended
----------------------

SDL_Surface *TTF_RenderText_Blended(TTF_Font *FONT, const char *TEXT, SDL_Color FG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The LATIN1 null terminated string to render.

fg
     The color to render the text in.  Pixels are blended between transparent and this color to draw the sntialiased glyphs.

Render the LATIN1 encoded TEXT using FONT with FG color onto a new surface, using the Blended mode (see Blended).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

     // Render some text in blended black to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0};
     SDL_Surface *text_surface;
     if(!(text_surface=TTF_RenderText_Blended(font,"Hello World!",color))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeText,

TTF_RenderUTF8_Blended,

TTF_RenderUNICODE_Blended,

TTF_RenderGlyph_Blended,

TTF_RenderText_Solid,

TTF_RenderText_Shaded

TTF_RenderUTF8_Blended
----------------------

SDL_Surface *TTF_RenderUTF8_Blended(TTF_Font *FONT, const char *TEXT, SDL_Color FG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The UTF8 null terminated string to render.

fg
     The color to render the text in.  Pixels are blended between transparent and this color to draw the sntialiased glyphs.

Render the UTF8 encoded TEXT using FONT with FG color onto a new surface, using the Blended mode (see Blended).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

Note that this example uses the same text as in the LATIN1 example, that is because plain ASCII is UTF8 compatible.

     // Render some UTF8 text in blended black to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0};
     SDL_Surface *text_surface;
     if(!(text_surface=TTF_RenderUTF8_Blended(font,"Hello World!",color))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeUTF8,

TTF_RenderText_Blended,

TTF_RenderUNICODE_Blended,

TTF_RenderGlyph_Blended,

TTF_RenderUTF8_Solid,

TTF_RenderUTF8_Shaded

TTF_RenderUNICODE_Blended
-------------------------

SDL_Surface *TTF_RenderUNICODE_Blended(TTF_Font *FONT, const Uint16 *TEXT, SDL_Color FG)

font
     Font to render the text with.  A NULL pointer is not checked.

text
     The UNICODE null terminated string to render.

fg
     The color to render the text in.  Pixels are blended between transparent and this color to draw the sntialiased glyphs.

Render the UNICODE encoded TEXT using FONT with FG color onto a new surface, using the Blended mode (see Blended).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

NOTE: Passing a NULL TEXT into this function will result in undefined behavior.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors.

     // Render some UNICODE text in blended black to a new surface
     // then blit to the upper left of the screen
     // then free the text surface
     //SDL_Surface *screen;
     SDL_Color color={0,0,0};
     SDL_Surface *text_surface;
     Uint16 text[]={'H','e','l','l','o',' ',
                    'W','o','r','l','d','!'};
     if(!(text_surface=TTF_RenderUNICODE_Blended(font,text,color))) {
         //handle error here, perhaps print TTF_GetError at least
     } else {
         SDL_BlitSurface(text_surface,NULL,screen,NULL);
         //perhaps we can reuse it, but I assume not for simplicity.
         SDL_FreeSurface(text_surface);
     }

See Also:

TTF_SizeUNICODE,

TTF_RenderText_Blended,

TTF_RenderUTF8_Blended,

TTF_RenderGlyph_Blended,

TTF_RenderUNICODE_Solid,

TTF_RenderUNICODE_Shaded

TTF_RenderGlyph_Blended
-----------------------

SDL_Surface *TTF_RenderGlyph_Blended(TTF_Font *FONT, Uint16 CH, SDL_Color FG)

font
     Font to render the glyph with.  A NULL pointer is not checked.

text
     The UNICODE character to render.

fg
     The color to render the glyph in.  Pixels are blended between transparent and this color to draw the sntialiased glyph.

Render the glyph for the UNICODE CH using FONT with FG color onto a new surface, using the Blended mode (see Blended).  The caller (you!) is responsible for freeing any returned surface.

NOTE: Passing a NULL FONT into this function will cause a segfault.

Returns: a pointer to a new SDL_Surface. NULL is returned on errors, such as when the glyph not available in the font.

     // Render and cache all printable ASCII characters in blended black
     //SDL_Surface *screen;
     SDL_Color color={0,0,0};
     SDL_Surface *glyph_cache[128-20];
     Uint16 ch;
     for(ch=20; ch<128; ++ch)
         glyph_cache[ch-20]=TTF_RenderGlyph_Blended(font,ch,color);

Combined with a cache of the glyph metrics (minx, miny, and advance), you might make a fast text rendering routine that prints directly to the screen, but with inaccurate kerning. (see Kerning)

See Also:

TTF_RenderGlyph_Solid,

TTF_RenderGlyph_Shaded,

TTF_RenderText_Blended,

TTF_RenderUTF8_Blended,

TTF_RenderGlyph_Blended,

TTF_GlyphMetrics

Types
*****

These types are defined and used by the SDL_ttf API.

TTF_Font
========

     typedef struct _TTF_Font TTF_Font;

The opaque holder of a loaded font.  You should always be using a pointer of this type, as in TTF_Font*, and not just plain TTF_Font. This stores the font data in a struct that is exposed only by using the API functions to get information.  You should not try to access the struct data directly, since the struct may change in different versions of the API, and thus your program would be unreliable.

See Also:

Management

Defines
*******

TTF_MAJOR_VERSION
     2

     SDL_ttf library major number at compilation time

TTF_MINOR_VERSION
     0

     SDL_ttf library minor number at compilation time

TTF_PATCHLEVEL
     7

     SDL_ttf library patch level at compilation time

UNICODE_BOM_NATIVE
     0xFEFF

     This allows you to switch byte-order of UNICODE text data to native order, meaning the mode of your CPU.  This is meant to be used in a UNICODE string that you are using with the SDL_ttf API.

UNICODE_BOM_SWAPPED
     0xFFFE

     This allows you to switch byte-order of UNICODE text data to swapped order, meaning the reversed mode of your CPU.  So if your CPU is LSB, then the data will be interpretted as MSB.  This is meant to be used in a UNICODE string that you are using with the SDL_ttf API.

TTF_STYLE_NORMAL
     0x00

     Used to indicate regular, normal, plain rendering style.

TTF_STYLE_BOLD
     0x01

     Used to indicate bold rendering style.  This is used a bitmask along with other styles.

TTF_STYLE_ITALIC
     0x02

     Used to indicate italicized rendering style.  This is used a bitmask along with other styles.

TTF_STYLE_UNDERLINE
     0x04

     Used to indicate underlined rendering style.  This is used a bitmask along with other styles.

See Also:

Glossary,

Glossary
********

Byte Order This all has to do with how data larger than a byte is actually stored in memory.  The CPU expects 16bit and 32bit, and larger, data to be ordered in one of the two ways listed below.  SDL has macros which you can use to detemine which endian your program will be using.

Big-Endian(MSB) means the most significant byte comes first in storage.  Sparc and Motorola 68k based chips are MSB ordered.

(SDL defines this as SDL_BYTEORDER==SDL_BIG_ENDIAN)

Little-Endian(LSB) is stored in the opposite order, with the least significant byte first in memory.  Intel and AMD are two LSB machines.

(SDL defines this as SDL_BYTEORDER==SDL_LIL_ENDIAN)

LATIN1 Latin-1 is an extension of ASCII, where ASCII only defines characters 0 through 127. Latin-1 continues and adds more common international symbols to define through character 255.

ISO 8859-1 (Latin-1) Unicode Table (pdf) (http://www.unicode.org/charts/PDF/U0080.pdf)

Latin-1 Characters

Kerning Kerning is the process of spacing adjacent characters apart depending on the actual two adjacent characters.  This allows some characters to be closer to each other than others.  When kerning is not used, such as when using the glyph metrics advance value, the characters will be spaced out at a constant size that accomodates all pairs of adjacent characters.  This would be the maximum space between characters needed.  There's currently no method to retrieve the kerning for a pair of characters from SDL_ttf, However correct kerning will be applied when a string of text is rendered instead of individual glyphs.