//
// Generated by Brutal.Sdl.Generate; do not edit by hand.
#nullable enable
namespace Brutal.SdlApi.Ttf
{
public static unsafe partial class SdlTtf
{
///
/// This function gets the version of the dynamically linked SDL_ttf library.
///
/// SDL_ttf version.
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static int Version() => PInvoke.Version();
///
/// Query the version of the FreeType library in use.
///
/// to be filled in with the major version number. Can be NULL.
/// to be filled in with the minor version number. Can be NULL.
/// to be filled in with the param version number. Can be NULL.
///
///
/// TTF_Init() should be called before calling this function.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void GetFreeTypeVersion(out int major, out int minor, out int patch)
{
major = default;
minor = default;
patch = default;
fixed (int* majorPtr = &major)
{
fixed (int* minorPtr = &minor)
{
fixed (int* patchPtr = &patch)
{
PInvoke.GetFreeTypeVersion(majorPtr, minorPtr, patchPtr);
}
}
}
}
///
/// Query the version of the HarfBuzz library in use.
///
/// to be filled in with the major version number. Can be NULL.
/// to be filled in with the minor version number. Can be NULL.
/// to be filled in with the param version number. Can be NULL.
///
///
/// If HarfBuzz is not available, the version reported is 0.0.0.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static void GetHarfBuzzVersion(out int major, out int minor, out int patch)
{
major = default;
minor = default;
patch = default;
fixed (int* majorPtr = &major)
{
fixed (int* minorPtr = &minor)
{
fixed (int* patchPtr = &patch)
{
PInvoke.GetHarfBuzzVersion(majorPtr, minorPtr, patchPtr);
}
}
}
}
///
/// Ergonomic wrapper over TTF_Init. Throws instead of returning false on failure.
///
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static void Init()
{
if (PInvoke.Init() == 0)
{
throw SdlException.FromError("TTF_Init failed");
}
}
///
/// Ergonomic wrapper over TTF_OpenFont. Throws instead of returning a null handle on failure.
///
/// path to font file.
/// point size to use for the newly-opened font.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfFont OpenFont(string file, float ptsize)
{
TtfFont result = PInvoke.OpenFont(file, ptsize);
if (result.IsNull())
{
throw SdlException.FromError("TTF_OpenFont failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_OpenFontIO. Throws instead of returning a null handle on failure.
///
/// an SDL_IOStream to provide a font file's data.
///
/// true to close src when the font is closed, false to leave
/// it open.
///
/// point size to use for the newly-opened font.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfFont OpenFontIO(nint src, bool closeio, float ptsize)
{
TtfFont result = PInvoke.OpenFontIO(src, closeio ? (byte)1 : (byte)0, ptsize);
if (result.IsNull())
{
throw SdlException.FromError("TTF_OpenFontIO failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_OpenFontWithProperties. Throws instead of returning a null handle on
/// failure.
///
/// the properties to use.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfFont OpenFontWithProperties(uint props)
{
TtfFont result = PInvoke.OpenFontWithProperties(props);
if (result.IsNull())
{
throw SdlException.FromError("TTF_OpenFontWithProperties failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_CopyFont. Throws instead of returning a null handle on failure.
///
/// the font to copy.
/// The created handle (never a null handle).
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfFont CopyFont(TtfFont existing_font)
{
TtfFont result = PInvoke.CopyFont(existing_font);
if (result.IsNull())
{
throw SdlException.FromError("TTF_CopyFont failed");
}
return result;
}
///
/// Get the properties associated with a font.
///
/// the font to query.
///
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
///
///
///
/// The following read-write properties are provided by SDL:
///
///
/// - TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER: The FT_Stroker_LineCap value
/// used when setting the font outline, defaults to
/// FT_STROKER_LINECAP_ROUND.
/// - TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER: The FT_Stroker_LineJoin value
/// used when setting the font outline, defaults to
/// FT_STROKER_LINEJOIN_ROUND.
/// - TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER: The FT_Fixed miter limit used
/// when setting the font outline, defaults to 0.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static uint GetFontProperties(TtfFont font) => PInvoke.GetFontProperties(font);
///
/// Get the font generation.
///
/// the font to query.
///
/// the font generation or 0 on failure; call SDL_GetError() for more
/// information.
///
///
///
/// The generation is incremented each time font properties change that require
/// rebuilding glyphs, such as style, size, etc.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static uint GetFontGeneration(TtfFont font) => PInvoke.GetFontGeneration(font);
///
/// Add a fallback font.
///
/// the font to modify.
/// the font to add as a fallback.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// Add a font that will be used for glyphs that are not in the current font.
/// The fallback font should have the same size and style as the current font.
///
///
/// If there are multiple fallback fonts, they are used in the order added.
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created
/// both fonts.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static bool AddFallbackFont(TtfFont font, TtfFont fallback) =>
PInvoke.AddFallbackFont(font, fallback) != 0;
///
/// Remove a fallback font.
///
/// the font to modify.
/// the font to remove as a fallback.
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created
/// both fonts.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static void RemoveFallbackFont(TtfFont font, TtfFont fallback) =>
PInvoke.RemoveFallbackFont(font, fallback);
///
/// Remove all fallback fonts.
///
/// the font to modify.
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static void ClearFallbackFonts(TtfFont font) => PInvoke.ClearFallbackFonts(font);
///
/// Set a font's size dynamically.
///
/// the font to resize.
/// the new point size.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This updates any TTF_Text objects using this font, and clears
/// already-generated glyphs, if any, from the cache.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetFontSize(TtfFont font, float ptsize) => PInvoke.SetFontSize(font, ptsize) != 0;
///
/// Set font size dynamically with target resolutions, in dots per inch.
///
/// the font to resize.
/// the new point size.
/// the target horizontal DPI.
/// the target vertical DPI.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This updates any TTF_Text objects using this font, and clears
/// already-generated glyphs, if any, from the cache.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetFontSizeDPI(TtfFont font, float ptsize, int hdpi, int vdpi) =>
PInvoke.SetFontSizeDPI(font, ptsize, hdpi, vdpi) != 0;
///
/// Get the size of a font.
///
/// the font to query.
///
/// the size of the font, or 0.0f on failure; call SDL_GetError() for
/// more information.
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static float GetFontSize(TtfFont font) => PInvoke.GetFontSize(font);
///
/// Get font target resolutions, in dots per inch.
///
/// the font to query.
/// a pointer filled in with the target horizontal DPI.
/// a pointer filled in with the target vertical DPI.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool GetFontDPI(TtfFont font, out int hdpi, out int vdpi)
{
hdpi = default;
vdpi = default;
fixed (int* hdpiPtr = &hdpi)
{
fixed (int* vdpiPtr = &vdpi)
{
return PInvoke.GetFontDPI(font, hdpiPtr, vdpiPtr) != 0;
}
}
}
///
/// Set a font's current style.
///
/// the font to set a new style on.
/// the new style values to set, OR'd together.
///
///
/// This updates any TTF_Text objects using this font, and clears
/// already-generated glyphs, if any, from the cache.
///
///
/// The font styles are a set of bit flags, OR'd together:
///
///
/// - TTF_STYLE_NORMAL (is zero)
/// - TTF_STYLE_BOLD
/// - TTF_STYLE_ITALIC
/// - TTF_STYLE_UNDERLINE
/// - TTF_STYLE_STRIKETHROUGH
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void SetFontStyle(TtfFont font, TtfFontStyleFlags style) => PInvoke.SetFontStyle(font, style);
///
/// Query a font's current style.
///
/// the font to query.
/// the current font style, as a set of bit flags.
///
///
/// The font styles are a set of bit flags, OR'd together:
///
///
/// - TTF_STYLE_NORMAL (is zero)
/// - TTF_STYLE_BOLD
/// - TTF_STYLE_ITALIC
/// - TTF_STYLE_UNDERLINE
/// - TTF_STYLE_STRIKETHROUGH
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static TtfFontStyleFlags GetFontStyle(TtfFont font) => PInvoke.GetFontStyle(font);
///
/// Set a font's current outline.
///
/// the font to set a new outline on.
/// positive outline value, 0 to default.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This uses the font properties TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER,
/// TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER, and
/// TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER when setting the font outline.
///
///
/// This updates any TTF_Text objects using this font, and clears
/// already-generated glyphs, if any, from the cache.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetFontOutline(TtfFont font, int outline) => PInvoke.SetFontOutline(font, outline) != 0;
///
/// Query a font's current outline.
///
/// the font to query.
/// the font's current outline value.
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static int GetFontOutline(TtfFont font) => PInvoke.GetFontOutline(font);
///
/// Set a font's current hinter setting.
///
/// the font to set a new hinter setting on.
/// the new hinter setting.
///
///
/// This updates any TTF_Text objects using this font, and clears
/// already-generated glyphs, if any, from the cache.
///
///
/// The hinter setting is a single value:
///
///
/// - TTF_HINTING_NORMAL
/// - TTF_HINTING_LIGHT
/// - TTF_HINTING_MONO
/// - TTF_HINTING_NONE
/// - TTF_HINTING_LIGHT_SUBPIXEL (available in SDL_ttf 3.0.0 and later)
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void SetFontHinting(TtfFont font, TtfHintingFlags hinting) =>
PInvoke.SetFontHinting(font, hinting);
///
/// Query the number of faces of a font.
///
/// the font to query.
/// the number of FreeType font faces.
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static int GetNumFontFaces(TtfFont font) => PInvoke.GetNumFontFaces(font);
///
/// Query a font's current FreeType hinter setting.
///
/// the font to query.
///
/// the font's current hinter value, or TTF_HINTING_INVALID if the
/// font is invalid.
///
///
///
/// The hinter setting is a single value:
///
///
/// - TTF_HINTING_NORMAL
/// - TTF_HINTING_LIGHT
/// - TTF_HINTING_MONO
/// - TTF_HINTING_NONE
/// - TTF_HINTING_LIGHT_SUBPIXEL (available in SDL_ttf 3.0.0 and later)
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static TtfHintingFlags GetFontHinting(TtfFont font) => PInvoke.GetFontHinting(font);
///
/// Enable Signed Distance Field rendering for a font.
///
/// the font to set SDF support on.
/// true to enable SDF, false to disable.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// SDF is a technique that helps fonts look sharp even when scaling and
/// rotating, and requires special shader support for display.
///
///
/// This works with Blended APIs, and generates the raw signed distance values
/// in the alpha channel of the resulting texture.
///
///
/// This updates any TTF_Text objects using this font, and clears
/// already-generated glyphs, if any, from the cache.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetFontSDF(TtfFont font, bool enabled) =>
PInvoke.SetFontSDF(font, enabled ? (byte)1 : (byte)0) != 0;
///
/// Query whether Signed Distance Field rendering is enabled for a font.
///
/// the font to query.
/// true if enabled, false otherwise.
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool GetFontSDF(TtfFont font) => PInvoke.GetFontSDF(font) != 0;
///
/// Query a font's weight, in terms of the lightness/heaviness of the strokes.
///
/// the font to query.
/// the font's current weight.
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.4.0.
///
public static int GetFontWeight(TtfFont font) => PInvoke.GetFontWeight(font);
///
/// Set a font's current wrap alignment option.
///
/// the font to set a new wrap alignment option on.
/// the new wrap alignment option.
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void SetFontWrapAlignment(TtfFont font, TtfHorizontalAlignment align) =>
PInvoke.SetFontWrapAlignment(font, align);
///
/// Query a font's current wrap alignment option.
///
/// the font to query.
/// the font's current wrap alignment option.
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static TtfHorizontalAlignment GetFontWrapAlignment(TtfFont font) => PInvoke.GetFontWrapAlignment(font);
///
/// Query the total height of a font.
///
/// the font to query.
/// the font's height.
///
///
/// This is usually equal to point size.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static int GetFontHeight(TtfFont font) => PInvoke.GetFontHeight(font);
///
/// Query the offset from the baseline to the top of a font.
///
/// the font to query.
/// the font's ascent.
///
///
/// This is a positive value, relative to the baseline.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static int GetFontAscent(TtfFont font) => PInvoke.GetFontAscent(font);
///
/// Query the offset from the baseline to the bottom of a font.
///
/// the font to query.
/// the font's descent.
///
///
/// This is a negative value, relative to the baseline.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static int GetFontDescent(TtfFont font) => PInvoke.GetFontDescent(font);
///
/// Set the spacing between lines of text for a font.
///
/// the font to modify.
/// the new line spacing for the font.
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void SetFontLineSkip(TtfFont font, int lineskip) => PInvoke.SetFontLineSkip(font, lineskip);
///
/// Query the spacing between lines of text for a font.
///
/// the font to query.
/// the font's recommended spacing.
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static int GetFontLineSkip(TtfFont font) => PInvoke.GetFontLineSkip(font);
///
/// Set if kerning is enabled for a font.
///
/// the font to set kerning on.
/// true to enable kerning, false to disable.
///
///
/// Newly-opened fonts default to allowing kerning. This is generally a good
/// policy unless you have a strong reason to disable it, as it tends to
/// produce better rendering (with kerning disabled, some fonts might render
/// the word kerning as something that looks like keming for example).
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void SetFontKerning(TtfFont font, bool enabled) =>
PInvoke.SetFontKerning(font, enabled ? (byte)1 : (byte)0);
///
/// Query whether or not kerning is enabled for a font.
///
/// the font to query.
/// true if kerning is enabled, false otherwise.
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool GetFontKerning(TtfFont font) => PInvoke.GetFontKerning(font) != 0;
///
/// Query whether a font is fixed-width.
///
/// the font to query.
/// true if the font is fixed-width, false otherwise.
///
///
/// A "fixed-width" font means all glyphs are the same width across; a
/// lowercase 'i' will be the same size across as a capital 'W', for example.
/// This is common for terminals and text editors, and other apps that treat
/// text as a grid. Most other things (WYSIWYG word processors, web pages, etc)
/// are more likely to not be fixed-width in most cases.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool FontIsFixedWidth(TtfFont font) => PInvoke.FontIsFixedWidth(font) != 0;
///
/// Query whether a font is scalable or not.
///
/// the font to query.
/// true if the font is scalable, false otherwise.
///
///
/// Scalability lets us distinguish between outline and bitmap fonts.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool FontIsScalable(TtfFont font) => PInvoke.FontIsScalable(font) != 0;
///
/// Query a font's family name.
///
/// the font to query.
/// the font's family name.
///
///
/// This string is dictated by the contents of the font file.
///
///
/// Note that the returned string is to internal storage, and should not be
/// modified or free'd by the caller. The string becomes invalid, with the rest
/// of the font, when font is handed to TTF_CloseFont().
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static string? GetFontFamilyName(TtfFont font) => PInvoke.GetFontFamilyName(font);
///
/// Query a font's style name.
///
/// the font to query.
/// the font's style name.
///
///
/// This string is dictated by the contents of the font file.
///
///
/// Note that the returned string is to internal storage, and should not be
/// modified or free'd by the caller. The string becomes invalid, with the rest
/// of the font, when font is handed to TTF_CloseFont().
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static string? GetFontStyleName(TtfFont font) => PInvoke.GetFontStyleName(font);
///
/// Set the direction to be used for text shaping by a font.
///
/// the font to modify.
/// the new direction for text to flow.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This function only supports left-to-right text shaping if SDL_ttf was not
/// built with HarfBuzz support.
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool SetFontDirection(TtfFont font, TtfDirection direction) =>
PInvoke.SetFontDirection(font, direction) != 0;
///
/// Get the direction to be used for text shaping by a font.
///
/// the font to query.
/// the direction to be used for text shaping.
///
///
/// This defaults to TTF_DIRECTION_INVALID if it hasn't been set.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static TtfDirection GetFontDirection(TtfFont font) => PInvoke.GetFontDirection(font);
///
/// Convert from a 4 character string to a 32-bit tag.
///
/// the 4 character string to convert.
/// the 32-bit representation of the string.
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static uint StringToTag(string @string) => PInvoke.StringToTag(@string);
///
/// Convert from a 32-bit tag to a 4 character string.
///
/// the 32-bit tag to convert.
///
/// a pointer filled in with the 4 character representation of
/// the tag.
///
///
/// the size of the buffer pointed at by string, should be at least
/// 4.
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void TagToString(uint tag, byte* @string, nuint size) => PInvoke.TagToString(tag, @string, size);
///
/// Set the script to be used for text shaping by a font.
///
/// the font to modify.
///
/// an
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
/// .
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This returns false if SDL_ttf isn't built with HarfBuzz support.
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetFontScript(TtfFont font, uint script) => PInvoke.SetFontScript(font, script) != 0;
///
/// Get the script used for text shaping a font.
///
/// the font to query.
///
/// an
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
/// or 0 if a script hasn't been set.
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static uint GetFontScript(TtfFont font) => PInvoke.GetFontScript(font);
///
/// Get the script used by a 32-bit codepoint.
///
/// the character code to check.
///
/// an
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
/// on success, or 0 on failure; call SDL_GetError() for more
/// information.
///
///
/// This function is thread-safe.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static uint GetGlyphScript(uint ch) => PInvoke.GetGlyphScript(ch);
///
/// Set language to be used for text shaping by a font.
///
/// the font to specify a language for.
///
/// a null-terminated string containing the desired
/// language's BCP47 code. Or null to reset the value.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// If SDL_ttf was not built with HarfBuzz support, this function returns
/// false.
///
///
/// This updates any TTF_Text objects using this font.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool SetFontLanguage(TtfFont font, string language_bcp47) =>
PInvoke.SetFontLanguage(font, language_bcp47) != 0;
///
/// Check whether a glyph is provided by the font for a UNICODE codepoint.
///
/// the font to query.
/// the codepoint to check.
/// true if font provides a glyph for this character, false if not.
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool FontHasGlyph(TtfFont font, uint ch) => PInvoke.FontHasGlyph(font, ch) != 0;
///
/// Get the pixel image for a UNICODE codepoint.
///
/// the font to query.
/// the codepoint to check.
///
/// a pointer filled in with the glyph image type, may be
/// NULL.
///
///
/// an SDL_Surface containing the glyph, or NULL on failure; call
/// SDL_GetError() for more information.
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static SdlSurface* GetGlyphImage(TtfFont font, uint ch, out TtfImageType image_type)
{
image_type = default;
fixed (TtfImageType* image_typePtr = &image_type)
{
return PInvoke.GetGlyphImage(font, ch, image_typePtr);
}
}
///
/// Get the pixel image for a character index.
///
/// the font to query.
/// the index of the glyph to return.
///
/// a pointer filled in with the glyph image type, may be
/// NULL.
///
///
/// an SDL_Surface containing the glyph, or NULL on failure; call
/// SDL_GetError() for more information.
///
///
///
/// This is useful for text engine implementations, which can call this with
/// the glyph_index in a TTF_CopyOperation
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static SdlSurface* GetGlyphImageForIndex(TtfFont font, uint glyph_index, out TtfImageType image_type)
{
image_type = default;
fixed (TtfImageType* image_typePtr = &image_type)
{
return PInvoke.GetGlyphImageForIndex(font, glyph_index, image_typePtr);
}
}
///
/// Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint.
///
/// the font to query.
/// the codepoint to check.
///
/// a pointer filled in with the minimum x coordinate of the glyph
/// from the left edge of its bounding box. This value may be
/// negative.
///
///
/// a pointer filled in with the maximum x coordinate of the glyph
/// from the left edge of its bounding box.
///
///
/// a pointer filled in with the minimum y coordinate of the glyph
/// from the bottom edge of its bounding box. This value may be
/// negative.
///
///
/// a pointer filled in with the maximum y coordinate of the glyph
/// from the bottom edge of its bounding box.
///
///
/// a pointer filled in with the distance to the next glyph from
/// the left edge of this glyph's bounding box.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// To understand what these metrics mean, here is a useful link:
///
///
/// https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetGlyphMetrics(
TtfFont font,
uint ch,
out int minx,
out int maxx,
out int miny,
out int maxy,
out int advance
)
{
minx = default;
maxx = default;
miny = default;
maxy = default;
advance = default;
fixed (int* minxPtr = &minx)
{
fixed (int* maxxPtr = &maxx)
{
fixed (int* minyPtr = &miny)
{
fixed (int* maxyPtr = &maxy)
{
fixed (int* advancePtr = &advance)
{
return PInvoke.GetGlyphMetrics(font, ch, minxPtr, maxxPtr, minyPtr, maxyPtr, advancePtr)
!= 0;
}
}
}
}
}
}
///
/// Query the kerning size between the glyphs of two UNICODE codepoints.
///
/// the font to query.
/// the previous codepoint.
/// the current codepoint.
///
/// a pointer filled in with the kerning size between the two
/// glyphs, in pixels, may be NULL.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetGlyphKerning(TtfFont font, uint previous_ch, uint ch, out int kerning)
{
kerning = default;
fixed (int* kerningPtr = &kerning)
{
return PInvoke.GetGlyphKerning(font, previous_ch, ch, kerningPtr) != 0;
}
}
///
/// Calculate the dimensions of a rendered string of UTF-8 text.
///
/// the font to query.
/// text to calculate, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// will be filled with width, in pixels, on return.
/// will be filled with height, in pixels, on return.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This will report the width and height, in pixels, of the space that the
/// specified string will take to fully render.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetStringSize(TtfFont font, string text, nuint length, int* w, int* h) =>
PInvoke.GetStringSize(font, text, length, w, h) != 0;
///
/// Calculate the dimensions of a rendered string of UTF-8 text.
///
/// the font to query.
/// text to calculate, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the maximum width or 0 to wrap on newline characters.
/// will be filled with width, in pixels, on return.
/// will be filled with height, in pixels, on return.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This will report the width and height, in pixels, of the space that the
/// specified string will take to fully render.
///
///
/// Text is wrapped to multiple lines on line endings and on word boundaries if
/// it extends beyond wrap_width in pixels.
///
///
/// If wrap_width is 0, this function will only wrap on newline characters.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetStringSizeWrapped(
TtfFont font,
string text,
nuint length,
int wrap_width,
int* w,
int* h
) => PInvoke.GetStringSizeWrapped(font, text, length, wrap_width, w, h) != 0;
///
/// Calculate how much of a UTF-8 string will fit in a given width.
///
/// the font to query.
/// text to calculate, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
///
/// maximum width, in pixels, available for the string, or 0
/// for unbounded width.
///
///
/// a pointer filled in with the width, in pixels, of the
/// string that will fit, may be NULL.
///
///
/// a pointer filled in with the length, in bytes, of
/// the string that will fit, may be NULL.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This reports the number of characters that can be rendered before reaching
/// max_width.
///
///
/// This does not need to render the string to do this calculation.
///
///
///
/// This function should be called on the thread that created the
/// font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool MeasureString(
TtfFont font,
string text,
nuint length,
int max_width,
int* measured_width,
nuint* measured_length
) => PInvoke.MeasureString(font, text, length, max_width, measured_width, measured_length) != 0;
///
/// Ergonomic wrapper over TTF_RenderText_Solid. Throws instead of returning a null pointer on failure.
///
/// the font to render with.
/// text to render, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the foreground color for the text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderTextSolid(TtfFont font, string text, nuint length, SdlColor fg)
{
SdlSurface* result = PInvoke.RenderTextSolid(font, text, length, fg);
if (result == null)
{
throw SdlException.FromError("TTF_RenderText_Solid failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderText_Solid_Wrapped. Throws instead of returning a null pointer on
/// failure.
///
/// the font to render with.
/// text to render, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the foreground color for the text.
///
/// the maximum width of the text surface or 0 to wrap on
/// newline characters.
///
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderTextSolidWrapped(
TtfFont font,
string text,
nuint length,
SdlColor fg,
int wrapLength
)
{
SdlSurface* result = PInvoke.RenderTextSolidWrapped(font, text, length, fg, wrapLength);
if (result == null)
{
throw SdlException.FromError("TTF_RenderText_Solid_Wrapped failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderGlyph_Solid. Throws instead of returning a null pointer on
/// failure.
///
/// the font to render with.
/// the character to render.
/// the foreground color for the text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderGlyphSolid(TtfFont font, uint ch, SdlColor fg)
{
SdlSurface* result = PInvoke.RenderGlyphSolid(font, ch, fg);
if (result == null)
{
throw SdlException.FromError("TTF_RenderGlyph_Solid failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderText_Shaded. Throws instead of returning a null pointer on
/// failure.
///
/// the font to render with.
/// text to render, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the foreground color for the text.
/// the background color for the text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderTextShaded(TtfFont font, string text, nuint length, SdlColor fg, SdlColor bg)
{
SdlSurface* result = PInvoke.RenderTextShaded(font, text, length, fg, bg);
if (result == null)
{
throw SdlException.FromError("TTF_RenderText_Shaded failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderText_Shaded_Wrapped. Throws instead of returning a null pointer on
/// failure.
///
/// the font to render with.
/// text to render, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the foreground color for the text.
/// the background color for the text.
///
/// the maximum width of the text surface or 0 to wrap on
/// newline characters.
///
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderTextShadedWrapped(
TtfFont font,
string text,
nuint length,
SdlColor fg,
SdlColor bg,
int wrap_width
)
{
SdlSurface* result = PInvoke.RenderTextShadedWrapped(font, text, length, fg, bg, wrap_width);
if (result == null)
{
throw SdlException.FromError("TTF_RenderText_Shaded_Wrapped failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderGlyph_Shaded. Throws instead of returning a null pointer on
/// failure.
///
/// the font to render with.
/// the codepoint to render.
/// the foreground color for the text.
/// the background color for the text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderGlyphShaded(TtfFont font, uint ch, SdlColor fg, SdlColor bg)
{
SdlSurface* result = PInvoke.RenderGlyphShaded(font, ch, fg, bg);
if (result == null)
{
throw SdlException.FromError("TTF_RenderGlyph_Shaded failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderText_Blended. Throws instead of returning a null pointer on
/// failure.
///
/// the font to render with.
/// text to render, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the foreground color for the text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderTextBlended(TtfFont font, string text, nuint length, SdlColor fg)
{
SdlSurface* result = PInvoke.RenderTextBlended(font, text, length, fg);
if (result == null)
{
throw SdlException.FromError("TTF_RenderText_Blended failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderText_Blended_Wrapped. Throws instead of returning a null pointer
/// on failure.
///
/// the font to render with.
/// text to render, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the foreground color for the text.
///
/// the maximum width of the text surface or 0 to wrap on
/// newline characters.
///
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderTextBlendedWrapped(
TtfFont font,
string text,
nuint length,
SdlColor fg,
int wrap_width
)
{
SdlSurface* result = PInvoke.RenderTextBlendedWrapped(font, text, length, fg, wrap_width);
if (result == null)
{
throw SdlException.FromError("TTF_RenderText_Blended_Wrapped failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderGlyph_Blended. Throws instead of returning a null pointer on
/// failure.
///
/// the font to render with.
/// the codepoint to render.
/// the foreground color for the text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderGlyphBlended(TtfFont font, uint ch, SdlColor fg)
{
SdlSurface* result = PInvoke.RenderGlyphBlended(font, ch, fg);
if (result == null)
{
throw SdlException.FromError("TTF_RenderGlyph_Blended failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderText_LCD. Throws instead of returning a null pointer on failure.
///
/// the font to render with.
/// text to render, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the foreground color for the text.
/// the background color for the text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderTextLCD(TtfFont font, string text, nuint length, SdlColor fg, SdlColor bg)
{
SdlSurface* result = PInvoke.RenderTextLCD(font, text, length, fg, bg);
if (result == null)
{
throw SdlException.FromError("TTF_RenderText_LCD failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderText_LCD_Wrapped. Throws instead of returning a null pointer on
/// failure.
///
/// the font to render with.
/// text to render, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// the foreground color for the text.
/// the background color for the text.
///
/// the maximum width of the text surface or 0 to wrap on
/// newline characters.
///
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderTextLCDWrapped(
TtfFont font,
string text,
nuint length,
SdlColor fg,
SdlColor bg,
int wrap_width
)
{
SdlSurface* result = PInvoke.RenderTextLCDWrapped(font, text, length, fg, bg, wrap_width);
if (result == null)
{
throw SdlException.FromError("TTF_RenderText_LCD_Wrapped failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_RenderGlyph_LCD. Throws instead of returning a null pointer on failure.
///
/// the font to render with.
/// the codepoint to render.
/// the foreground color for the text.
/// the background color for the text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static SdlSurface* RenderGlyphLCD(TtfFont font, uint ch, SdlColor fg, SdlColor bg)
{
SdlSurface* result = PInvoke.RenderGlyphLCD(font, ch, fg, bg);
if (result == null)
{
throw SdlException.FromError("TTF_RenderGlyph_LCD failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_CreateSurfaceTextEngine. Throws instead of returning a null pointer on
/// failure.
///
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfTextEngine* CreateSurfaceTextEngine()
{
TtfTextEngine* result = PInvoke.CreateSurfaceTextEngine();
if (result == null)
{
throw SdlException.FromError("TTF_CreateSurfaceTextEngine failed");
}
return result;
}
///
/// Draw text to an SDL surface.
///
/// the text to draw.
///
/// the x coordinate in pixels, positive from the left edge towards
/// the right.
///
///
/// the y coordinate in pixels, positive from the top edge towards the
/// bottom.
///
/// the surface to draw on.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// text must have been created using a TTF_TextEngine from
/// TTF_CreateSurfaceTextEngine().
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static bool DrawSurfaceText(TtfText* text, int x, int y, SdlSurface* surface) =>
PInvoke.DrawSurfaceText(text, x, y, surface) != 0;
///
/// Destroy a text engine created for drawing text on SDL surfaces.
///
///
/// a TTF_TextEngine object created with
/// TTF_CreateSurfaceTextEngine().
///
///
///
/// All text created by this engine should be destroyed before calling this
/// function.
///
///
///
/// This function should be called on the thread that created the
/// engine.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void DestroySurfaceTextEngine(TtfTextEngine* engine) => PInvoke.DestroySurfaceTextEngine(engine);
///
/// Ergonomic wrapper over TTF_CreateRendererTextEngine. Throws instead of returning a null pointer on
/// failure.
///
/// the renderer to use for creating textures and drawing text.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfTextEngine* CreateRendererTextEngine(SdlRenderer renderer)
{
TtfTextEngine* result = PInvoke.CreateRendererTextEngine(renderer);
if (result == null)
{
throw SdlException.FromError("TTF_CreateRendererTextEngine failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_CreateRendererTextEngineWithProperties. Throws instead of returning a
/// null pointer on failure.
///
/// the properties to use.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfTextEngine* CreateRendererTextEngineWithProperties(uint props)
{
TtfTextEngine* result = PInvoke.CreateRendererTextEngineWithProperties(props);
if (result == null)
{
throw SdlException.FromError("TTF_CreateRendererTextEngineWithProperties failed");
}
return result;
}
///
/// Draw text to an SDL renderer.
///
/// the text to draw.
///
/// the x coordinate in pixels, positive from the left edge towards
/// the right.
///
///
/// the y coordinate in pixels, positive from the top edge towards the
/// bottom.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// text must have been created using a TTF_TextEngine from
/// TTF_CreateRendererTextEngine(), and will draw using the renderer passed to
/// that function.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static bool DrawRendererText(TtfText* text, float x, float y) =>
PInvoke.DrawRendererText(text, x, y) != 0;
///
/// Destroy a text engine created for drawing text on an SDL renderer.
///
///
/// a TTF_TextEngine object created with
/// TTF_CreateRendererTextEngine().
///
///
///
/// All text created by this engine should be destroyed before calling this
/// function.
///
///
///
/// This function should be called on the thread that created the
/// engine.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void DestroyRendererTextEngine(TtfTextEngine* engine) =>
PInvoke.DestroyRendererTextEngine(engine);
///
/// Ergonomic wrapper over TTF_CreateGPUTextEngine. Throws instead of returning a null pointer on
/// failure.
///
///
/// the SDL_GPUDevice to use for creating textures and drawing
/// text.
///
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfTextEngine* CreateGpuTextEngine(SdlGpuDevice device)
{
TtfTextEngine* result = PInvoke.CreateGpuTextEngine(device);
if (result == null)
{
throw SdlException.FromError("TTF_CreateGPUTextEngine failed");
}
return result;
}
///
/// Ergonomic wrapper over TTF_CreateGPUTextEngineWithProperties. Throws instead of returning a null
/// pointer on failure.
///
/// the properties to use.
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfTextEngine* CreateGpuTextEngineWithProperties(uint props)
{
TtfTextEngine* result = PInvoke.CreateGpuTextEngineWithProperties(props);
if (result == null)
{
throw SdlException.FromError("TTF_CreateGPUTextEngineWithProperties failed");
}
return result;
}
///
/// Destroy a text engine created for drawing text with the SDL GPU API.
///
///
/// a TTF_TextEngine object created with
/// TTF_CreateGPUTextEngine().
///
///
///
/// All text created by this engine should be destroyed before calling this
/// function.
///
///
///
/// This function should be called on the thread that created the
/// engine.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void DestroyGpuTextEngine(TtfTextEngine* engine) => PInvoke.DestroyGpuTextEngine(engine);
///
/// Sets the winding order of the vertices returned by TTF_GetGPUTextDrawData
/// for a particular GPU text engine.
///
///
/// a TTF_TextEngine object created with
/// TTF_CreateGPUTextEngine().
///
/// the new winding order option.
///
/// This function should be called on the thread that created the
/// engine.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void SetGpuTextEngineWinding(TtfTextEngine* engine, TtfGpuTextEngineWinding winding) =>
PInvoke.SetGpuTextEngineWinding(engine, winding);
///
/// Get the winding order of the vertices returned by TTF_GetGPUTextDrawData
/// for a particular GPU text engine
///
///
/// a TTF_TextEngine object created with
/// TTF_CreateGPUTextEngine().
///
///
/// the winding order used by the GPU text engine or
/// TTF_GPU_TEXTENGINE_WINDING_INVALID in case of error.
///
///
/// This function should be called on the thread that created the
/// engine.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static TtfGpuTextEngineWinding GetGpuTextEngineWinding(TtfTextEngine* engine) =>
PInvoke.GetGpuTextEngineWinding(engine);
///
/// Ergonomic wrapper over TTF_CreateText. Throws instead of returning a null pointer on failure.
///
///
/// the text engine to use when creating the text object, may be
/// NULL.
///
/// the font to render with.
/// the text to use, in UTF-8 encoding.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
/// The created resource (never null); the caller owns it and is responsible for freeing it.
/// The SDL call failed; the message carries the SDL_GetError
/// text.
public static TtfText* CreateText(TtfTextEngine* engine, TtfFont font, string text, nuint length)
{
TtfText* result = PInvoke.CreateText(engine, font, text, length);
if (result == null)
{
throw SdlException.FromError("TTF_CreateText failed");
}
return result;
}
///
/// Get the properties associated with a text object.
///
/// the TTF_Text to query.
///
/// a valid property ID on success or 0 on failure; call
/// SDL_GetError() for more information.
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static uint GetTextProperties(TtfText* text) => PInvoke.GetTextProperties(text);
///
/// Set the text engine used by a text object.
///
/// the TTF_Text to modify.
/// the text engine to use for drawing.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetTextEngine(TtfText* text, TtfTextEngine* engine) =>
PInvoke.SetTextEngine(text, engine) != 0;
///
/// Set the font used by a text object.
///
/// the TTF_Text to modify.
/// the font to use, may be NULL.
///
/// false if the text pointer is null; otherwise, true. call
/// SDL_GetError() for more information.
///
///
///
/// When a text object has a font, any changes to the font will automatically
/// regenerate the text. If you set the font to NULL, the text will continue to
/// render but changes to the font will no longer affect the text.
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetTextFont(TtfText* text, TtfFont font) => PInvoke.SetTextFont(text, font) != 0;
///
/// Ergonomic wrapper over TTF_GetTextFont.
///
/// the TTF_Text to query.
///
/// Borrowed handle: the returned handle is owned by SDL (or by another object) and must not be
/// disposed. Do not call on it; doing so would free a resource this
/// call does not own. A null handle is returned on failure.
///
public static TtfFont GetTextFont(TtfText* text) => PInvoke.GetTextFont(text);
///
/// Set the direction to be used for text shaping a text object.
///
/// the text to modify.
/// the new direction for text to flow.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This function only supports left-to-right text shaping if SDL_ttf was not
/// built with HarfBuzz support.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool SetTextDirection(TtfText* text, TtfDirection direction) =>
PInvoke.SetTextDirection(text, direction) != 0;
///
/// Get the direction to be used for text shaping a text object.
///
/// the text to query.
/// the direction to be used for text shaping.
///
///
/// This defaults to the direction of the font used by the text object.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static TtfDirection GetTextDirection(TtfText* text) => PInvoke.GetTextDirection(text);
///
/// Set the script to be used for text shaping a text object.
///
/// the text to modify.
///
/// an
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
/// .
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This returns false if SDL_ttf isn't built with HarfBuzz support.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetTextScript(TtfText* text, uint script) => PInvoke.SetTextScript(text, script) != 0;
///
/// Get the script used for text shaping a text object.
///
/// the text to query.
///
/// an
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
/// or 0 if a script hasn't been set on either the text object or the
/// font.
///
///
///
/// This defaults to the script of the font used by the text object.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static uint GetTextScript(TtfText* text) => PInvoke.GetTextScript(text);
///
/// Set the color of a text object.
///
/// the TTF_Text to modify.
/// the red color value in the range of 0-255.
/// the green color value in the range of 0-255.
/// the blue color value in the range of 0-255.
/// the alpha value in the range of 0-255.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// The default text color is white (255, 255, 255, 255).
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static bool SetTextColor(TtfText* text, byte r, byte g, byte b, byte a) =>
PInvoke.SetTextColor(text, r, g, b, a) != 0;
///
/// Set the color of a text object.
///
/// the TTF_Text to modify.
/// the red color value, normally in the range of 0-1.
/// the green color value, normally in the range of 0-1.
/// the blue color value, normally in the range of 0-1.
/// the alpha value in the range of 0-1.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// The default text color is white (1.0f, 1.0f, 1.0f, 1.0f).
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static bool SetTextColorFloat(TtfText* text, float r, float g, float b, float a) =>
PInvoke.SetTextColorFloat(text, r, g, b, a) != 0;
///
/// Get the color of a text object.
///
/// the TTF_Text to query.
///
/// a pointer filled in with the red color value in the range of
/// 0-255, may be NULL.
///
///
/// a pointer filled in with the green color value in the range of
/// 0-255, may be NULL.
///
///
/// a pointer filled in with the blue color value in the range of
/// 0-255, may be NULL.
///
///
/// a pointer filled in with the alpha value in the range of 0-255,
/// may be NULL.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static bool GetTextColor(TtfText* text, out byte r, out byte g, out byte b, out byte a)
{
r = default;
g = default;
b = default;
a = default;
fixed (byte* rPtr = &r)
{
fixed (byte* gPtr = &g)
{
fixed (byte* bPtr = &b)
{
fixed (byte* aPtr = &a)
{
return PInvoke.GetTextColor(text, rPtr, gPtr, bPtr, aPtr) != 0;
}
}
}
}
}
///
/// Get the color of a text object.
///
/// the TTF_Text to query.
///
/// a pointer filled in with the red color value, normally in the
/// range of 0-1, may be NULL.
///
///
/// a pointer filled in with the green color value, normally in the
/// range of 0-1, may be NULL.
///
///
/// a pointer filled in with the blue color value, normally in the
/// range of 0-1, may be NULL.
///
///
/// a pointer filled in with the alpha value in the range of 0-1, may
/// be NULL.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static bool GetTextColorFloat(TtfText* text, out float r, out float g, out float b, out float a)
{
r = default;
g = default;
b = default;
a = default;
fixed (float* rPtr = &r)
{
fixed (float* gPtr = &g)
{
fixed (float* bPtr = &b)
{
fixed (float* aPtr = &a)
{
return PInvoke.GetTextColorFloat(text, rPtr, gPtr, bPtr, aPtr) != 0;
}
}
}
}
}
///
/// Set the position of a text object.
///
/// the TTF_Text to modify.
/// the x offset of the upper left corner of this text in pixels.
/// the y offset of the upper left corner of this text in pixels.
///
///
/// This can be used to position multiple text objects within a single wrapping
/// text area.
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetTextPosition(TtfText* text, int x, int y) => PInvoke.SetTextPosition(text, x, y) != 0;
///
/// Get the position of a text object.
///
/// the TTF_Text to query.
///
/// a pointer filled in with the x offset of the upper left corner of
/// this text in pixels, may be NULL.
///
///
/// a pointer filled in with the y offset of the upper left corner of
/// this text in pixels, may be NULL.
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool GetTextPosition(TtfText* text, out int x, out int y)
{
x = default;
y = default;
fixed (int* xPtr = &x)
{
fixed (int* yPtr = &y)
{
return PInvoke.GetTextPosition(text, xPtr, yPtr) != 0;
}
}
}
///
/// Set whether wrapping is enabled on a text object.
///
/// the TTF_Text to modify.
///
/// the maximum width in pixels, 0 to wrap on newline
/// characters.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetTextWrapWidth(TtfText* text, int wrap_width) =>
PInvoke.SetTextWrapWidth(text, wrap_width) != 0;
///
/// Get whether wrapping is enabled on a text object.
///
/// the TTF_Text to query.
///
/// a pointer filled in with the maximum width in pixels or 0
/// if the text is being wrapped on newline characters.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool GetTextWrapWidth(TtfText* text, out int wrap_width)
{
wrap_width = default;
fixed (int* wrap_widthPtr = &wrap_width)
{
return PInvoke.GetTextWrapWidth(text, wrap_widthPtr) != 0;
}
}
///
/// Set whether whitespace should be visible when wrapping a text object.
///
/// the TTF_Text to modify.
///
/// true to show whitespace when wrapping text, false to hide
/// it.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// If the whitespace is visible, it will take up space for purposes of
/// alignment and wrapping. This is good for editing, but looks better when
/// centered or aligned if whitespace around line wrapping is hidden. This
/// defaults false.
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool SetTextWrapWhitespaceVisible(TtfText* text, bool visible) =>
PInvoke.SetTextWrapWhitespaceVisible(text, visible ? (byte)1 : (byte)0) != 0;
///
/// Return whether whitespace is shown when wrapping a text object.
///
/// the TTF_Text to query.
///
/// true if whitespace is shown when wrapping text, or false
/// otherwise.
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static bool TextWrapWhitespaceVisible(TtfText* text) => PInvoke.TextWrapWhitespaceVisible(text) != 0;
///
/// Set the UTF-8 text used by a text object.
///
/// the TTF_Text to modify.
/// the UTF-8 text to use, may be NULL.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
///
public static bool SetTextString(TtfText* text, string @string, nuint length) =>
PInvoke.SetTextString(text, @string, length) != 0;
///
/// Insert UTF-8 text into a text object.
///
/// the TTF_Text to modify.
///
/// the offset, in bytes, from the beginning of the string if >=
/// 0, the offset from the end of the string if < 0. Note that
/// this does not do UTF-8 validation, so you should only insert
/// at UTF-8 sequence boundaries.
///
/// the UTF-8 text to insert.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
///
public static bool InsertTextString(TtfText* text, int offset, string @string, nuint length) =>
PInvoke.InsertTextString(text, offset, @string, length) != 0;
///
/// Append UTF-8 text to a text object.
///
/// the TTF_Text to modify.
/// the UTF-8 text to insert.
///
/// the length of the text, in bytes, or 0 for null terminated
/// text.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
///
public static bool AppendTextString(TtfText* text, string @string, nuint length) =>
PInvoke.AppendTextString(text, @string, length) != 0;
///
/// Delete UTF-8 text from a text object.
///
/// the TTF_Text to modify.
///
/// the offset, in bytes, from the beginning of the string if >=
/// 0, the offset from the end of the string if < 0. Note that
/// this does not do UTF-8 validation, so you should only delete
/// at UTF-8 sequence boundaries.
///
///
/// the length of text to delete, in bytes, or -1 for the
/// remainder of the string.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This function may cause the internal text representation to be rebuilt.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
///
public static bool DeleteTextString(TtfText* text, int offset, int length) =>
PInvoke.DeleteTextString(text, offset, length) != 0;
///
/// Get the size of a text object.
///
/// the TTF_Text to query.
///
/// a pointer filled in with the width of the text, in pixels, may be
/// NULL.
///
///
/// a pointer filled in with the height of the text, in pixels, may be
/// NULL.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// The size of the text may change when the font or font style and size
/// change.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetTextSize(TtfText* text, out int w, out int h)
{
w = default;
h = default;
fixed (int* wPtr = &w)
{
fixed (int* hPtr = &h)
{
return PInvoke.GetTextSize(text, wPtr, hPtr) != 0;
}
}
}
///
/// Get the substring of a text object that surrounds a text offset.
///
/// the TTF_Text to query.
/// a byte offset into the text string.
///
/// a pointer filled in with the substring containing the
/// offset.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// If offset is less than 0, this will return a zero length substring at the
/// beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If
/// offset is greater than or equal to the length of the text string, this
/// will return a zero length substring at the end of the text with the
/// TTF_SUBSTRING_TEXT_END flag set.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetTextSubString(TtfText* text, int offset, TtfSubString* substring) =>
PInvoke.GetTextSubString(text, offset, substring) != 0;
///
/// Get the substring of a text object that contains the given line.
///
/// the TTF_Text to query.
/// a zero-based line index, in the range [0 .. text->num_lines-1].
///
/// a pointer filled in with the substring containing the
/// offset.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// If line is less than 0, this will return a zero length substring at the
/// beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If line
/// is greater than or equal to text->num_lines this will return a zero
/// length substring at the end of the text with the TTF_SUBSTRING_TEXT_END
/// flag set.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetTextSubStringForLine(TtfText* text, int line, TtfSubString* substring) =>
PInvoke.GetTextSubStringForLine(text, line, substring) != 0;
///
/// Ergonomic wrapper over TTF_GetTextSubStringsForRange.
///
/// the TTF_Text to query.
/// a byte offset into the text string.
///
/// the length of the range being queried, in bytes, or -1 for
/// the remainder of the string.
///
/// The SDL call failed; the message carries the SDL_GetError
/// text.
///
/// SDL returns a freshly SDL_malloc'd buffer for this call; the returned array is a managed copy, and
/// the native buffer is freed with SDL_free before this method returns.
///
public static TtfSubString[] GetTextSubStringsForRange(TtfText* text, int offset, int length)
{
int count;
var ptr = PInvoke.GetTextSubStringsForRange(text, offset, length, &count);
if (ptr is null)
throw SdlException.FromError("TTF_GetTextSubStringsForRange failed");
try
{
var result = new TtfSubString[count];
for (var i = 0; i < count; i++)
result[i] = *ptr[i];
return result;
}
finally
{
Sdl.PInvoke.Free(ptr);
}
}
///
/// Get the portion of a text string that is closest to a point.
///
/// the TTF_Text to query.
///
/// the x coordinate relative to the left side of the text, may be
/// outside the bounds of the text area.
///
///
/// the y coordinate relative to the top side of the text, may be
/// outside the bounds of the text area.
///
///
/// a pointer filled in with the closest substring of text to
/// the given point.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This will return the closest substring of text to the given point.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetTextSubStringForPoint(TtfText* text, int x, int y, TtfSubString* substring) =>
PInvoke.GetTextSubStringForPoint(text, x, y, substring) != 0;
///
/// Get the previous substring in a text object
///
/// the TTF_Text to query.
/// the TTF_SubString to query.
///
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// If called at the start of the text, this will return a zero length
/// substring with the TTF_SUBSTRING_TEXT_START flag set.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetPreviousTextSubString(TtfText* text, TtfSubString* substring, TtfSubString* previous) =>
PInvoke.GetPreviousTextSubString(text, substring, previous) != 0;
///
/// Get the next substring in a text object
///
/// the TTF_Text to query.
/// the TTF_SubString to query.
/// a pointer filled in with the next substring.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// If called at the end of the text, this will return a zero length substring
/// with the TTF_SUBSTRING_TEXT_END flag set.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool GetNextTextSubString(TtfText* text, TtfSubString* substring, TtfSubString* next) =>
PInvoke.GetNextTextSubString(text, substring, next) != 0;
///
/// Update the layout of a text object.
///
/// the TTF_Text to update.
///
/// true on success or false on failure; call SDL_GetError() for more
/// information.
///
///
///
/// This is automatically done when the layout is requested or the text is
/// rendered, but you can call this if you need more control over the timing of
/// when the layout and text engine representation are updated.
///
///
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static bool UpdateText(TtfText* text) => PInvoke.UpdateText(text) != 0;
///
/// Destroy a text object created by a text engine.
///
/// the text to destroy.
///
/// This function should be called on the thread that created the
/// text.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
public static void DestroyText(TtfText* text) => PInvoke.DestroyText(text);
///
/// Dispose of a previously-created font.
///
/// the font to dispose of.
///
///
/// Call this when done with a font. This function will free any resources
/// associated with it. It is safe to call this function on NULL, for example
/// on the result of a failed call to TTF_OpenFont().
///
///
/// The font is not valid after being passed to this function. String pointers
/// from functions that return information on this font, such as
/// TTF_GetFontFamilyName() and TTF_GetFontStyleName(), are no longer valid
/// after this call, as well.
///
///
///
/// This function should not be called while any other thread is
/// using the font.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static void CloseFont(TtfFont font) => PInvoke.CloseFont(font);
///
/// Deinitialize SDL_ttf.
///
///
///
/// You must call this when done with the library, to free internal resources.
/// It is safe to call this when the library isn't initialized, as it will just
/// return immediately.
///
///
/// Once you have as many quit calls as you have had successful calls to
/// TTF_Init, the library will actually deinitialize.
///
///
/// Please note that this does not automatically close any fonts that are still
/// open at the time of deinitialization, and it is possibly not safe to close
/// them afterwards, as parts of the library will no longer be initialized to
/// deal with it. A well-written program should call TTF_CloseFont() on any
/// open fonts before calling this function!
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
public static void Quit() => PInvoke.Quit();
///
/// Check if SDL_ttf is initialized.
///
///
/// the current number of initialization calls, that need to
/// eventually be paired with this many calls to TTF_Quit().
///
///
///
/// This reports the number of times the library has been initialized by a call
/// to TTF_Init(), without a paired deinitialization request from TTF_Quit().
///
///
/// In short: if it's greater than zero, the library is currently initialized
/// and ready to work. If zero, it is not initialized.
///
///
/// Despite the return value being a signed integer, this function should not
/// return a negative number.
///
///
///
/// It is safe to call this function from any thread.
///
///
/// This function is available since SDL_ttf 3.0.0.
///
///
///
public static int WasInit() => PInvoke.WasInit();
}
}