SDL2 multimedia library for 2D graphics, input handling, audio playback, and window management. Core types: Window, Renderer, Texture, Surface, Event, and Mixer. Compile with -lib sdl2.
Font
TrueType font rendering
Operations
- New
- Free
- GetAscent
- GetDescent
- GetHeight
- GetLineSkip
- GetOutline
- GetStyle
- Init
- IsNull
- Quit
- RenderTextBlended
- RenderTextShaded
- RenderTextSolid
- RenderUTF8Blended
- RenderUTF8BlendedWrapped
- RenderUTF8Shaded
- RenderUTF8Solid
- SetOutline
- SetStyle
- SizeUTF8
Free #
Close the font and release it.
TTF_CloseFont was never bound, so until now a loaded font could not be released at all -- which is why every example that draws text simply leaks one.
Font->Quit() is NOT this. That is the static TTF_Quit, which shuts down the whole subsystem; calling it once per font, as some code does, is a different thing entirely.
Safe to call twice -- the handle is cleared. Do not use the font afterwards, and close it before Quit.
method : public : Free() ~ NilGetAscent #
Maximum distance of the font's glyphs above the baseline
method : public : GetAscent() ~ IntReturn
| Type | Description |
|---|---|
| Int | ascent in pixels, or -1 for a closed font |
GetDescent #
Maximum distance of the font's glyphs below the baseline
method : public : GetDescent() ~ IntReturn
| Type | Description |
|---|---|
| Int | descent in pixels, negative below the baseline; 0 for a closed font |
GetHeight #
Maximum height of the font's glyphs
method : public : GetHeight() ~ IntReturn
| Type | Description |
|---|---|
| Int | height in pixels, or -1 for a closed font |
GetLineSkip #
Recommended spacing between lines of text
method : public : GetLineSkip() ~ IntReturn
| Type | Description |
|---|---|
| Int | line skip in pixels, or -1 for a closed font |
GetOutline #
Get the outline width
method : public : GetOutline() ~ IntReturn
| Type | Description |
|---|---|
| Int | outline width in pixels, or -1 for a closed font |
GetStyle #
Get the rendering style
method : public : GetStyle() ~ IntReturn
| Type | Description |
|---|---|
| Int | FontStyle values OR'd together, or -1 for a closed font |
IsNull #
Determines if the underlying SDL C-struct is NULL
method : public : IsNull() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if NULL, false otherwise |
New # constructor
Load file for use as a font, this can load TTF and FON files.
New(file:String, ptsize:Int)Parameters
| Name | Type | Description |
|---|---|---|
| file | String | file name to load font from. |
| ptsize | Int | Point size (based on 72DPI) to load font as |
New # constructor
Load file for use as a font, this can load TTF and FON files.
New(file:String, ptsize:Int, index:Int)Parameters
| Name | Type | Description |
|---|---|---|
| file | String | file name to load font from. |
| ptsize | Int | Point size (based on 72DPI) to load font as |
| index | Int | choose a font face from a file containing multiple font faces. The first face is always index 0. |
RenderTextBlended #
Render the LATIN1 encoded text blended
method : public : RenderTextBlended(text:String, fg:Color) ~ SurfaceParameters
| Name | Type | Description |
|---|---|---|
| text | String | the LATIN1 null terminated string to render. |
| fg | Color | the color to render the text in. This becomes colormap index 1. |
Return
| Type | Description |
|---|---|
| Surface | Surface instance, caller responsible for freeing |
RenderTextShaded #
Render the LATIN1 encoded text shaded
method : public : RenderTextShaded(text:String, fg:Color, bg:Color) ~ SurfaceParameters
| Name | Type | Description |
|---|---|---|
| text | String | the LATIN1 null terminated string to render. |
| fg | Color | the color to render the text in. This becomes colormap index 1. |
| bg | Color | the color to render the background box in. This becomes colormap index 0. |
Return
| Type | Description |
|---|---|
| Surface | Surface instance, caller responsible for freeing |
RenderTextSolid #
Render the LATIN1 encoded text blended
method : public : RenderTextSolid(text:String, fg:Color) ~ SurfaceParameters
| Name | Type | Description |
|---|---|---|
| text | String | the LATIN1 null terminated string to render. |
| fg | Color | the color to render the text in. This becomes colormap index 1. |
Return
| Type | Description |
|---|---|
| Surface | Surface instance, caller responsible for freeing |
RenderUTF8Blended #
Render the UTF8 encoded text blended
method : public : RenderUTF8Blended(text:String, fg:Color) ~ SurfaceParameters
| Name | Type | Description |
|---|---|---|
| text | String | the LATIN1 null terminated string to render. |
| fg | Color | the color to render the text in. This becomes colormap index 1. |
Return
| Type | Description |
|---|---|
| Surface | Surface instance, caller responsible for freeing |
RenderUTF8BlendedWrapped #
Render UTF8 text blended, wrapping lines at word boundaries so no line is wider than wrap_length pixels. Lines are also broken at newlines.
method : public : RenderUTF8BlendedWrapped(text:String, fg:Color, wrap_length:Int) ~ SurfaceParameters
| Name | Type | Description |
|---|---|---|
| text | String | the text to render |
| fg | Color | the color to render the text in |
| wrap_length | Int | the maximum line width in pixels; 0 breaks lines only at newlines |
Return
| Type | Description |
|---|---|
| Surface | Surface instance, caller responsible for freeing; IsNull() is true on failure |
RenderUTF8Shaded #
Render the UTF8 encoded text shaded
method : public : RenderUTF8Shaded(text:String, fg:Color, bg:Color) ~ SurfaceParameters
| Name | Type | Description |
|---|---|---|
| text | String | the LATIN1 null terminated string to render. |
| fg | Color | the color to render the text in. This becomes colormap index 1. |
| bg | Color | the color to render the background box in. This becomes colormap index 0. |
Return
| Type | Description |
|---|---|
| Surface | Surface instance, caller responsible for freeing |
RenderUTF8Solid #
Render the UTF8 encoded text blended
method : public : RenderUTF8Solid(text:String, fg:Color) ~ SurfaceParameters
| Name | Type | Description |
|---|---|---|
| text | String | the LATIN1 null terminated string to render. |
| fg | Color | the color to render the text in. This becomes colormap index 1. |
Return
| Type | Description |
|---|---|
| Surface | Surface instance, caller responsible for freeing |
SetOutline #
Set the outline width; text is then rendered as an outline of that many pixels
method : public : SetOutline(outline:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| outline | Int | outline width in pixels, 0 for no outline |
SetStyle #
Set the rendering style
method : public : SetStyle(style:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| style | Int | FontStyle values OR'd together, such as FontStyle->TTF_STYLE_BOLD |
SizeUTF8 #
Measure the size UTF8 text would have if rendered, without rendering it. Use it to center, right-align or fit a label.
method : public : SizeUTF8(text:String, w:IntRef, h:IntRef) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| text | String | the text to measure |
| w | IntRef | holder filled in with the width in pixels |
| h | IntRef | holder filled in with the height in pixels |
Return
| Type | Description |
|---|---|
| Int | 0 on success, or a negative value on failure or for a closed font |
Example
w := IntRef->New(); h := IntRef->New();
if(font->SizeUTF8("Accuracy: 0.97", w, h) = 0) {
x := (640 - w->Get()) / 2;
};