[Top] | [Contents] | [Index] | [ ? ] |
1. Overview The README from the SDL_ttf distribution
2. Getting Started Using SDL_ttf
3. Functions Functions supported by the SDL_ttf API 4. Types Types used with the SDL_ttf API 5. Defines Defined values/macros in the SDL_ttf API
6. Glossary Terms used in this document
Index Index of selected words
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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: JonathanCAtkins@gmail.com
The latest version of this library is available from:
SDL_ttf Homepage
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
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, which may suit your purposes. Please see the file "COPYING" for license information for this library. Enjoy! -Sam Lantinga slouken@devolution.com (5/1/98) |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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:
|
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 it.
Some free font sources are:
You may also want to look at some demonstration code which may be downloaded from:
http://www.jonatkins.org/SDL_ttf/
2.1 Includes The include files to use for SDL_ttf 2.2 Compiling Using the SDL_ttf library and header file.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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"
|
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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. All examples are gcc and perhaps UNIX specific, but adaptable to many compilers and Operating Systems.
Simple Example for compiling to an object file:
Simple Example for linking an executable (Unix style has no .exe):
|
Now myprogram
is ready to run.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These are the functions in the SDL_ttf API.
3.1 General API activation, info, and error handling 3.2 Management Loading fonts from files or memory 3.3 Attributes Getting and Setting font attributes 3.4 Render Drawing strings and glyphs with a font
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions are core elements in SDL_ttf.
Info
Activation
3.1.1 TTF_Linked_Version Get runtime version number
Errors
3.1.2 TTF_Init Initialize API 3.1.3 TTF_WasInit Query API initialization status 3.1.4 TTF_Quit Cleanup API
3.1.5 TTF_SetError Set the current error string 3.1.6 TTF_GetError Get the current error string
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
const SDL_version *TTF_Linked_Version()
void SDL_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.
No prior initialization needs to be done before these function/macros are used.
|
See Also:
3.1.2 TTF_Init
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_Init()
Initialize the truetype font API.
This must be called before using other functions in this library, except TTF_WasInit
.
SDL does not have to be initialized before this call.
Returns: 0 on success, -1 on any error
|
See Also:
3.1.4 TTF_Quit,
3.1.3 TTF_WasInit
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_WasInit()
Query the initilization status of the truetype font API.
You may, of course, use this before TTF_Init
to avoid initializing twice in a row.
Or use this to determine if you need to call TTF_Quit
.
Returns: 1 if already initialized, 0 if not initialized.
|
See Also:
3.1.2 TTF_Init,
3.1.4 TTF_Quit
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
|
See Also:
3.1.2 TTF_Init,
3.1.3 TTF_WasInit
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
void TTF_SetError(const char *fmt, ...)
This is really a defined macro for 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 flags, precisions, field widths, nor length modifiers, are supported in the format. For any more specifics read the SDL docs.
|
See Also:
3.1.6 TTF_GetError
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
char *TTF_GetError()
This is really a defined macro for SDL_GetError
. It returns the last error set by TTF_SetError (or SDL_SetError
) as a string. Use this 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.
|
See Also:
3.1.5 TTF_SetError
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions deal with loading and freeing a TTF_Font.
Loading
Freeing
3.2.1 TTF_OpenFont From a file 3.2.2 TTF_OpenFontRW Using RWops 3.2.3 TTF_OpenFontIndex From a file, with an index 3.2.4 TTF_OpenFontIndexRW From memory, with an index
3.2.5 TTF_CloseFont Free a loaded font
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
TTF_Font *TTF_OpenFont(const char *file, int ptsize)
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.
|
See Also:
3.2.3 TTF_OpenFontIndex,
3.2.2 TTF_OpenFontRW,
3.2.5 TTF_CloseFont
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
TTF_Font *TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize)
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.
|
SDL_RWFromFile
's returned pointer.
See Also:
3.2.4 TTF_OpenFontIndexRW,
3.2.1 TTF_OpenFont,
3.2.5 TTF_CloseFont
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
TTF_Font *TTF_OpenFontIndex(const char *file, int ptsize, long index)
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.
|
See Also:
3.2.4 TTF_OpenFontIndexRW,
3.2.1 TTF_OpenFont,
3.2.5 TTF_CloseFont
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
TTF_Font *TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index)
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.
|
SDL_RWFromFile
's returned pointer.
See Also:
3.2.3 TTF_OpenFontIndex,
3.2.2 TTF_OpenFontRW,
3.2.5 TTF_CloseFont
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
void TTF_CloseFont(TTF_Font *font)
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.
|
See Also:
3.2.1 TTF_OpenFont,
3.2.2 TTF_OpenFontRW,
3.2.3 TTF_OpenFontIndex,
3.2.4 TTF_OpenFontIndexRW
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions deal with TTF_Font, and global, attributes.
See the end of 3.3.19 TTF_GlyphMetrics for info on how the metrics work.
Global Attributes
Font Style
3.3.1 TTF_ByteSwappedUNICODE Set default UNICODE byte swapping mode
Font Settings
3.3.2 TTF_GetFontStyle Get font render style 3.3.3 TTF_SetFontStyle Set font render style 3.3.4 TTF_GetFontOutline Get font outline width 3.3.5 TTF_SetFontOutline Set font outline width
Font Metrics
3.3.6 TTF_GetFontHinting Get freetype hinter setting 3.3.7 TTF_SetFontHinting Set freetype hinter setting 3.3.8 TTF_GetFontKerning Get freetype kerning setting 3.3.9 TTF_SetFontKerning Set freetype kerning setting
Face Attributes
3.3.10 TTF_FontHeight Get font maximum total height 3.3.11 TTF_FontAscent Get font highest ascent (height above base) 3.3.12 TTF_FontDescent Get font lowest descent (height below base) 3.3.13 TTF_FontLineSkip Get font recommended line spacing
Glyphs
3.3.14 TTF_FontFaces Get the number of faces in a font 3.3.15 TTF_FontFaceIsFixedWidth Get whether font is monospaced or not 3.3.16 TTF_FontFaceFamilyName Get current font face family name string 3.3.17 TTF_FontFaceStyleName Get current font face style name string
Text Metrics
3.3.18 TTF_GlyphIsProvided Get individual font glyph availability 3.3.19 TTF_GlyphMetrics Get individual font glyph metrics
3.3.20 TTF_SizeText Get size of LATIN1 text string as would be rendered 3.3.21 TTF_SizeUTF8 Get size of UTF8 text string as would be rendered 3.3.22 TTF_SizeUNICODE Get size of UNICODE text string as would be rendered
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
void TTF_ByteSwappedUNICODE(int swapped)
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 endianness of the CPU.
|
See Also:
5. Defines
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_GetFontStyle(TTF_Font *font)
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
TTF_STYLE_STRIKETHROUGH
If no style is set then TTF_STYLE_NORMAL is returned.
|
See Also:
3.3.3 TTF_SetFontStyle,
5. Defines
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
void TTF_SetFontStyle(TTF_Font *font, int style)
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: TTF_STYLE_UNDERLINE may cause surfaces created by TTF_RenderGlyph_*
functions to be extended vertically, downward only, to encompass the underline if the original glyph metrics didn't allow for the underline to be drawn below. This does not change the math used to place a glyph using glyph metrics.
On the other hand TTF_STYLE_STRIKETHROUGH doesn't extend the glyph, since this would invalidate the metrics used to position the glyph when blitting, because they would likely be extended vertically upward. There is perhaps a workaround, but it would require programs to be smarter about glyph blitting math than they are currently designed for.
Still, sometimes the underline or strikethrough may be outside of the generated surface, and thus not visible when blitted to the screen. In this case, you should probably turn off these styles and draw your own strikethroughs and underlines.
|
See Also:
3.3.2 TTF_GetFontStyle,
5. Defines
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_GetFontOutline(TTF_Font *font)
Get the current outline size of the loaded font.
NOTE: Passing a NULL font into this function will cause a segfault.
Returns: The size of the outline currently set on the font, in pixels.
|
See Also:
3.3.5 TTF_SetFontOutline,
3.3.2 TTF_GetFontStyle
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
void TTF_SetFontOutline(TTF_Font *font, int outline)
Set the outline pixel width 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 outline size, so it may be best to check the current outline size using TTF_GetFontOutline
first.
|
See Also:
3.3.4 TTF_GetFontOutline,
3.3.3 TTF_SetFontStyle
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_GetFontHinting(TTF_Font *font)
Get the current hinting setting of the loaded font.
NOTE: Passing a NULL font into this function will cause a segfault.
Returns: The hinting type matching one of the following defined values:
TTF_HINTING_NORMAL
TTF_HINTING_LIGHT
TTF_HINTING_MONO
TTF_HINTING_NONE
If no hinting is set then TTF_HINTING_NORMAL is returned.
|
See Also:
3.3.7 TTF_SetFontHinting,
5. Defines,
see section Hinting,
Font Hinting @ Wikipedia,
FreeType Hinting and Bitmap rendering,
FreeType Hinting Modes
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
void TTF_SetFontHinting(TTF_Font *font, int hinting)
Set the hinting of the loaded font. You should experiment with this setting if you know which font you are using beforehand, especially when using smaller sized fonts. If the user is selecting a font, you may wish to let them select the hinting mode for that font as well.
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 hinting, so it may be best to check the current hinting by using TTF_GetFontHinting
first.
|
See Also:
3.3.6 TTF_GetFontHinting,
5. Defines,
see section Hinting,
Font Hinting @ Wikipedia,
FreeType Hinting and Bitmap rendering,
FreeType Hinting Modes
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_GetFontKerning(TTF_Font *font)
Get the current kerning setting of the loaded font.
NOTE: Passing a NULL font into this function will cause a segfault.
Returns: 0(zero) if kerning is disabled. A non-zero value is returned when enabled. The default for a newly loaded font is enabled(1).
|
See Also:
3.3.9 TTF_SetFontKerning,
see section Kerning,
Kerning @ Wikipedia
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
void TTF_SetFontKerning(TTF_Font *font, int allowed)
Set whther to use kerning when rendering the loaded font. This has no effect on individual glyphs, but rather when rendering whole strings of characters, at least a word at a time. Perhaps the only time to disable this is when kerning is not working for a specific font, resulting in overlapping glyphs or abnormal spacing within words.
NOTE: Passing a NULL font into this function will cause a segfault.
|
See Also:
3.3.8 TTF_GetFontKerning,
see section Kerning,
Kerning @ Wikipedia
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_FontHeight(const TTF_Font *font)
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.
|
See Also:
3.3.11 TTF_FontAscent,
3.3.12 TTF_FontDescent,
3.3.13 TTF_FontLineSkip,
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_FontAscent(const TTF_Font *font)
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.
|
See Also:
3.3.10 TTF_FontHeight,
3.3.12 TTF_FontDescent,
3.3.13 TTF_FontLineSkip,
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_FontDescent(const TTF_Font *font)
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.
|
See Also:
3.3.10 TTF_FontHeight,
3.3.11 TTF_FontAscent,
3.3.13 TTF_FontLineSkip,
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_FontLineSkip(const TTF_Font *font)
Get the recommended 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.
|
See Also:
3.3.10 TTF_FontHeight,
3.3.11 TTF_FontAscent,
3.3.12 TTF_FontDescent,
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
long TTF_FontFaces(const TTF_Font *font)
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 other typographical features perhaps)
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.
|
See Also:
3.3.15 TTF_FontFaceIsFixedWidth,
3.3.16 TTF_FontFaceFamilyName,
3.3.17 TTF_FontFaceStyleName
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_FontFaceIsFixedWidth(const TTF_Font *font)
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.
|
See Also:
3.3.14 TTF_FontFaces,
3.3.16 TTF_FontFaceFamilyName,
3.3.17 TTF_FontFaceStyleName,
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
char * TTF_FontFaceFamilyName(const TTF_Font *font)
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.
|
See Also:
3.3.14 TTF_FontFaces,
3.3.15 TTF_FontFaceIsFixedWidth,
3.3.17 TTF_FontFaceStyleName
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
char * TTF_FontFaceStyleName(const TTF_Font *font)
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.
|
See Also:
3.3.14 TTF_FontFaces,
3.3.15 TTF_FontFaceIsFixedWidth,
3.3.16 TTF_FontFaceFamilyName
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_GlyphIsProvided(const TTF_Font *font, Uint16 ch)
Get the status of the availability of the glyph for ch from the loaded font.
NOTE: Passing a NULL font into this function will cause a segfault.
Returns: the index of the glyph for ch in font, or 0 for an undefined character code.
|
See Also:
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
int *minx, int *maxx,
int *miny, int *maxy,
int *advance)
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.
|
This diagram shows the relationships between the values:
Here's how the numbers look:
|
We see from the Line Skip that each line of text is 55 pixels high,
including spacing for this font.
The Ascent-Descent=52, so there seems to be 3 pixels worth of space between lines for this font.
Let's say we want to draw the surface of glyph 'g' (retrived via
3.4.4 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:
|
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:
|
NOTE: The only difference between these example is the +TTF_FontAscent(font)
used in the top-left corner algorithm.
NOTE: These examples assume that 'g' is present in the font!
NOTE: In practice you may want to also subtract TTF_GetFontOutline(font)
from your X and Y coordinates to keep the glyphs in the same place no matter what outline size is set.
See the web page at The FreeType2 Documentation Tutorial for more.
Any glyph based rendering calculations will not result in accurate kerning between adjacent glyphs. (see section Kerning)
See Also:
3.3.10 TTF_FontHeight,
3.3.11 TTF_FontAscent,
3.3.12 TTF_FontDescent,
3.3.13 TTF_FontLineSkip,
3.3.20 TTF_SizeText,
3.3.21 TTF_SizeUTF8,
3.3.22 TTF_SizeUNICODE,
3.3.18 TTF_GlyphIsProvided,
3.3.4 TTF_GetFontOutline
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_SizeText(TTF_Font *font,
const char *text, int *w, int *h)
Calculate the resulting surface size of the LATIN1 encoded text rendered using font. No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using 3.3.10 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.
|
See Also:
3.3.21 TTF_SizeUTF8,
3.3.22 TTF_SizeUNICODE,
3.4.1 TTF_RenderText_Solid,
3.4.5 TTF_RenderText_Shaded,
3.4.9 TTF_RenderText_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_SizeUTF8(TTF_Font *font,
const char *text, int *w, int *h)
Calculate the resulting surface size of the UTF8 encoded text rendered using font. No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using 3.3.10 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.
|
See Also:
3.3.20 TTF_SizeText,
3.3.22 TTF_SizeUNICODE,
3.4.2 TTF_RenderUTF8_Solid,
3.4.6 TTF_RenderUTF8_Shaded,
3.4.10 TTF_RenderUTF8_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
int TTF_SizeUNICODE(TTF_Font *font,
const Unit16 *text, int *w, int *h)
Calculate the resulting surface size of the UNICODE encoded text rendered using font. No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using 3.3.10 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.
|
See Also:
3.3.20 TTF_SizeText,
3.3.21 TTF_SizeUTF8,
3.4.3 TTF_RenderUNICODE_Solid,
3.4.7 TTF_RenderUNICODE_Shaded,
3.4.11 TTF_RenderUNICODE_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions render text using a TTF_Font
.
There are three modes of rendering:
Solid
Shaded
3.4.1 TTF_RenderText_Solid Draw LATIN1 text in solid mode 3.4.2 TTF_RenderUTF8_Solid Draw UTF8 text in solid mode 3.4.3 TTF_RenderUNICODE_Solid Draw UNICODE text in solid mode 3.4.4 TTF_RenderGlyph_Solid Draw a UNICODE glyph in solid mode
Blended
3.4.5 TTF_RenderText_Shaded Draw LATIN1 text in shaded mode 3.4.6 TTF_RenderUTF8_Shaded Draw UTF8 text in shaded mode 3.4.7 TTF_RenderUNICODE_Shaded Draw UNICODE text in shaded mode 3.4.8 TTF_RenderGlyph_Shaded Draw a UNICODE glyph in shaded mode
3.4.9 TTF_RenderText_Blended Draw LATIN1 text in blended mode 3.4.10 TTF_RenderUTF8_Blended Draw UTF8 text in blended mode 3.4.11 TTF_RenderUNICODE_Blended Draw UNICODE text in blended mode 3.4.12 TTF_RenderGlyph_Blended Draw a UNICODE glyph in blended mode
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderText_Solid(TTF_Font *font,
const char *text, SDL_Color fg)
Render the LATIN1 encoded text using font with fg color onto a new surface, using the Solid mode (see section 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.
|
See Also:
3.3.20 TTF_SizeText,
3.4.2 TTF_RenderUTF8_Solid,
3.4.3 TTF_RenderUNICODE_Solid,
3.4.4 TTF_RenderGlyph_Solid,
3.4.5 TTF_RenderText_Shaded,
3.4.9 TTF_RenderText_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderUTF8_Solid(TTF_Font *font,
const char *text, SDL_Color fg)
Render the UTF8 encoded text using font with fg color onto a new surface, using the Solid mode (see section 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.
|
See Also:
3.3.21 TTF_SizeUTF8,
3.4.1 TTF_RenderText_Solid,
3.4.3 TTF_RenderUNICODE_Solid,
3.4.4 TTF_RenderGlyph_Solid,
3.4.6 TTF_RenderUTF8_Shaded,
3.4.10 TTF_RenderUTF8_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
const Uint16 *text, SDL_Color fg)
Render the UNICODE encoded text using font with fg color onto a new surface, using the Solid mode (see section 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.
|
See Also:
3.3.22 TTF_SizeUNICODE,
3.4.1 TTF_RenderText_Solid,
3.4.2 TTF_RenderUTF8_Solid,
3.4.4 TTF_RenderGlyph_Solid,
3.4.7 TTF_RenderUNICODE_Shaded,
3.4.11 TTF_RenderUNICODE_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderGlyph_Solid(TTF_Font *font,
Uint16 ch, SDL_Color fg)
Render the glyph for the UNICODE ch using font with fg color onto a new surface, using the Solid mode (see section 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.
|
See Also:
3.4.8 TTF_RenderGlyph_Shaded,
3.4.12 TTF_RenderGlyph_Blended,
3.4.1 TTF_RenderText_Solid,
3.4.2 TTF_RenderUTF8_Solid,
3.4.4 TTF_RenderGlyph_Solid,
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderText_Shaded(TTF_Font *font,
const char *text, SDL_Color fg, SDL_Color bg)
Render the LATIN1 encoded text using font with fg color onto a new surface filled with the bg color, using the Shaded mode (see section 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.
|
See Also:
3.3.20 TTF_SizeText,
3.4.6 TTF_RenderUTF8_Shaded,
3.4.7 TTF_RenderUNICODE_Shaded,
3.4.8 TTF_RenderGlyph_Shaded,
3.4.1 TTF_RenderText_Solid,
3.4.9 TTF_RenderText_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderUTF8_Shaded(TTF_Font *font,
const char *text, SDL_Color fg, SDL_Color bg)
Render the UTF8 encoded text using font with fg color onto a new surface filled with the bg color, using the Shaded mode (see section 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.
|
See Also:
3.3.21 TTF_SizeUTF8,
3.4.5 TTF_RenderText_Shaded,
3.4.7 TTF_RenderUNICODE_Shaded,
3.4.8 TTF_RenderGlyph_Shaded,
3.4.2 TTF_RenderUTF8_Solid,
3.4.10 TTF_RenderUTF8_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderUNICODE_Shaded(TTF_Font *font,
const Uint16 *text, SDL_Color fg, SDL_Color bg)
Render the UNICODE encoded text using font with fg color onto a new surface filled with the bg color, using the Shaded mode (see section 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.
|
See Also:
3.3.22 TTF_SizeUNICODE,
3.4.5 TTF_RenderText_Shaded,
3.4.6 TTF_RenderUTF8_Shaded,
3.4.8 TTF_RenderGlyph_Shaded,
3.4.3 TTF_RenderUNICODE_Solid,
3.4.11 TTF_RenderUNICODE_Blended
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderGlyph_Shaded(TTF_Font *font,
Uint16 ch, SDL_Color fg, SDL_Color bg)
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 section 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.
|
See Also:
3.4.4 TTF_RenderGlyph_Solid,
3.4.12 TTF_RenderGlyph_Blended,
3.4.5 TTF_RenderText_Shaded,
3.4.6 TTF_RenderUTF8_Shaded,
3.4.8 TTF_RenderGlyph_Shaded,
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderText_Blended(TTF_Font *font,
const char *text, SDL_Color fg)
Render the LATIN1 encoded text using font with fg color onto a new surface, using the Blended mode (see section 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.
|
See Also:
3.3.20 TTF_SizeText,
3.4.10 TTF_RenderUTF8_Blended,
3.4.11 TTF_RenderUNICODE_Blended,
3.4.12 TTF_RenderGlyph_Blended,
3.4.1 TTF_RenderText_Solid,
3.4.5 TTF_RenderText_Shaded
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderUTF8_Blended(TTF_Font *font,
const char *text, SDL_Color fg)
Render the UTF8 encoded text using font with fg color onto a new surface, using the Blended mode (see section 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.
|
See Also:
3.3.21 TTF_SizeUTF8,
3.4.9 TTF_RenderText_Blended,
3.4.11 TTF_RenderUNICODE_Blended,
3.4.12 TTF_RenderGlyph_Blended,
3.4.2 TTF_RenderUTF8_Solid,
3.4.6 TTF_RenderUTF8_Shaded
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderUNICODE_Blended(TTF_Font *font,
const Uint16 *text, SDL_Color fg)
Render the UNICODE encoded text using font with fg color onto a new surface, using the Blended mode (see section 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.
|
See Also:
3.3.22 TTF_SizeUNICODE,
3.4.9 TTF_RenderText_Blended,
3.4.10 TTF_RenderUTF8_Blended,
3.4.12 TTF_RenderGlyph_Blended,
3.4.3 TTF_RenderUNICODE_Solid,
3.4.7 TTF_RenderUNICODE_Shaded
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SDL_Surface *TTF_RenderGlyph_Blended(TTF_Font *font,
Uint16 ch, SDL_Color fg)
Render the glyph for the UNICODE ch using font with fg color onto a new surface, using the Blended mode (see section 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.
|
See Also:
3.4.4 TTF_RenderGlyph_Solid,
3.4.8 TTF_RenderGlyph_Shaded,
3.4.9 TTF_RenderText_Blended,
3.4.10 TTF_RenderUTF8_Blended,
3.4.12 TTF_RenderGlyph_Blended,
3.3.19 TTF_GlyphMetrics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These types are defined and used by the SDL_ttf API.
4.1 TTF_Font The opaque holder of a loaded font
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
|
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:
3.2 Management
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
2
0
10
0xFEFF
0xFFFE
0x00
0x01
0x02
0x04
0x08
0
0
0
0
See Also:
6. Glossary,
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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. |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Jump to: | A B H K L M R S T U |
---|
Jump to: | A B H K L M R S T U |
---|
[Top] | [Contents] | [Index] | [ ? ] |
[Top] | [Contents] | [Index] | [ ? ] |
1. Overview
2. Getting Started
3. Functions
4. Types
5. Defines
6. Glossary
Index
[Top] | [Contents] | [Index] | [ ? ] |
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ < ] | Back | previous section in reading order | 1.2.2 |
[ > ] | Forward | next section in reading order | 1.2.4 |
[ << ] | FastBack | previous or up-and-previous section | 1.1 |
[ Up ] | Up | up section | 1.2 |
[ >> ] | FastForward | next or up-and-next section | 1.3 |
[Top] | Top | cover (top) of document | |
[Contents] | Contents | table of contents | |
[Index] | Index | concept index | |
[ ? ] | About | this page |