SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_ttf.h
1#ifndef SDL3PP_TTF_H_
2#define SDL3PP_TTF_H_
3
4#include "SDL3pp_gpu.h"
5#include "SDL3pp_render.h"
6#include "SDL3pp_surface.h"
7#include "SDL3pp_version.h"
8#include "SDL3pp_video.h"
9
10#if defined(SDL3PP_ENABLE_TTF) || defined(SDL3PP_DOC)
11
12#include <SDL3_ttf/SDL_ttf.h>
13
14namespace SDL {
15
26
27// Forward decl
28struct Font;
29
31using FontRaw = TTF_Font*;
32
39
40// Forward decl
41struct TextEngine;
42
44using TextEngineRaw = TTF_TextEngine*;
45
52
53// Forward decl
54struct Text;
55
57using TextRaw = TTF_Text*;
58
60using TextRawConst = const TTF_Text*;
61
68
71
72#ifdef SDL3PP_DOC
73
79#define SDL_TTF_MAJOR_VERSION
80
81#define SDL_TTF_MINOR_VERSION
82
83#define SDL_TTF_MICRO_VERSION
84
86
90#define SDL_TTF_VERSION \
91 SDL_VERSIONNUM( \
92 SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION)
93
97#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \
98 ((SDL_TTF_MAJOR_VERSION >= X) && \
99 (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \
100 (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || \
101 SDL_TTF_MICRO_VERSION >= Z))
102
103#endif // SDL3PP_DOC
104
105namespace TTF {
106
116inline int Version() { return TTF_Version(); }
117
133inline void Init() { CheckError(TTF_Init()); }
134
155inline void Quit() { TTF_Quit(); }
156
179inline int WasInit() { return TTF_WasInit(); }
180
181} // namespace TTF
182
198inline void GetFreeTypeVersion(int* major, int* minor, int* patch)
199{
200 TTF_GetFreeTypeVersion(major, minor, patch);
201}
202
216inline void GetHarfBuzzVersion(int* major, int* minor, int* patch)
217{
218 TTF_GetHarfBuzzVersion(major, minor, patch);
219}
220
234
235constexpr FontStyleFlags STYLE_NORMAL = TTF_STYLE_NORMAL;
236
237constexpr FontStyleFlags STYLE_BOLD = TTF_STYLE_BOLD;
238
239constexpr FontStyleFlags STYLE_ITALIC = TTF_STYLE_ITALIC;
240
242 TTF_STYLE_UNDERLINE;
243
245 TTF_STYLE_STRIKETHROUGH;
246
259using HintingFlags = TTF_HintingFlags;
260
261#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
262
263constexpr HintingFlags HINTING_INVALID = TTF_HINTING_INVALID;
264
265#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
266
268 TTF_HINTING_NORMAL;
269
271constexpr HintingFlags HINTING_LIGHT = TTF_HINTING_LIGHT;
272
277constexpr HintingFlags HINTING_MONO = TTF_HINTING_MONO;
278
280constexpr HintingFlags HINTING_NONE = TTF_HINTING_NONE;
281
283constexpr HintingFlags HINTING_LIGHT_SUBPIXEL = TTF_HINTING_LIGHT_SUBPIXEL;
284
290using HorizontalAlignment = TTF_HorizontalAlignment;
291
293 TTF_HORIZONTAL_ALIGN_INVALID;
294
296 TTF_HORIZONTAL_ALIGN_LEFT;
297
299 TTF_HORIZONTAL_ALIGN_CENTER;
300
302 TTF_HORIZONTAL_ALIGN_RIGHT;
303
315using Direction = TTF_Direction;
316
317constexpr Direction DIRECTION_INVALID = TTF_DIRECTION_INVALID;
318
319constexpr Direction DIRECTION_LTR = TTF_DIRECTION_LTR;
320
321constexpr Direction DIRECTION_RTL = TTF_DIRECTION_RTL;
322
323constexpr Direction DIRECTION_TTB = TTF_DIRECTION_TTB;
324
325constexpr Direction DIRECTION_BTT = TTF_DIRECTION_BTT;
326
332using ImageType = TTF_ImageType;
333
334constexpr ImageType IMAGE_INVALID = TTF_IMAGE_INVALID;
335
337 TTF_IMAGE_ALPHA;
338
340 TTF_IMAGE_COLOR;
341
343constexpr ImageType IMAGE_SDF = TTF_IMAGE_SDF;
344
352struct Font : ResourceBase<FontRaw>
353{
355
363 constexpr explicit Font(FontRaw resource) noexcept
364 : ResourceBase(resource)
365 {
366 }
367
369 constexpr Font(const Font& other) = delete;
370
372 constexpr Font(Font&& other) noexcept
373 : Font(other.release())
374 {
375 }
376
377 constexpr Font(const FontRef& other) = delete;
378
379 constexpr Font(FontRef&& other) = delete;
380
399 Font(StringParam file, float ptsize);
400
424 Font(IOStreamRef src, float ptsize, bool closeio = false);
425
468 Font(PropertiesRef props);
469
471 ~Font() { TTF_CloseFont(get()); }
472
474 constexpr Font& operator=(Font&& other) noexcept
475 {
476 swap(*this, other);
477 return *this;
478 }
479
481 Font& operator=(const Font& other) = delete;
482
503 void Close();
504
521 Font Copy() const;
522
543
558 Uint32 GetGeneration() const;
559
581 void AddFallback(FontRef fallback);
582
598 void RemoveFallback(FontRef fallback);
599
613 void ClearFallbacks();
614
631 void SetSize(float ptsize);
632
652 void SetSizeDPI(float ptsize, int hdpi, int vdpi);
653
668 float GetSize() const;
669
684 void GetDPI(int* hdpi, int* vdpi) const;
685
709 void SetStyle(FontStyleFlags style);
710
730 FontStyleFlags GetStyle() const;
731
752 void SetOutline(int outline);
753
765 int GetOutline() const;
766
790 void SetHinting(HintingFlags hinting);
791
801 int GetNumFaces() const;
802
823 HintingFlags GetHinting() const;
824
847 void SetSDF(bool enabled);
848
860 bool GetSDF() const;
861
862#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
863
874 int GetWeight() const;
875
876#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
877
893
906
918 int GetHeight() const;
919
931 int GetAscent() const;
932
944 int GetDescent() const;
945
960 void SetLineSkip(int lineskip);
961
973 int GetLineSkip() const;
974
994 void SetKerning(bool enabled);
995
1007 bool GetKerning() const;
1008
1024 bool IsFixedWidth() const;
1025
1039 bool IsScalable() const;
1040
1056 const char* GetFamilyName() const;
1057
1073 const char* GetStyleName() const;
1074
1091 void SetDirection(Direction direction);
1092
1105 Direction GetDirection() const;
1106
1125 void SetScript(Uint32 script);
1126
1141 Uint32 GetScript() const;
1142
1158 static Uint32 GetGlyphScript(Uint32 ch);
1159
1177 void SetLanguage(StringParam language_bcp47);
1178
1190 bool HasGlyph(Uint32 ch) const;
1191
1206 Surface GetGlyphImage(Uint32 ch, ImageType* image_type) const;
1207
1226 ImageType* image_type) const;
1227
1255 void GetGlyphMetrics(Uint32 ch,
1256 int* minx,
1257 int* maxx,
1258 int* miny,
1259 int* maxy,
1260 int* advance) const;
1261
1275 int GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const;
1276
1292 Point GetStringSize(std::string_view text) const
1293 {
1294 Point p;
1295 GetStringSize(text, &p.x, &p.y);
1296 return p;
1297 }
1298
1315 void GetStringSize(std::string_view text, int* w, int* h) const;
1316
1338 Point GetStringSizeWrapped(std::string_view text, int wrap_width) const
1339 {
1340 Point p;
1341 GetStringSizeWrapped(text, wrap_width, &p.x, &p.y);
1342 return p;
1343 }
1344
1367 void GetStringSizeWrapped(std::string_view text,
1368 int wrap_width,
1369 int* w,
1370 int* h) const;
1371
1394 void MeasureString(std::string_view text,
1395 int max_width,
1396 int* measured_width,
1397 size_t* measured_length) const;
1398
1431 Surface RenderText_Solid(std::string_view text, Color fg) const;
1432
1464 Surface RenderText_Solid_Wrapped(std::string_view text,
1465 Color fg,
1466 int wrapLength) const;
1467
1495
1529 Surface RenderText_Shaded(std::string_view text, Color fg, Color bg) const;
1530
1564 Surface RenderText_Shaded_Wrapped(std::string_view text,
1565 Color fg,
1566 Color bg,
1567 int wrap_width) const;
1568
1598
1630 Surface RenderText_Blended(std::string_view text, Color fg) const;
1631
1663 Surface RenderText_Blended_Wrapped(std::string_view text,
1664 Color fg,
1665 int wrap_width) const;
1666
1694
1727 Surface RenderText_LCD(std::string_view text, Color fg, Color bg) const;
1728
1762 Surface RenderText_LCD_Wrapped(std::string_view text,
1763 Color fg,
1764 Color bg,
1765 int wrap_width) const;
1766
1796};
1797
1818inline Font OpenFont(StringParam file, float ptsize)
1819{
1820 return Font(std::move(file), ptsize);
1821}
1822
1823inline Font::Font(StringParam file, float ptsize)
1824 : Font(CheckError(TTF_OpenFont(file, ptsize)))
1825{
1826}
1827
1828inline Font::Font(IOStreamRef src, float ptsize, bool closeio)
1829 : Font(CheckError(TTF_OpenFontIO(src, closeio, ptsize)))
1830{
1831}
1832
1834 : Font(CheckError(TTF_OpenFontWithProperties(props)))
1835{
1836}
1837
1863inline Font OpenFontIO(IOStreamRef src, float ptsize, bool closeio = false)
1864{
1865 return Font(src, ptsize, closeio);
1866}
1867
1910inline Font OpenFontWithProperties(PropertiesRef props) { return Font(props); }
1911
1918
1919constexpr auto FILENAME_STRING =
1920 TTF_PROP_FONT_CREATE_FILENAME_STRING;
1921
1922constexpr auto IOSTREAM_POINTER =
1923 TTF_PROP_FONT_CREATE_IOSTREAM_POINTER;
1924
1926 TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER;
1927
1929 TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN;
1931
1932constexpr auto SIZE_FLOAT =
1933 TTF_PROP_FONT_CREATE_SIZE_FLOAT;
1934
1935constexpr auto FACE_NUMBER =
1936 TTF_PROP_FONT_CREATE_FACE_NUMBER;
1937
1939 TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER;
1940
1941constexpr auto VERTICAL_DPI_NUMBER =
1942 TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER;
1943
1944#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
1945
1947 TTF_PROP_FONT_CREATE_EXISTING_FONT;
1948
1949#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
1950
1951} // namespace prop::Font::Create
1952
1972inline Font CopyFont(FontRef existing_font)
1973{
1974 return Font(CheckError(TTF_CopyFont(existing_font)));
1975}
1976
1977inline Font Font::Copy() const { return SDL::CopyFont(get()); }
1978
2000{
2001 return CheckError(TTF_GetFontProperties(font));
2002}
2003
2008
2019namespace prop::Font {
2020
2022 TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER;
2023
2025 TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER;
2026
2028 TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER;
2029
2030} // namespace prop::Font
2031
2048{
2049 return TTF_GetFontGeneration(font);
2050}
2051
2053{
2054 return SDL::GetFontGeneration(get());
2055}
2056
2079inline void AddFallbackFont(FontRef font, FontRef fallback)
2080{
2081 CheckError(TTF_AddFallbackFont(font, fallback));
2082}
2083
2084inline void Font::AddFallback(FontRef fallback)
2085{
2086 SDL::AddFallbackFont(get(), fallback);
2087}
2088
2105inline void RemoveFallbackFont(FontRef font, FontRef fallback)
2106{
2107 TTF_RemoveFallbackFont(font, fallback);
2108}
2109
2110inline void Font::RemoveFallback(FontRef fallback)
2111{
2112 SDL::RemoveFallbackFont(get(), fallback);
2113}
2114
2130inline void ClearFallbackFonts(FontRef font) { TTF_ClearFallbackFonts(font); }
2131
2133
2151inline void SetFontSize(FontRef font, float ptsize)
2152{
2153 CheckError(TTF_SetFontSize(font, ptsize));
2154}
2155
2156inline void Font::SetSize(float ptsize) { SDL::SetFontSize(get(), ptsize); }
2157
2178inline void SetFontSizeDPI(FontRef font, float ptsize, int hdpi, int vdpi)
2179{
2180 CheckError(TTF_SetFontSizeDPI(font, ptsize, hdpi, vdpi));
2181}
2182
2183inline void Font::SetSizeDPI(float ptsize, int hdpi, int vdpi)
2184{
2185 SDL::SetFontSizeDPI(get(), ptsize, hdpi, vdpi);
2186}
2187
2203inline float GetFontSize(FontRef font) { return TTF_GetFontSize(font); }
2204
2205inline float Font::GetSize() const { return SDL::GetFontSize(get()); }
2206
2222inline void GetFontDPI(FontRef font, int* hdpi, int* vdpi)
2223{
2224 CheckError(TTF_GetFontDPI(font, hdpi, vdpi));
2225}
2226
2227inline void Font::GetDPI(int* hdpi, int* vdpi) const
2228{
2229 SDL::GetFontDPI(get(), hdpi, vdpi);
2230}
2231
2256inline void SetFontStyle(FontRef font, FontStyleFlags style)
2257{
2258 TTF_SetFontStyle(font, style);
2259}
2260
2262{
2263 SDL::SetFontStyle(get(), style);
2264}
2265
2287{
2288 return TTF_GetFontStyle(font);
2289}
2290
2292{
2293 return SDL::GetFontStyle(get());
2294}
2295
2317inline void SetFontOutline(FontRef font, int outline)
2318{
2319 CheckError(TTF_SetFontOutline(font, outline));
2320}
2321
2322inline void Font::SetOutline(int outline)
2323{
2324 SDL::SetFontOutline(get(), outline);
2325}
2326
2339inline int GetFontOutline(FontRef font) { return TTF_GetFontOutline(font); }
2340
2341inline int Font::GetOutline() const { return SDL::GetFontOutline(get()); }
2342
2367inline void SetFontHinting(FontRef font, HintingFlags hinting)
2368{
2369 TTF_SetFontHinting(font, hinting);
2370}
2371
2372inline void Font::SetHinting(HintingFlags hinting)
2373{
2374 SDL::SetFontHinting(get(), hinting);
2375}
2376
2387inline int GetNumFontFaces(FontRef font) { return TTF_GetNumFontFaces(font); }
2388
2389inline int Font::GetNumFaces() const { return SDL::GetNumFontFaces(get()); }
2390
2413{
2414 return TTF_GetFontHinting(font);
2415}
2416
2418{
2419 return SDL::GetFontHinting(get());
2420}
2421
2445inline void SetFontSDF(FontRef font, bool enabled)
2446{
2447 CheckError(TTF_SetFontSDF(font, enabled));
2448}
2449
2450inline void Font::SetSDF(bool enabled) { SDL::SetFontSDF(get(), enabled); }
2451
2464inline bool GetFontSDF(FontRef font) { return TTF_GetFontSDF(font); }
2465
2466inline bool Font::GetSDF() const { return SDL::GetFontSDF(get()); }
2467
2468#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
2469
2481inline int GetFontWeight(FontRef font) { return TTF_GetFontWeight(font); }
2482
2483inline int Font::GetWeight() const { return SDL::GetFontWeight(get()); }
2484
2485constexpr int FONT_WEIGHT_THIN =
2486 TTF_FONT_WEIGHT_THIN;
2487
2489 TTF_FONT_WEIGHT_EXTRA_LIGHT;
2490
2491constexpr int FONT_WEIGHT_LIGHT =
2492 TTF_FONT_WEIGHT_LIGHT;
2493
2494constexpr int FONT_WEIGHT_NORMAL =
2495 TTF_FONT_WEIGHT_NORMAL;
2496
2497constexpr int FONT_WEIGHT_MEDIUM =
2498 TTF_FONT_WEIGHT_MEDIUM;
2499
2501 TTF_FONT_WEIGHT_SEMI_BOLD;
2502
2503constexpr int FONT_WEIGHT_BOLD =
2504 TTF_FONT_WEIGHT_BOLD;
2505
2507 TTF_FONT_WEIGHT_EXTRA_BOLD;
2508
2509constexpr int FONT_WEIGHT_BLACK =
2510 TTF_FONT_WEIGHT_BLACK;
2511
2513 TTF_FONT_WEIGHT_EXTRA_BLACK;
2514
2515#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
2516
2533{
2534 TTF_SetFontWrapAlignment(font, align);
2535}
2536
2538{
2540}
2541
2555{
2556 return TTF_GetFontWrapAlignment(font);
2557}
2558
2563
2576inline int GetFontHeight(FontRef font) { return TTF_GetFontHeight(font); }
2577
2578inline int Font::GetHeight() const { return SDL::GetFontHeight(get()); }
2579
2592inline int GetFontAscent(FontRef font) { return TTF_GetFontAscent(font); }
2593
2594inline int Font::GetAscent() const { return SDL::GetFontAscent(get()); }
2595
2608inline int GetFontDescent(FontRef font) { return TTF_GetFontDescent(font); }
2609
2610inline int Font::GetDescent() const { return SDL::GetFontDescent(get()); }
2611
2627inline void SetFontLineSkip(FontRef font, int lineskip)
2628{
2629 TTF_SetFontLineSkip(font, lineskip);
2630}
2631
2632inline void Font::SetLineSkip(int lineskip)
2633{
2634 SDL::SetFontLineSkip(get(), lineskip);
2635}
2636
2649inline int GetFontLineSkip(FontRef font) { return TTF_GetFontLineSkip(font); }
2650
2651inline int Font::GetLineSkip() const { return SDL::GetFontLineSkip(get()); }
2652
2673inline void SetFontKerning(FontRef font, bool enabled)
2674{
2675 TTF_SetFontKerning(font, enabled);
2676}
2677
2678inline void Font::SetKerning(bool enabled)
2679{
2680 SDL::SetFontKerning(get(), enabled);
2681}
2682
2695inline bool GetFontKerning(FontRef font) { return TTF_GetFontKerning(font); }
2696
2697inline bool Font::GetKerning() const { return SDL::GetFontKerning(get()); }
2698
2715inline bool FontIsFixedWidth(FontRef font)
2716{
2717 return TTF_FontIsFixedWidth(font);
2718}
2719
2720inline bool Font::IsFixedWidth() const { return SDL::FontIsFixedWidth(get()); }
2721
2736inline bool FontIsScalable(FontRef font) { return TTF_FontIsScalable(font); }
2737
2738inline bool Font::IsScalable() const { return SDL::FontIsScalable(get()); }
2739
2756inline const char* GetFontFamilyName(FontRef font)
2757{
2758 return TTF_GetFontFamilyName(font);
2759}
2760
2761inline const char* Font::GetFamilyName() const
2762{
2763 return SDL::GetFontFamilyName(get());
2764}
2765
2782inline const char* GetFontStyleName(FontRef font)
2783{
2784 return TTF_GetFontStyleName(font);
2785}
2786
2787inline const char* Font::GetStyleName() const
2788{
2789 return SDL::GetFontStyleName(get());
2790}
2791
2809inline void SetFontDirection(FontRef font, Direction direction)
2810{
2811 CheckError(TTF_SetFontDirection(font, direction));
2812}
2813
2814inline void Font::SetDirection(Direction direction)
2815{
2816 SDL::SetFontDirection(get(), direction);
2817}
2818
2833{
2834 return TTF_GetFontDirection(font);
2835}
2836
2838{
2839 return SDL::GetFontDirection(get());
2840}
2841
2855{
2856 return TTF_StringToTag(string);
2857}
2858
2874inline void TagToString(Uint32 tag, char* string, size_t size)
2875{
2876 TTF_TagToString(tag, string, size);
2877}
2878
2898inline void SetFontScript(FontRef font, Uint32 script)
2899{
2900 CheckError(TTF_SetFontScript(font, script));
2901}
2902
2903inline void Font::SetScript(Uint32 script)
2904{
2905 SDL::SetFontScript(get(), script);
2906}
2907
2923inline Uint32 GetFontScript(FontRef font) { return TTF_GetFontScript(font); }
2924
2925inline Uint32 Font::GetScript() const { return SDL::GetFontScript(get()); }
2926
2942{
2943 return CheckError(TTF_GetGlyphScript(ch));
2944}
2945
2947{
2948 return SDL::GetGlyphScript(ch);
2949}
2950
2968inline void SetFontLanguage(FontRef font, StringParam language_bcp47)
2969{
2970 CheckError(TTF_SetFontLanguage(font, language_bcp47));
2971}
2972
2973inline void Font::SetLanguage(StringParam language_bcp47)
2974{
2975 SDL::SetFontLanguage(get(), std::move(language_bcp47));
2976}
2977
2990inline bool FontHasGlyph(FontRef font, Uint32 ch)
2991{
2992 return TTF_FontHasGlyph(font, ch);
2993}
2994
2995inline bool Font::HasGlyph(Uint32 ch) const
2996{
2997 return SDL::FontHasGlyph(get(), ch);
2998}
2999
3015inline Surface GetGlyphImage(FontRef font, Uint32 ch, ImageType* image_type)
3016{
3017 return Surface{CheckError(TTF_GetGlyphImage(font, ch, image_type))};
3018}
3019
3020inline Surface Font::GetGlyphImage(Uint32 ch, ImageType* image_type) const
3021{
3022 return SDL::GetGlyphImage(get(), ch, image_type);
3023}
3024
3044 Uint32 glyph_index,
3045 ImageType* image_type)
3046{
3047 return Surface(
3048 CheckError(TTF_GetGlyphImageForIndex(font, glyph_index, image_type)));
3049}
3050
3052 ImageType* image_type) const
3053{
3054 return SDL::GetGlyphImageForIndex(get(), glyph_index, image_type);
3055}
3056
3085inline void GetGlyphMetrics(FontRef font,
3086 Uint32 ch,
3087 int* minx,
3088 int* maxx,
3089 int* miny,
3090 int* maxy,
3091 int* advance)
3092{
3093 CheckError(TTF_GetGlyphMetrics(font, ch, minx, maxx, miny, maxy, advance));
3094}
3095
3097 int* minx,
3098 int* maxx,
3099 int* miny,
3100 int* maxy,
3101 int* advance) const
3102{
3103 SDL::GetGlyphMetrics(get(), ch, minx, maxx, miny, maxy, advance);
3104}
3105
3120inline int GetGlyphKerning(FontRef font, Uint32 previous_ch, Uint32 ch)
3121{
3122 if (int r; TTF_GetGlyphKerning(font, previous_ch, ch, &r)) return r;
3123 throw Error();
3124}
3125
3126inline int Font::GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const
3127{
3128 return SDL::GetGlyphKerning(get(), previous_ch, ch);
3129}
3130
3148inline void GetStringSize(FontRef font, std::string_view text, int* w, int* h)
3149{
3150 CheckError(TTF_GetStringSize(font, text.data(), text.size(), w, h));
3151}
3152
3153inline void Font::GetStringSize(std::string_view text, int* w, int* h) const
3154{
3155 SDL::GetStringSize(get(), text, w, h);
3156}
3157
3182 std::string_view text,
3183 int wrap_width,
3184 int* w,
3185 int* h)
3186{
3187 CheckError(
3188 TTF_GetStringSizeWrapped(font, text.data(), text.size(), wrap_width, w, h));
3189}
3190
3191inline void Font::GetStringSizeWrapped(std::string_view text,
3192 int wrap_width,
3193 int* w,
3194 int* h) const
3195{
3196 SDL::GetStringSizeWrapped(get(), text, wrap_width, w, h);
3197}
3198
3222inline void MeasureString(FontRef font,
3223 std::string_view text,
3224 int max_width,
3225 int* measured_width,
3226 size_t* measured_length)
3227{
3228 CheckError(TTF_MeasureString(font,
3229 text.data(),
3230 text.size(),
3231 max_width,
3232 measured_width,
3233 measured_length));
3234}
3235
3236inline void Font::MeasureString(std::string_view text,
3237 int max_width,
3238 int* measured_width,
3239 size_t* measured_length) const
3240{
3241 SDL::MeasureString(get(), text, max_width, measured_width, measured_length);
3242}
3243
3277inline Surface RenderText_Solid(FontRef font, std::string_view text, Color fg)
3278{
3279 return Surface{TTF_RenderText_Solid(font, text.data(), text.size(), fg)};
3280}
3281
3282inline Surface Font::RenderText_Solid(std::string_view text, Color fg) const
3283{
3284 return SDL::RenderText_Solid(get(), text, fg);
3285}
3286
3320 std::string_view text,
3321 Color fg,
3322 int wrapLength)
3323{
3324 return Surface(TTF_RenderText_Solid_Wrapped(
3325 font, text.data(), text.size(), fg, wrapLength));
3326}
3327
3328inline Surface Font::RenderText_Solid_Wrapped(std::string_view text,
3329 Color fg,
3330 int wrapLength) const
3331{
3332 return SDL::RenderText_Solid_Wrapped(get(), text, fg, wrapLength);
3333}
3334
3363{
3364 return Surface(TTF_RenderGlyph_Solid(font, ch, fg));
3365}
3366
3368{
3369 return SDL::RenderGlyph_Solid(get(), ch, fg);
3370}
3371
3407 std::string_view text,
3408 Color fg,
3409 Color bg)
3410{
3411 return Surface(TTF_RenderText_Shaded(font, text.data(), text.size(), fg, bg));
3412}
3413
3414inline Surface Font::RenderText_Shaded(std::string_view text,
3415 Color fg,
3416 Color bg) const
3417{
3418 return SDL::RenderText_Shaded(get(), text, fg, bg);
3419}
3420
3456 std::string_view text,
3457 Color fg,
3458 Color bg,
3459 int wrap_width)
3460{
3461 return Surface(TTF_RenderText_Shaded_Wrapped(
3462 font, text.data(), text.size(), fg, bg, wrap_width));
3463}
3464
3465inline Surface Font::RenderText_Shaded_Wrapped(std::string_view text,
3466 Color fg,
3467 Color bg,
3468 int wrap_width) const
3469{
3470 return SDL::RenderText_Shaded_Wrapped(get(), text, fg, bg, wrap_width);
3471}
3472
3503 Uint32 ch,
3504 ColorRaw fg,
3505 ColorRaw bg)
3506{
3507 return Surface(TTF_RenderGlyph_Shaded(font, ch, fg, bg));
3508}
3509
3511 ColorRaw fg,
3512 ColorRaw bg) const
3513{
3514 return SDL::RenderGlyph_Shaded(get(), ch, fg, bg);
3515}
3516
3549inline Surface RenderText_Blended(FontRef font, std::string_view text, Color fg)
3550{
3551 return Surface(TTF_RenderText_Blended(font, text.data(), text.size(), fg));
3552}
3553
3554inline Surface Font::RenderText_Blended(std::string_view text, Color fg) const
3555{
3556 return SDL::RenderText_Blended(get(), text, fg);
3557}
3558
3592 std::string_view text,
3593 Color fg,
3594 int wrap_width)
3595{
3596 return Surface(TTF_RenderText_Blended_Wrapped(
3597 font, text.data(), text.size(), fg, wrap_width));
3598}
3599
3600inline Surface Font::RenderText_Blended_Wrapped(std::string_view text,
3601 Color fg,
3602 int wrap_width) const
3603{
3604 return SDL::RenderText_Blended_Wrapped(get(), text, fg, wrap_width);
3605}
3606
3635{
3636 return Surface(TTF_RenderGlyph_Blended(font, ch, fg));
3637}
3638
3640{
3641 return SDL::RenderGlyph_Blended(get(), ch, fg);
3642}
3643
3678 std::string_view text,
3679 Color fg,
3680 Color bg)
3681{
3682 return Surface(TTF_RenderText_LCD(font, text.data(), text.size(), fg, bg));
3683}
3684
3685inline Surface Font::RenderText_LCD(std::string_view text,
3686 Color fg,
3687 Color bg) const
3688{
3689 return SDL::RenderText_LCD(get(), text, fg, bg);
3690}
3691
3726 std::string_view text,
3727 Color fg,
3728 Color bg,
3729 int wrap_width)
3730{
3731 return Surface(TTF_RenderText_LCD_Wrapped(
3732 font, text.data(), text.size(), fg, bg, wrap_width));
3733}
3734
3735inline Surface Font::RenderText_LCD_Wrapped(std::string_view text,
3736 Color fg,
3737 Color bg,
3738 int wrap_width) const
3739{
3740 return SDL::RenderText_LCD_Wrapped(get(), text, fg, bg, wrap_width);
3741}
3742
3773 Uint32 ch,
3774 ColorRaw fg,
3775 ColorRaw bg)
3776{
3777 return Surface(TTF_RenderGlyph_LCD(font, ch, fg, bg));
3778}
3779
3781{
3782 return SDL::RenderGlyph_LCD(get(), ch, fg, bg);
3783}
3784
3793
3795 TTF_SUBSTRING_DIRECTION_MASK;
3797
3799 TTF_SUBSTRING_TEXT_START;
3801
3803constexpr SubStringFlags SUBSTRING_LINE_START = TTF_SUBSTRING_LINE_START;
3804
3806constexpr SubStringFlags SUBSTRING_LINE_END = TTF_SUBSTRING_LINE_END;
3807
3809 TTF_SUBSTRING_TEXT_END;
3810
3816using GPUTextEngineWinding = TTF_GPUTextEngineWinding;
3817
3819 TTF_GPU_TEXTENGINE_WINDING_INVALID;
3820
3822 TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE;
3823
3825 TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE;
3826
3844struct TextEngine : ResourceBase<TextEngineRaw>
3845{
3847
3855 constexpr explicit TextEngine(TextEngineRaw resource) noexcept
3856 : ResourceBase(resource)
3857 {
3858 }
3859
3861 constexpr TextEngine(const TextEngine& other) = delete;
3862
3864 constexpr TextEngine(TextEngine&& other) noexcept
3865 : TextEngine(other.release())
3866 {
3867 }
3868
3871
3873 constexpr TextEngine& operator=(TextEngine&& other) noexcept
3874 {
3875 swap(*this, other);
3876 return *this;
3877 }
3878
3880 TextEngine& operator=(const TextEngine& other) = delete;
3881
3883 virtual void Destroy() = 0;
3884
3900 Text CreateText(FontRef font, std::string_view text);
3901};
3902
3905{
3920
3921 SurfaceTextEngine(const SurfaceTextEngine&) = delete;
3922
3923 SurfaceTextEngine& operator=(const SurfaceTextEngine&) = delete;
3924
3925 ~SurfaceTextEngine() final { Destroy(); }
3926
3940 void Destroy() final;
3941};
3942
3945{
3963
3989
3990 RendererTextEngine(const RendererTextEngine&) = delete;
3991
3992 RendererTextEngine& operator=(const RendererTextEngine&) = delete;
3993
3994 ~RendererTextEngine() final { Destroy(); }
3995
4009 void Destroy() final;
4010};
4011
4014{
4032
4058
4059 GPUTextEngine(const GPUTextEngine&) = delete;
4060
4061 GPUTextEngine& operator=(const GPUTextEngine&) = delete;
4062
4063 ~GPUTextEngine() final { Destroy(); }
4064
4078 void SetGPUWinding(GPUTextEngineWinding winding);
4079
4095
4109 void Destroy() final;
4110};
4111
4119using GPUAtlasDrawSequence = TTF_GPUAtlasDrawSequence;
4120
4133using SubString = TTF_SubString;
4134
4135// Forward decl
4136struct SubStringIterator;
4137
4143using TextData = TTF_TextData;
4144
4156struct Text : ResourceBase<TextRaw, TextRawConst>
4157{
4159
4167 constexpr explicit Text(TextRaw resource) noexcept
4168 : ResourceBase(resource)
4169 {
4170 }
4171
4173 constexpr Text(const Text& other) = delete;
4174
4176 constexpr Text(Text&& other) noexcept
4177 : Text(other.release())
4178 {
4179 }
4180
4181 constexpr Text(const TextRef& other) = delete;
4182
4183 constexpr Text(TextRef&& other) = delete;
4184
4202 Text(TextEngineRef engine, FontRef font, std::string_view text);
4203
4205 constexpr operator TextConstRef() const noexcept { return get(); }
4206
4208 ~Text() { TTF_DestroyText(get()); }
4209
4211 constexpr Text& operator=(Text&& other) noexcept
4212 {
4213 swap(*this, other);
4214 return *this;
4215 }
4216
4218 Text& operator=(const Text& other) = delete;
4219
4230 void Destroy();
4231
4251 void DrawSurface(Point p, SurfaceRef surface) const;
4252
4272 void DrawRenderer(FPoint p) const;
4273
4301
4314
4330 void SetEngine(TextEngineRef engine);
4331
4345 TextEngineRef GetEngine() const;
4346
4367 bool SetFont(FontRef font);
4368
4382 FontRef GetFont() const;
4383
4398 void SetDirection(Direction direction);
4399
4412 Direction GetDirection() const;
4413
4430 void SetScript(Uint32 script);
4431
4448 Uint32 GetScript() const;
4449
4466 void SetColor(Color c);
4467
4484 void SetColorFloat(FColor c);
4485
4507 void GetColor(Uint8* r, Uint8* g, Uint8* b, Uint8* a) const;
4508
4523 Color GetColor() const;
4524
4546 void GetColorFloat(float* r, float* g, float* b, float* a) const;
4547
4562 FColor GetColorFloat() const;
4563
4582 void SetPosition(const PointRaw& p);
4583
4600 void GetPosition(int* x, int* y) const;
4601
4616 Point GetPosition() const;
4617
4634 void SetWrapWidth(int wrap_width);
4635
4650 int GetWrapWidth() const;
4651
4673 void SetWrapWhitespaceVisible(bool visible);
4674
4688 bool IsWrapWhitespaceVisible() const;
4689
4707 void SetString(std::string_view string);
4708
4730 void InsertString(int offset, std::string_view string);
4731
4749 void AppendString(std::string_view string);
4750
4773 void DeleteString(int offset, int length);
4774
4792 void GetSize(int* w, int* h) const;
4793
4810 Point GetSize() const;
4811
4831 void GetSubString(int offset, SubString* substring) const;
4832
4837
4842
4859
4878 void GetSubStringForLine(int line, SubString* substring) const;
4879
4892 {
4893 return GetSubStringsForRange(0);
4894 }
4895
4912 OwnArray<SubString*> GetSubStringsForRange(int offset, int length = -1) const;
4913
4930
4947 void GetSubStringForPoint(Point p, SubString* substring) const;
4948
4965 void GetPreviousSubString(const SubString& substring,
4966 SubString* previous) const;
4967
4983 void GetNextSubString(const SubString& substring, SubString* next) const;
4984
4999 void Update();
5000
5005 const char* GetText() const { return get()->text; }
5006
5008 int GetNumLines() const { return get()->num_lines; }
5009};
5010
5015class SubStringIterator
5016{
5017 TextRef m_text;
5018
5019 SubString m_subString;
5020
5022 : m_text(text)
5023 , m_subString()
5024 {
5025 }
5026
5027public:
5030 : SubStringIterator(TextRef{})
5031 {
5032 }
5033
5035 constexpr operator bool() const { return bool(m_text); }
5036
5038 constexpr const SubString& operator*() const { return m_subString; }
5039
5041 constexpr const SubString* operator->() const { return &m_subString; }
5042
5044 constexpr bool operator==(const SubStringIterator& other) const
5045 {
5046 return m_subString.offset == other.m_subString.offset;
5047 }
5048
5050 SubStringIterator& operator++()
5051 {
5052 m_text.GetNextSubString(m_subString, &m_subString);
5053 return *this;
5054 }
5055
5057 SubStringIterator operator++(int)
5058 {
5059 auto curr = *this;
5060 m_text.GetNextSubString(m_subString, &m_subString);
5061 return curr;
5062 }
5063
5065 SubStringIterator& operator--()
5066 {
5067 m_text.GetPreviousSubString(m_subString, &m_subString);
5068 return *this;
5069 }
5070
5072 SubStringIterator operator--(int)
5073 {
5074 auto curr = *this;
5075 m_text.GetPreviousSubString(m_subString, &m_subString);
5076 return curr;
5077 }
5078
5079 friend class Text;
5080};
5081
5099
5101 : TextEngine(TTF_CreateSurfaceTextEngine())
5102{
5103}
5104
5125inline void DrawSurfaceText(TextConstRef text, Point p, SurfaceRef surface)
5126{
5127 CheckError(TTF_DrawSurfaceText(text, p.x, p.y, surface));
5128}
5129
5130inline void Text::DrawSurface(Point p, SurfaceRef surface) const
5131{
5132 SDL::DrawSurfaceText(get(), p, surface);
5133}
5134
5151{
5152 TTF_DestroySurfaceTextEngine(engine);
5153}
5154
5159
5177{
5178 return RendererTextEngine(renderer);
5179}
5180
5182 : TextEngine(TTF_CreateRendererTextEngine(renderer))
5183{
5184}
5185
5187 : TextEngine(TTF_CreateRendererTextEngineWithProperties(props))
5188{
5189}
5190
5220
5230
5231constexpr auto RENDERER_POINTER =
5232 TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER;
5233
5235 TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE;
5237
5238} // namespace prop::RendererTextEngine
5239
5261{
5262 CheckError(TTF_DrawRendererText(text, p.x, p.y));
5263}
5264
5265inline void Text::DrawRenderer(FPoint p) const
5266{
5268}
5269
5286{
5287 TTF_DestroyRendererTextEngine(engine);
5288}
5289
5294
5312{
5313 return GPUTextEngine(device);
5314}
5315
5317 : TextEngine(TTF_CreateGPUTextEngine(device))
5318{
5319}
5320
5322 : TextEngine(TTF_CreateGPUTextEngineWithProperties(props))
5323{
5324}
5325
5354
5364
5365constexpr auto DEVICE_POINTER =
5366 TTF_PROP_GPU_TEXT_ENGINE_DEVICE;
5367
5369 TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE;
5371
5372} // namespace prop::GpuTextEngine
5373
5400{
5401 return TTF_GetGPUTextDrawData(text);
5402}
5403
5405{
5406 return SDL::GetGPUTextDrawData(get());
5407}
5408
5425{
5426 TTF_DestroyGPUTextEngine(engine);
5427}
5428
5430
5447 GPUTextEngineWinding winding)
5448{
5449 TTF_SetGPUTextEngineWinding(engine, winding);
5450}
5451
5456
5474{
5475 return TTF_GetGPUTextEngineWinding(engine);
5476}
5477
5482
5501 FontRef font,
5502 std::string_view text)
5503{
5504 return Text(engine, font, text);
5505}
5506
5507inline Text TextEngine::CreateText(FontRef font, std::string_view text)
5508{
5509 return Text(get(), font, text);
5510}
5511
5512inline Text::Text(TextEngineRef engine, FontRef font, std::string_view text)
5513 : Text(TTF_CreateText(engine, font, text.data(), text.size()))
5514{
5515}
5516
5530{
5531 return {CheckError(TTF_GetTextProperties(text))};
5532}
5533
5535{
5536 return SDL::GetTextProperties(get());
5537}
5538
5555inline void SetTextEngine(TextRef text, TextEngineRef engine)
5556{
5557 CheckError(TTF_SetTextEngine(text, engine));
5558}
5559
5561{
5562 SDL::SetTextEngine(get(), engine);
5563}
5564
5580{
5581 return CheckError(TTF_GetTextEngine(text));
5582}
5583
5585{
5586 return SDL::GetTextEngine(get());
5587}
5588
5610inline bool SetTextFont(TextRef text, FontRef font)
5611{
5612 return TTF_SetTextFont(text, font);
5613}
5614
5615inline bool Text::SetFont(FontRef font)
5616{
5617 return SDL::SetTextFont(get(), font);
5618}
5619
5635{
5636 return {CheckError(TTF_GetTextFont(text))};
5637}
5638
5639inline FontRef Text::GetFont() const { return SDL::GetTextFont(get()); }
5640
5656inline void SetTextDirection(TextRef text, Direction direction)
5657{
5658 CheckError(TTF_SetTextDirection(text, direction));
5659}
5660
5661inline void Text::SetDirection(Direction direction)
5662{
5663 SDL::SetTextDirection(get(), direction);
5664}
5665
5680{
5681 return TTF_GetTextDirection(text);
5682}
5683
5685{
5686 return SDL::GetTextDirection(get());
5687}
5688
5706inline void SetTextScript(TextRef text, Uint32 script)
5707{
5708 CheckError(TTF_SetTextScript(text, script));
5709}
5710
5711inline void Text::SetScript(Uint32 script)
5712{
5713 SDL::SetTextScript(get(), script);
5714}
5715
5734{
5735 return TTF_GetTextScript(text);
5736}
5737
5738inline Uint32 Text::GetScript() const { return SDL::GetTextScript(get()); }
5739
5757inline void SetTextColor(TextRef text, Color c)
5758{
5759 CheckError(TTF_SetTextColor(text, c.r, c.g, c.b, c.a));
5760}
5761
5763
5782{
5783 CheckError(TTF_SetTextColorFloat(text, c.r, c.g, c.b, c.a));
5784}
5785
5787
5811 Uint8* r,
5812 Uint8* g,
5813 Uint8* b,
5814 Uint8* a)
5815{
5816 CheckError(TTF_GetTextColor(text, r, g, b, a));
5817}
5818
5835{
5836 Color c;
5837 GetTextColor(text, &c.r, &c.g, &c.b, &c.a);
5838 return c;
5839}
5840
5841inline void Text::GetColor(Uint8* r, Uint8* g, Uint8* b, Uint8* a) const
5842{
5843 SDL::GetTextColor(get(), r, g, b, a);
5844}
5845
5846inline Color Text::GetColor() const { return SDL::GetTextColor(get()); }
5847
5871 float* r,
5872 float* g,
5873 float* b,
5874 float* a)
5875{
5876 CheckError(TTF_GetTextColorFloat(text, r, g, b, a));
5877}
5878
5895{
5896 FColor c;
5897 GetTextColorFloat(text, &c.r, &c.g, &c.b, &c.a);
5898 return c;
5899}
5900
5901inline void Text::GetColorFloat(float* r, float* g, float* b, float* a) const
5902{
5903 SDL::GetTextColorFloat(get(), r, g, b, a);
5904}
5905
5907{
5908 return SDL::GetTextColorFloat(get());
5909}
5910
5930inline void SetTextPosition(TextRef text, const PointRaw& p)
5931{
5932 CheckError(TTF_SetTextPosition(text, p.x, p.y));
5933}
5934
5935inline void Text::SetPosition(const PointRaw& p)
5936{
5938}
5939
5957inline void GetTextPosition(TextConstRef text, int* x, int* y)
5958{
5959 CheckError(TTF_GetTextPosition(text, x, y));
5960}
5961
5978{
5979 Point p;
5980 GetTextPosition(text, &p.x, &p.y);
5981 return p;
5982}
5983
5984inline void Text::GetPosition(int* x, int* y) const
5985{
5986 SDL::GetTextPosition(get(), x, y);
5987}
5988
5990
6008inline void SetTextWrapWidth(TextRef text, int wrap_width)
6009{
6010 CheckError(TTF_SetTextWrapWidth(text, wrap_width));
6011}
6012
6013inline void Text::SetWrapWidth(int wrap_width)
6014{
6015 SDL::SetTextWrapWidth(get(), wrap_width);
6016}
6017
6034{
6035 int w;
6036 CheckError(TTF_GetTextWrapWidth(text, &w));
6037 return w;
6038}
6039
6040inline int Text::GetWrapWidth() const { return SDL::GetTextWrapWidth(get()); }
6041
6062inline void SetTextWrapWhitespaceVisible(TextRef text, bool visible)
6063{
6064 CheckError(TTF_SetTextWrapWhitespaceVisible(text, visible));
6065}
6066
6067inline void Text::SetWrapWhitespaceVisible(bool visible)
6068{
6070}
6071
6086{
6087 return TTF_TextWrapWhitespaceVisible(text);
6088}
6089
6091{
6093}
6094
6113inline void SetTextString(TextRef text, std::string_view string)
6114{
6115 CheckError(TTF_SetTextString(text, string.data(), string.size()));
6116}
6117
6118inline void Text::SetString(std::string_view string)
6119{
6120 SDL::SetTextString(get(), string);
6121}
6122
6145inline void InsertTextString(TextRef text, int offset, std::string_view string)
6146{
6147 CheckError(TTF_InsertTextString(text, offset, string.data(), string.size()));
6148}
6149
6150inline void Text::InsertString(int offset, std::string_view string)
6151{
6152 SDL::InsertTextString(get(), offset, string);
6153}
6154
6173inline void AppendTextString(TextRef text, std::string_view string)
6174{
6175 CheckError(TTF_AppendTextString(text, string.data(), string.size()));
6176}
6177
6178inline void Text::AppendString(std::string_view string)
6179{
6180 SDL::AppendTextString(get(), string);
6181}
6182
6206inline void DeleteTextString(TextRef text, int offset, int length)
6207{
6208 CheckError(TTF_DeleteTextString(text, offset, length));
6209}
6210
6211inline void Text::DeleteString(int offset, int length)
6212{
6213 SDL::DeleteTextString(get(), offset, length);
6214}
6215
6233inline void GetTextSize(TextConstRef text, int* w, int* h)
6234{
6235 CheckError(TTF_GetTextSize(text, w, h));
6236}
6237
6254{
6255 Point p;
6256 GetTextSize(text, &p.x, &p.y);
6257 return p;
6258}
6259
6260inline void Text::GetSize(int* w, int* h) const
6261{
6262 SDL::GetTextSize(get(), w, h);
6263}
6264
6265inline Point Text::GetSize() const { return SDL::GetTextSize(get()); }
6266
6288 int offset,
6289 SubString* substring)
6290{
6291 CheckError(TTF_GetTextSubString(text, offset, substring));
6292}
6293
6294inline void Text::GetSubString(int offset, SubString* substring) const
6295{
6296 SDL::GetTextSubString(get(), offset, substring);
6297}
6298
6319 int line,
6320 SubString* substring)
6321{
6322 CheckError(TTF_GetTextSubStringForLine(text, line, substring));
6323}
6324
6325inline void Text::GetSubStringForLine(int line, SubString* substring) const
6326{
6327 SDL::GetTextSubStringForLine(get(), line, substring);
6328}
6329
6346 int offset,
6347 int length)
6348{
6349 int count = 0;
6350 auto data = TTF_GetTextSubStringsForRange(text, offset, length, &count);
6351 return OwnArray<SubString*>{data, size_t(count)};
6352}
6353
6355 int length) const
6356{
6357 return SDL::GetTextSubStringsForRange(get(), offset, length);
6358}
6359
6378 Point p,
6379 SubString* substring)
6380{
6381 CheckError(TTF_GetTextSubStringForPoint(text, p.x, p.y, substring));
6382}
6383
6384inline void Text::GetSubStringForPoint(Point p, SubString* substring) const
6385{
6386 SDL::GetTextSubStringForPoint(get(), p, substring);
6387}
6388
6407 const SubString& substring,
6408 SubString* previous)
6409{
6410 CheckError(TTF_GetPreviousTextSubString(text, &substring, previous));
6411}
6412
6413inline void Text::GetPreviousSubString(const SubString& substring,
6414 SubString* previous) const
6415{
6416 SDL::GetPreviousTextSubString(get(), substring, previous);
6417}
6418
6436 const SubString& substring,
6437 SubString* next)
6438{
6439 CheckError(TTF_GetNextTextSubString(text, &substring, next));
6440}
6441
6442inline void Text::GetNextSubString(const SubString& substring,
6443 SubString* next) const
6444{
6445 SDL::GetNextTextSubString(get(), substring, next);
6446}
6447
6463inline void UpdateText(TextRef text) { CheckError(TTF_UpdateText(text)); }
6464
6465inline void Text::Update() { SDL::UpdateText(get()); }
6466
6479inline void DestroyText(TextRaw text) { TTF_DestroyText(text); }
6480
6481inline void Text::Destroy() { DestroyText(release()); }
6482
6505inline void CloseFont(FontRaw font) { TTF_CloseFont(font); }
6506
6507inline void Font::Close() { CloseFont(release()); }
6508
6510
6511} // namespace SDL
6512
6513#endif // defined(SDL3PP_ENABLE_TTF) || defined(SDL3PP_DOC)
6514
6515#endif /* SDL3PP_TTF_H_ */
An exception that returns GetError().
Definition SDL3pp_error.h:163
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Const reference wrapper for a given resource,.
Definition SDL3pp_resource.h:111
Reference wrapper for a given resource,.
Definition SDL3pp_resource.h:75
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Iterator for substrings.
Definition SDL3pp_ttf.h:5016
SubStringIterator()
Default constructor.
Definition SDL3pp_ttf.h:5029
SubStringIterator operator--(int)
Decrement operator.
Definition SDL3pp_ttf.h:5072
constexpr const SubString & operator*() const
Retrieve SubString.
Definition SDL3pp_ttf.h:5038
constexpr const SubString * operator->() const
Retrieve SubString.
Definition SDL3pp_ttf.h:5041
SubStringIterator & operator--()
Decrement operator.
Definition SDL3pp_ttf.h:5065
constexpr bool operator==(const SubStringIterator &other) const
Comparison.
Definition SDL3pp_ttf.h:5044
SubStringIterator & operator++()
Increment operator.
Definition SDL3pp_ttf.h:5050
SubStringIterator operator++(int)
Increment operator.
Definition SDL3pp_ttf.h:5057
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:383
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
ResourceRef< GPUDevice > GPUDeviceRef
Reference for GPUDevice.
Definition SDL3pp_gpu.h:386
ResourceRef< IOStream > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:34
void Quit()
Clean up all initialized subsystems.
Definition SDL3pp_init.h:329
SDL_Color ColorRaw
Alias to raw representation for Color.
Definition SDL3pp_pixels.h:83
ResourceRef< Properties > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:54
SDL_Point PointRaw
Alias to raw representation for Point.
Definition SDL3pp_rect.h:22
Point GetPosition() const
Get the position of a text object.
Definition SDL3pp_ttf.h:5989
void GetStringSize(FontRef font, std::string_view text, int *w, int *h)
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:3148
FontRef GetFont() const
Get the font used by a text object.
Definition SDL3pp_ttf.h:5639
TTF_ImageType ImageType
The type of data in a glyph image.
Definition SDL3pp_ttf.h:332
constexpr FontStyleFlags STYLE_NORMAL
No special style.
Definition SDL3pp_ttf.h:235
void SetTextPosition(TextRef text, const PointRaw &p)
Set the position of a text object.
Definition SDL3pp_ttf.h:5930
Uint32 GetGlyphScript(Uint32 ch)
Get the script used by a 32-bit codepoint.
Definition SDL3pp_ttf.h:2941
constexpr SubStringFlags SUBSTRING_LINE_END
This substring contains the end of line line_index.
Definition SDL3pp_ttf.h:3806
constexpr HintingFlags HINTING_LIGHT
Light hinting applies subtle adjustments to improve rendering.
Definition SDL3pp_ttf.h:271
FontStyleFlags GetFontStyle(FontRef font)
Query a font's current style.
Definition SDL3pp_ttf.h:2286
bool GetFontKerning(FontRef font)
Query whether or not kerning is enabled for a font.
Definition SDL3pp_ttf.h:2695
constexpr HorizontalAlignment HORIZONTAL_ALIGN_CENTER
CENTER.
Definition SDL3pp_ttf.h:298
void GetPreviousTextSubString(TextConstRef text, const SubString &substring, SubString *previous)
Get the previous substring in a text object.
Definition SDL3pp_ttf.h:6406
PropertiesRef GetTextProperties(TextConstRef text)
Get the properties associated with a text object.
Definition SDL3pp_ttf.h:5529
void Destroy() final
Destroy a text engine created for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:5155
void SetTextScript(TextRef text, Uint32 script)
Set the script to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5706
Font OpenFontIO(IOStreamRef src, float ptsize, bool closeio=false)
Create a font from an IOStream, using a specified point size.
Definition SDL3pp_ttf.h:1863
TTF_Text * TextRaw
Alias to raw representation for Text.
Definition SDL3pp_ttf.h:57
int GetFontDescent(FontRef font)
Query the offset from the baseline to the bottom of a font.
Definition SDL3pp_ttf.h:2608
constexpr HorizontalAlignment HORIZONTAL_ALIGN_RIGHT
RIGHT.
Definition SDL3pp_ttf.h:301
TTF_GPUTextEngineWinding GPUTextEngineWinding
The winding order of the vertices returned by Text.GetGPUDrawData.
Definition SDL3pp_ttf.h:3816
ResourceLegacyRef< TextEngineRaw > TextEngineRef
Reference for TextEngine.
Definition SDL3pp_ttf.h:51
void Destroy() final
Destroy a text engine created for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:5290
int GetFontWeight(FontRef font)
Query a font's weight, in terms of the lightness/heaviness of the strokes.
Definition SDL3pp_ttf.h:2481
void SetTextWrapWhitespaceVisible(TextRef text, bool visible)
Set whether whitespace should be visible when wrapping a text object.
Definition SDL3pp_ttf.h:6062
void SetFontLanguage(FontRef font, StringParam language_bcp47)
Set language to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2968
void GetPreviousSubString(const SubString &substring, SubString *previous) const
Get the previous substring in a text object.
Definition SDL3pp_ttf.h:6413
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE
COUNTER_CLOCKWISE.
Definition SDL3pp_ttf.h:3824
Surface RenderText_Solid_Wrapped(FontRef font, std::string_view text, Color fg, int wrapLength)
Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3319
void MeasureString(FontRef font, std::string_view text, int max_width, int *measured_width, size_t *measured_length)
Calculate how much of a UTF-8 string will fit in a given width.
Definition SDL3pp_ttf.h:3222
const TTF_Text * TextRawConst
Alias to const raw representation for Text.
Definition SDL3pp_ttf.h:60
bool IsFixedWidth() const
Query whether a font is fixed-width.
Definition SDL3pp_ttf.h:2720
void SetFontStyle(FontRef font, FontStyleFlags style)
Set a font's current style.
Definition SDL3pp_ttf.h:2256
Surface RenderText_LCD_Wrapped(FontRef font, std::string_view text, Color fg, Color bg, int wrap_width)
Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3725
GPUTextEngine CreateGPUTextEngineWithProperties(PropertiesRef props)
Create a text engine for drawing text with the SDL GPU API, with the specified properties.
Definition SDL3pp_ttf.h:5350
void GetTextColorFloat(TextConstRef text, float *r, float *g, float *b, float *a)
Get the color of a text object.
Definition SDL3pp_ttf.h:5870
TTF_Direction Direction
Direction flags.
Definition SDL3pp_ttf.h:315
constexpr SubStringFlags SUBSTRING_TEXT_START
This substring contains the beginning of the text.
Definition SDL3pp_ttf.h:3798
const char * GetStyleName() const
Query a font's style name.
Definition SDL3pp_ttf.h:2787
void SetTextDirection(TextRef text, Direction direction)
Set the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5656
static Uint32 GetGlyphScript(Uint32 ch)
Get the script used by a 32-bit codepoint.
Definition SDL3pp_ttf.h:2946
void ClearFallbackFonts(FontRef font)
Remove all fallback fonts.
Definition SDL3pp_ttf.h:2130
void SetFontScript(FontRef font, Uint32 script)
Set the script to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2898
Surface RenderText_LCD(std::string_view text, Color fg, Color bg) const
Render UTF-8 text at LCD subpixel quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3685
Uint32 GetFontGeneration(FontRef font)
Get the font generation.
Definition SDL3pp_ttf.h:2047
void AppendTextString(TextRef text, std::string_view string)
Append UTF-8 text to a text object.
Definition SDL3pp_ttf.h:6173
void SetSizeDPI(float ptsize, int hdpi, int vdpi)
Set font size dynamically with target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:2183
constexpr int FONT_WEIGHT_BLACK
Black (900) named font weight value.
Definition SDL3pp_ttf.h:2509
void SetLanguage(StringParam language_bcp47)
Set language to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2973
void SetFontWrapAlignment(FontRef font, HorizontalAlignment align)
Set a font's current wrap alignment option.
Definition SDL3pp_ttf.h:2532
TextEngineRef GetTextEngine(TextConstRef text)
Get the text engine used by a text object.
Definition SDL3pp_ttf.h:5579
void DestroyRendererTextEngine(TextEngineRaw engine)
Destroy a text engine created for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:5285
void DrawRenderer(FPoint p) const
Draw text to an SDL renderer.
Definition SDL3pp_ttf.h:5265
constexpr SubStringFlags SUBSTRING_LINE_START
This substring contains the beginning of line line_index.
Definition SDL3pp_ttf.h:3803
void DestroyText(TextRaw text)
Destroy a text object created by a text engine.
Definition SDL3pp_ttf.h:6479
constexpr Direction DIRECTION_LTR
Left to Right.
Definition SDL3pp_ttf.h:319
TTF_SubString SubString
The representation of a substring within text.
Definition SDL3pp_ttf.h:4133
constexpr ImageType IMAGE_COLOR
The color channels have image data.
Definition SDL3pp_ttf.h:339
Surface GetGlyphImage(FontRef font, Uint32 ch, ImageType *image_type)
Get the pixel image for a UNICODE codepoint.
Definition SDL3pp_ttf.h:3015
Uint32 GetTextScript(TextConstRef text)
Get the script used for text shaping a text object.
Definition SDL3pp_ttf.h:5733
void AddFallback(FontRef fallback)
Add a fallback font.
Definition SDL3pp_ttf.h:2084
Uint32 StringToTag(StringParam string)
Convert from a 4 character string to a 32-bit tag.
Definition SDL3pp_ttf.h:2854
Direction GetTextDirection(TextConstRef text)
Get the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5679
Surface RenderText_LCD(FontRef font, std::string_view text, Color fg, Color bg)
Render UTF-8 text at LCD subpixel quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3677
HintingFlags GetHinting() const
Query a font's current FreeType hinter setting.
Definition SDL3pp_ttf.h:2417
Surface GetGlyphImage(Uint32 ch, ImageType *image_type) const
Get the pixel image for a UNICODE codepoint.
Definition SDL3pp_ttf.h:3020
void GetTextSubStringForPoint(TextConstRef text, Point p, SubString *substring)
Get the portion of a text string that is closest to a point.
Definition SDL3pp_ttf.h:6377
const char * GetFamilyName() const
Query a font's family name.
Definition SDL3pp_ttf.h:2761
void ClearFallbacks()
Remove all fallback fonts.
Definition SDL3pp_ttf.h:2132
void SetString(std::string_view string)
Set the UTF-8 text used by a text object.
Definition SDL3pp_ttf.h:6118
void UpdateText(TextRef text)
Update the layout of a text object.
Definition SDL3pp_ttf.h:6463
Direction GetDirection() const
Get the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5684
void DrawSurfaceText(TextConstRef text, Point p, SurfaceRef surface)
Draw text to an SDL surface.
Definition SDL3pp_ttf.h:5125
int GetWrapWidth() const
Get whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:6040
Point GetSize() const
Get the size of a text object.
Definition SDL3pp_ttf.h:6265
void SetStyle(FontStyleFlags style)
Set a font's current style.
Definition SDL3pp_ttf.h:2261
bool SetTextFont(TextRef text, FontRef font)
Set the font used by a text object.
Definition SDL3pp_ttf.h:5610
SurfaceTextEngine()
Create a text engine for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:5100
Surface GetGlyphImageForIndex(Uint32 glyph_index, ImageType *image_type) const
Get the pixel image for a character index.
Definition SDL3pp_ttf.h:3051
void SetWrapWhitespaceVisible(bool visible)
Set whether whitespace should be visible when wrapping a text object.
Definition SDL3pp_ttf.h:6067
void SetDirection(Direction direction)
Set the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5661
constexpr ImageType IMAGE_INVALID
INVALID.
Definition SDL3pp_ttf.h:334
Text CreateText(TextEngineRef engine, FontRef font, std::string_view text)
Create a text object from UTF-8 text and a text engine.
Definition SDL3pp_ttf.h:5500
FontStyleFlags GetStyle() const
Query a font's current style.
Definition SDL3pp_ttf.h:2291
TextEngineRef GetEngine() const
Get the text engine used by a text object.
Definition SDL3pp_ttf.h:5584
Surface RenderText_Solid_Wrapped(std::string_view text, Color fg, int wrapLength) const
Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3328
float GetFontSize(FontRef font)
Get the size of a font.
Definition SDL3pp_ttf.h:2203
Surface RenderText_Shaded(FontRef font, std::string_view text, Color fg, Color bg)
Render UTF-8 text at high quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3406
void SetTextWrapWidth(TextRef text, int wrap_width)
Set whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:6008
void RemoveFallbackFont(FontRef font, FontRef fallback)
Remove a fallback font.
Definition SDL3pp_ttf.h:2105
void GetHarfBuzzVersion(int *major, int *minor, int *patch)
Query the version of the HarfBuzz library in use.
Definition SDL3pp_ttf.h:216
Font OpenFontWithProperties(PropertiesRef props)
Create a font with the specified properties.
Definition SDL3pp_ttf.h:1910
const char * GetFontStyleName(FontRef font)
Query a font's style name.
Definition SDL3pp_ttf.h:2782
void SetOutline(int outline)
Set a font's current outline.
Definition SDL3pp_ttf.h:2322
Surface RenderText_Blended_Wrapped(std::string_view text, Color fg, int wrap_width) const
Render word-wrapped UTF-8 text at high quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3600
constexpr HintingFlags HINTING_INVALID
INVALID.
Definition SDL3pp_ttf.h:263
int GetHeight() const
Query the total height of a font.
Definition SDL3pp_ttf.h:2578
void AddFallbackFont(FontRef font, FontRef fallback)
Add a fallback font.
Definition SDL3pp_ttf.h:2079
bool GetKerning() const
Query whether or not kerning is enabled for a font.
Definition SDL3pp_ttf.h:2697
Surface RenderText_Solid(std::string_view text, Color fg) const
Render UTF-8 text at fast quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3282
bool FontHasGlyph(FontRef font, Uint32 ch)
Check whether a glyph is provided by the font for a UNICODE codepoint.
Definition SDL3pp_ttf.h:2990
GPUAtlasDrawSequence * GetGPUTextDrawData(TextConstRef text)
Get the geometry data needed for drawing the text.
Definition SDL3pp_ttf.h:5399
void DestroySurfaceTextEngine(TextEngineRaw engine)
Destroy a text engine created for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:5150
int GetOutline() const
Query a font's current outline.
Definition SDL3pp_ttf.h:2341
constexpr int FONT_WEIGHT_EXTRA_LIGHT
ExtraLight (200) named font weight value.
Definition SDL3pp_ttf.h:2488
TTF_GPUAtlasDrawSequence GPUAtlasDrawSequence
Draw sequence returned by Text.GetGPUDrawData.
Definition SDL3pp_ttf.h:4119
Surface GetGlyphImageForIndex(FontRef font, Uint32 glyph_index, ImageType *image_type)
Get the pixel image for a character index.
Definition SDL3pp_ttf.h:3043
void SetGPUWinding(GPUTextEngineWinding winding)
Sets the winding order of the vertices returned by Text.GetGPUDrawData for a particular GPU text engi...
Definition SDL3pp_ttf.h:5452
bool FontIsFixedWidth(FontRef font)
Query whether a font is fixed-width.
Definition SDL3pp_ttf.h:2715
Uint32 FontStyleFlags
Font style flags for Font.
Definition SDL3pp_ttf.h:233
void RemoveFallback(FontRef fallback)
Remove a fallback font.
Definition SDL3pp_ttf.h:2110
bool TextWrapWhitespaceVisible(TextConstRef text)
Return whether whitespace is shown when wrapping a text object.
Definition SDL3pp_ttf.h:6085
void SetColor(Color c)
Set the color of a text object.
Definition SDL3pp_ttf.h:5762
bool IsWrapWhitespaceVisible() const
Return whether whitespace is shown when wrapping a text object.
Definition SDL3pp_ttf.h:6090
int GetFontAscent(FontRef font)
Query the offset from the baseline to the top of a font.
Definition SDL3pp_ttf.h:2592
float GetSize() const
Get the size of a font.
Definition SDL3pp_ttf.h:2205
int GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const
Query the kerning size between the glyphs of two UNICODE codepoints.
Definition SDL3pp_ttf.h:3126
Surface RenderText_Blended(std::string_view text, Color fg) const
Render UTF-8 text at high quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3554
void GetGlyphMetrics(FontRef font, Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance)
Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint.
Definition SDL3pp_ttf.h:3085
void SetTextColor(TextRef text, Color c)
Set the color of a text object.
Definition SDL3pp_ttf.h:5757
Uint32 SubStringFlags
Flags for SubString.
Definition SDL3pp_ttf.h:3792
void SetFontLineSkip(FontRef font, int lineskip)
Set the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:2627
Surface RenderText_Shaded_Wrapped(FontRef font, std::string_view text, Color fg, Color bg, int wrap_width)
Render word-wrapped UTF-8 text at high quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3455
Surface RenderGlyph_Blended(Uint32 ch, ColorRaw fg) const
Render a single UNICODE codepoint at high quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3639
constexpr Direction DIRECTION_BTT
Bottom to Top.
Definition SDL3pp_ttf.h:325
constexpr HintingFlags HINTING_MONO
Monochrome hinting adjusts the font for better rendering at lower resolutions.
Definition SDL3pp_ttf.h:277
void SetSDF(bool enabled)
Enable Signed Distance Field rendering for a font.
Definition SDL3pp_ttf.h:2450
FontRef GetTextFont(TextConstRef text)
Get the font used by a text object.
Definition SDL3pp_ttf.h:5634
constexpr int FONT_WEIGHT_EXTRA_BOLD
ExtraBold (800) named font weight value.
Definition SDL3pp_ttf.h:2506
void SetScript(Uint32 script)
Set the script to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5711
void GetFontDPI(FontRef font, int *hdpi, int *vdpi)
Get font target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:2222
void SetWrapWidth(int wrap_width)
Set whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:6013
constexpr FontStyleFlags STYLE_ITALIC
Italic style.
Definition SDL3pp_ttf.h:239
Direction GetFontDirection(FontRef font)
Get the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2832
void SetLineSkip(int lineskip)
Set the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:2632
bool GetSDF() const
Query whether Signed Distance Field rendering is enabled for a font.
Definition SDL3pp_ttf.h:2466
HorizontalAlignment GetFontWrapAlignment(FontRef font)
Query a font's current wrap alignment option.
Definition SDL3pp_ttf.h:2554
void SetPosition(const PointRaw &p)
Set the position of a text object.
Definition SDL3pp_ttf.h:5935
void SetKerning(bool enabled)
Set if kerning is enabled for a font.
Definition SDL3pp_ttf.h:2678
bool IsScalable() const
Query whether a font is scalable or not.
Definition SDL3pp_ttf.h:2738
GPUTextEngine CreateGPUTextEngine(GPUDeviceRef device)
Create a text engine for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:5311
ResourceRef< Font > FontRef
Reference for Font.
Definition SDL3pp_ttf.h:38
Surface RenderText_LCD_Wrapped(std::string_view text, Color fg, Color bg, int wrap_width) const
Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3735
void GetFreeTypeVersion(int *major, int *minor, int *patch)
Query the version of the FreeType library in use.
Definition SDL3pp_ttf.h:198
void TagToString(Uint32 tag, char *string, size_t size)
Convert from a 32-bit tag to a 4 character string.
Definition SDL3pp_ttf.h:2874
bool GetFontSDF(FontRef font)
Query whether Signed Distance Field rendering is enabled for a font.
Definition SDL3pp_ttf.h:2464
void GetTextSubStringForLine(TextConstRef text, int line, SubString *substring)
Get the substring of a text object that contains the given line.
Definition SDL3pp_ttf.h:6318
constexpr FontStyleFlags STYLE_BOLD
Bold style.
Definition SDL3pp_ttf.h:237
constexpr FontStyleFlags STYLE_STRIKETHROUGH
Strikethrough text.
Definition SDL3pp_ttf.h:244
constexpr int FONT_WEIGHT_THIN
Thin (100) named font weight value.
Definition SDL3pp_ttf.h:2485
void GetNextSubString(const SubString &substring, SubString *next) const
Get the next substring in a text object.
Definition SDL3pp_ttf.h:6442
void SetColorFloat(FColor c)
Set the color of a text object.
Definition SDL3pp_ttf.h:5786
void SetTextEngine(TextRef text, TextEngineRef engine)
Set the text engine used by a text object.
Definition SDL3pp_ttf.h:5555
TTF_TextEngine * TextEngineRaw
Alias to raw representation for TextEngine.
Definition SDL3pp_ttf.h:44
constexpr Direction DIRECTION_RTL
Right to Left.
Definition SDL3pp_ttf.h:321
const char * GetFontFamilyName(FontRef font)
Query a font's family name.
Definition SDL3pp_ttf.h:2756
Direction GetDirection() const
Get the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2837
HintingFlags GetFontHinting(FontRef font)
Query a font's current FreeType hinter setting.
Definition SDL3pp_ttf.h:2412
GPUTextEngineWinding GetGPUWinding() const
Get the winding order of the vertices returned by Text.GetGPUDrawData for a particular GPU text engin...
Definition SDL3pp_ttf.h:5478
Uint32 GetGeneration() const
Get the font generation.
Definition SDL3pp_ttf.h:2052
int GetDescent() const
Query the offset from the baseline to the bottom of a font.
Definition SDL3pp_ttf.h:2610
Surface RenderGlyph_Solid(Uint32 ch, ColorRaw fg) const
Render a single 32-bit glyph at fast quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3367
Font CopyFont(FontRef existing_font)
Create a copy of an existing font.
Definition SDL3pp_ttf.h:1972
TTF_TextData TextData
Internal data for Text.
Definition SDL3pp_ttf.h:4143
void Update()
Update the layout of a text object.
Definition SDL3pp_ttf.h:6465
constexpr HintingFlags HINTING_NORMAL
Normal hinting applies standard grid-fitting.
Definition SDL3pp_ttf.h:267
void MeasureString(std::string_view text, int max_width, int *measured_width, size_t *measured_length) const
Calculate how much of a UTF-8 string will fit in a given width.
Definition SDL3pp_ttf.h:3236
void SetEngine(TextEngineRef engine)
Set the text engine used by a text object.
Definition SDL3pp_ttf.h:5560
constexpr HorizontalAlignment HORIZONTAL_ALIGN_INVALID
INVALID.
Definition SDL3pp_ttf.h:292
void SetFontSize(FontRef font, float ptsize)
Set a font's size dynamically.
Definition SDL3pp_ttf.h:2151
RendererTextEngine CreateRendererTextEngine(RendererRef renderer)
Create a text engine for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:5176
bool HasGlyph(Uint32 ch) const
Check whether a glyph is provided by the font for a UNICODE codepoint.
Definition SDL3pp_ttf.h:2995
constexpr Direction DIRECTION_INVALID
INVALID.
Definition SDL3pp_ttf.h:317
constexpr HintingFlags HINTING_NONE
No hinting, the font is rendered without any grid-fitting.
Definition SDL3pp_ttf.h:280
ResourceRef< Text > TextRef
Reference for Text.
Definition SDL3pp_ttf.h:67
Surface RenderText_Blended(FontRef font, std::string_view text, Color fg)
Render UTF-8 text at high quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3549
void SetGPUTextEngineWinding(TextEngineRef engine, GPUTextEngineWinding winding)
Sets the winding order of the vertices returned by Text.GetGPUDrawData for a particular GPU text engi...
Definition SDL3pp_ttf.h:5446
constexpr int FONT_WEIGHT_BOLD
Bold (700) named font weight value.
Definition SDL3pp_ttf.h:2503
Surface RenderGlyph_Shaded(Uint32 ch, ColorRaw fg, ColorRaw bg) const
Render a single UNICODE codepoint at high quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3510
constexpr ImageType IMAGE_ALPHA
The color channels are white.
Definition SDL3pp_ttf.h:336
void SetWrapAlignment(HorizontalAlignment align)
Set a font's current wrap alignment option.
Definition SDL3pp_ttf.h:2537
void SetFontOutline(FontRef font, int outline)
Set a font's current outline.
Definition SDL3pp_ttf.h:2317
void DeleteTextString(TextRef text, int offset, int length)
Delete UTF-8 text from a text object.
Definition SDL3pp_ttf.h:6206
constexpr int FONT_WEIGHT_MEDIUM
Medium (500) named font weight value.
Definition SDL3pp_ttf.h:2497
Surface RenderText_Shaded_Wrapped(std::string_view text, Color fg, Color bg, int wrap_width) const
Render word-wrapped UTF-8 text at high quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3465
Surface RenderGlyph_Solid(FontRef font, Uint32 ch, ColorRaw fg)
Render a single 32-bit glyph at fast quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3362
TTF_Font * FontRaw
Alias to raw representation for Font.
Definition SDL3pp_ttf.h:31
void DrawSurface(Point p, SurfaceRef surface) const
Draw text to an SDL surface.
Definition SDL3pp_ttf.h:5130
int GetWeight() const
Query a font's weight, in terms of the lightness/heaviness of the strokes.
Definition SDL3pp_ttf.h:2483
Surface RenderText_Shaded(std::string_view text, Color fg, Color bg) const
Render UTF-8 text at high quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3414
int GetGlyphKerning(FontRef font, Uint32 previous_ch, Uint32 ch)
Query the kerning size between the glyphs of two UNICODE codepoints.
Definition SDL3pp_ttf.h:3120
RendererTextEngine CreateRendererTextEngineWithProperties(PropertiesRef props)
Create a text engine for drawing text on an SDL renderer, with the specified properties.
Definition SDL3pp_ttf.h:5215
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_INVALID
INVALID.
Definition SDL3pp_ttf.h:3818
void SetDirection(Direction direction)
Set the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2814
void SetScript(Uint32 script)
Set the script to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2903
void SetFontKerning(FontRef font, bool enabled)
Set if kerning is enabled for a font.
Definition SDL3pp_ttf.h:2673
int GetLineSkip() const
Query the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:2651
GPUTextEngine(GPUDeviceRef device)
Create a text engine for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:5316
void Close()
Dispose of a previously-created font.
Definition SDL3pp_ttf.h:6507
Surface RenderGlyph_LCD(Uint32 ch, ColorRaw fg, ColorRaw bg) const
Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3780
void InsertString(int offset, std::string_view string)
Insert UTF-8 text into a text object.
Definition SDL3pp_ttf.h:6150
HorizontalAlignment GetWrapAlignment() const
Query a font's current wrap alignment option.
Definition SDL3pp_ttf.h:2559
void SetTextColorFloat(TextRef text, FColor c)
Set the color of a text object.
Definition SDL3pp_ttf.h:5781
bool SetFont(FontRef font)
Set the font used by a text object.
Definition SDL3pp_ttf.h:5615
void DestroyGPUTextEngine(TextEngineRaw engine)
Destroy a text engine created for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:5424
OwnArray< SubString * > GetTextSubStringsForRange(TextConstRef text, int offset, int length)
Get the substrings of a text object that contain a range of text.
Definition SDL3pp_ttf.h:6345
void GetNextTextSubString(TextConstRef text, const SubString &substring, SubString *next)
Get the next substring in a text object.
Definition SDL3pp_ttf.h:6435
void SetFontHinting(FontRef font, HintingFlags hinting)
Set a font's current hinter setting.
Definition SDL3pp_ttf.h:2367
OwnArray< SubString * > GetSubStringsForRange(int offset, int length=-1) const
Get the substrings of a text object that contain a range of text.
Definition SDL3pp_ttf.h:6354
Surface RenderText_Blended_Wrapped(FontRef font, std::string_view text, Color fg, int wrap_width)
Render word-wrapped UTF-8 text at high quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3591
void GetSubString(int offset, SubString *substring) const
Get the substring of a text object that surrounds a text offset.
Definition SDL3pp_ttf.h:6294
constexpr FontStyleFlags STYLE_UNDERLINE
Underlined text.
Definition SDL3pp_ttf.h:241
constexpr int FONT_WEIGHT_EXTRA_BLACK
ExtraBlack (950) named font weight value.
Definition SDL3pp_ttf.h:2512
void GetTextPosition(TextConstRef text, int *x, int *y)
Get the position of a text object.
Definition SDL3pp_ttf.h:5957
void AppendString(std::string_view string)
Append UTF-8 text to a text object.
Definition SDL3pp_ttf.h:6178
constexpr SubStringFlags SUBSTRING_TEXT_END
This substring contains the end of the text.
Definition SDL3pp_ttf.h:3808
Font Copy() const
Create a copy of an existing font.
Definition SDL3pp_ttf.h:1977
void GetTextSize(TextConstRef text, int *w, int *h)
Get the size of a text object.
Definition SDL3pp_ttf.h:6233
void GetTextSubString(TextConstRef text, int offset, SubString *substring)
Get the substring of a text object that surrounds a text offset.
Definition SDL3pp_ttf.h:6287
constexpr SubStringFlags SUBSTRING_DIRECTION_MASK
The mask for the flow direction for this substring.
Definition SDL3pp_ttf.h:3794
void GetTextColor(TextConstRef text, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
Get the color of a text object.
Definition SDL3pp_ttf.h:5810
int GetTextWrapWidth(TextConstRef text)
Get whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:6033
ResourceConstRef< TextRaw, TextRawConst > TextConstRef
Safely wrap Text for non owning const parameters.
Definition SDL3pp_ttf.h:70
PropertiesRef GetProperties() const
Get the properties associated with a text object.
Definition SDL3pp_ttf.h:5534
constexpr Direction DIRECTION_TTB
Top to Bottom.
Definition SDL3pp_ttf.h:323
int GetNumFaces() const
Query the number of faces of a font.
Definition SDL3pp_ttf.h:2389
int GetFontHeight(FontRef font)
Query the total height of a font.
Definition SDL3pp_ttf.h:2576
Text CreateText(FontRef font, std::string_view text)
Create a text object from UTF-8 text and a text engine.
Definition SDL3pp_ttf.h:5507
Surface RenderText_Solid(FontRef font, std::string_view text, Color fg)
Render UTF-8 text at fast quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3277
Color GetColor() const
Get the color of a text object.
Definition SDL3pp_ttf.h:5846
void SetSize(float ptsize)
Set a font's size dynamically.
Definition SDL3pp_ttf.h:2156
constexpr HintingFlags HINTING_LIGHT_SUBPIXEL
Light hinting with subpixel rendering for more precise font edges.
Definition SDL3pp_ttf.h:283
void DeleteString(int offset, int length)
Delete UTF-8 text from a text object.
Definition SDL3pp_ttf.h:6211
SurfaceTextEngine CreateSurfaceTextEngine()
Create a text engine for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:5095
void GetDPI(int *hdpi, int *vdpi) const
Get font target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:2227
Font OpenFont(StringParam file, float ptsize)
Create a font from a file, using a specified point size.
Definition SDL3pp_ttf.h:1818
void Destroy()
Destroy a text object created by a text engine.
Definition SDL3pp_ttf.h:6481
Uint32 GetFontScript(FontRef font)
Get the script used for text shaping a font.
Definition SDL3pp_ttf.h:2923
RendererTextEngine(RendererRef renderer)
Create a text engine for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:5181
void SetFontDirection(FontRef font, Direction direction)
Set the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2809
void SetHinting(HintingFlags hinting)
Set a font's current hinter setting.
Definition SDL3pp_ttf.h:2372
TTF_HintingFlags HintingFlags
Hinting flags for TTF (TrueType Fonts).
Definition SDL3pp_ttf.h:259
GPUAtlasDrawSequence * GetGPUDrawData() const
Get the geometry data needed for drawing the text.
Definition SDL3pp_ttf.h:5404
void SetFontSizeDPI(FontRef font, float ptsize, int hdpi, int vdpi)
Set font size dynamically with target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:2178
FColor GetColorFloat() const
Get the color of a text object.
Definition SDL3pp_ttf.h:5906
void GetGlyphMetrics(Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance) const
Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint.
Definition SDL3pp_ttf.h:3096
Uint32 GetScript() const
Get the script used for text shaping a font.
Definition SDL3pp_ttf.h:2925
void InsertTextString(TextRef text, int offset, std::string_view string)
Insert UTF-8 text into a text object.
Definition SDL3pp_ttf.h:6145
constexpr HorizontalAlignment HORIZONTAL_ALIGN_LEFT
LEFT.
Definition SDL3pp_ttf.h:295
bool FontIsScalable(FontRef font)
Query whether a font is scalable or not.
Definition SDL3pp_ttf.h:2736
constexpr int FONT_WEIGHT_SEMI_BOLD
SemiBold (600) named font weight value.
Definition SDL3pp_ttf.h:2500
Surface RenderGlyph_LCD(FontRef font, Uint32 ch, ColorRaw fg, ColorRaw bg)
Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3772
void CloseFont(FontRaw font)
Dispose of a previously-created font.
Definition SDL3pp_ttf.h:6505
Surface RenderGlyph_Blended(FontRef font, Uint32 ch, ColorRaw fg)
Render a single UNICODE codepoint at high quality to a new ARGB surface.
Definition SDL3pp_ttf.h:3634
int GetAscent() const
Query the offset from the baseline to the top of a font.
Definition SDL3pp_ttf.h:2594
PropertiesRef GetProperties()
Get the properties associated with a font.
Definition SDL3pp_ttf.h:2004
Uint32 GetScript() const
Get the script used for text shaping a text object.
Definition SDL3pp_ttf.h:5738
void DrawRendererText(TextConstRef text, FPoint p)
Draw text to an SDL renderer.
Definition SDL3pp_ttf.h:5260
int GetFontLineSkip(FontRef font)
Query the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:2649
int GetFontOutline(FontRef font)
Query a font's current outline.
Definition SDL3pp_ttf.h:2339
constexpr int FONT_WEIGHT_NORMAL
Normal (400) named font weight value.
Definition SDL3pp_ttf.h:2494
void GetStringSizeWrapped(FontRef font, std::string_view text, int wrap_width, int *w, int *h)
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:3181
int GetNumFontFaces(FontRef font)
Query the number of faces of a font.
Definition SDL3pp_ttf.h:2387
void SetFontSDF(FontRef font, bool enabled)
Enable Signed Distance Field rendering for a font.
Definition SDL3pp_ttf.h:2445
void SetTextString(TextRef text, std::string_view string)
Set the UTF-8 text used by a text object.
Definition SDL3pp_ttf.h:6113
PropertiesRef GetFontProperties(FontRef font)
Get the properties associated with a font.
Definition SDL3pp_ttf.h:1999
constexpr ImageType IMAGE_SDF
The alpha channel has signed distance field information.
Definition SDL3pp_ttf.h:343
constexpr int FONT_WEIGHT_LIGHT
Light (300) named font weight value.
Definition SDL3pp_ttf.h:2491
void Destroy() final
Destroy a text engine created for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:5429
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_CLOCKWISE
CLOCKWISE.
Definition SDL3pp_ttf.h:3821
GPUTextEngineWinding GetGPUTextEngineWinding(TextEngineRef engine)
Get the winding order of the vertices returned by Text.GetGPUDrawData for a particular GPU text engin...
Definition SDL3pp_ttf.h:5473
TTF_HorizontalAlignment HorizontalAlignment
The horizontal alignment used when rendering wrapped text.
Definition SDL3pp_ttf.h:290
Surface RenderGlyph_Shaded(FontRef font, Uint32 ch, ColorRaw fg, ColorRaw bg)
Render a single UNICODE codepoint at high quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:3502
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:290
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:238
ResourceRef< Surface > SurfaceRef
Reference for Surface.
Definition SDL3pp_surface.h:54
ResourceRef< Renderer > RendererRef
Reference for Renderer.
Definition SDL3pp_video.h:75
Properties for Font creation.
Definition SDL3pp_ttf.h:1917
constexpr auto HORIZONTAL_DPI_NUMBER
Number for horizontal dpi.
Definition SDL3pp_ttf.h:1938
constexpr auto IOSTREAM_AUTOCLOSE_BOOLEAN
Enable iostream autoclose.
Definition SDL3pp_ttf.h:1928
constexpr auto FILENAME_STRING
String for filename.
Definition SDL3pp_ttf.h:1919
constexpr auto IOSTREAM_OFFSET_NUMBER
Number for iostream offset.
Definition SDL3pp_ttf.h:1925
constexpr auto VERTICAL_DPI_NUMBER
Number for vertical dpi.
Definition SDL3pp_ttf.h:1941
constexpr auto SIZE_FLOAT
Float for size.
Definition SDL3pp_ttf.h:1932
constexpr auto IOSTREAM_POINTER
Pointer to iostream.
Definition SDL3pp_ttf.h:1922
constexpr auto EXISTING_FONT_POINTER
Pointer to existing font.
Definition SDL3pp_ttf.h:1946
constexpr auto FACE_NUMBER
Number for face.
Definition SDL3pp_ttf.h:1935
Properties for Font.
Definition SDL3pp_ttf.h:1917
constexpr auto OUTLINE_MITER_LIMIT_NUMBER
Number for outline miter limit.
Definition SDL3pp_ttf.h:2027
constexpr auto OUTLINE_LINE_JOIN_NUMBER
Number for outline line join.
Definition SDL3pp_ttf.h:2024
constexpr auto OUTLINE_LINE_CAP_NUMBER
Number for outline line cap.
Definition SDL3pp_ttf.h:2021
Properties for GPUTextEngine.
Definition SDL3pp_ttf.h:5363
constexpr auto ATLAS_TEXTURE_SIZE_NUMBER
Number for atlas texture size.
Definition SDL3pp_ttf.h:5368
constexpr auto DEVICE_POINTER
Pointer to device.
Definition SDL3pp_ttf.h:5365
Properties for RendererTextEngine.
Definition SDL3pp_ttf.h:5229
constexpr auto ATLAS_TEXTURE_SIZE_NUMBER
Number for atlas texture size.
Definition SDL3pp_ttf.h:5234
constexpr auto RENDERER_POINTER
Pointer to renderer.
Definition SDL3pp_ttf.h:5231
Main include header for the SDL3pp library.
A structure that represents a color as RGBA components.
Definition SDL3pp_pixels.h:2145
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition SDL3pp_pixels.h:2318
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:526
The internal structure containing font information.
Definition SDL3pp_ttf.h:353
Font & operator=(const Font &other)=delete
Assignment operator.
constexpr Font(Font &&other) noexcept
Move constructor.
Definition SDL3pp_ttf.h:372
~Font()
Destructor.
Definition SDL3pp_ttf.h:471
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Point GetStringSize(std::string_view text) const
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:1292
constexpr Font(FontRaw resource) noexcept
Constructs from raw Font.
Definition SDL3pp_ttf.h:363
constexpr Font & operator=(Font &&other) noexcept
Assignment operator.
Definition SDL3pp_ttf.h:474
constexpr Font(const Font &other)=delete
Copy constructor.
Point GetStringSizeWrapped(std::string_view text, int wrap_width) const
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:1338
A GPU based text engine.
Definition SDL3pp_ttf.h:4014
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:97
A renderer based text engine.
Definition SDL3pp_ttf.h:3945
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156
A surface based text engine.
Definition SDL3pp_ttf.h:3905
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:172
A text engine used to create text objects.
Definition SDL3pp_ttf.h:3845
constexpr TextEngine(TextEngineRaw resource) noexcept
Constructs from raw TextEngine.
Definition SDL3pp_ttf.h:3855
TextEngine & operator=(const TextEngine &other)=delete
Assignment operator.
constexpr TextEngine(const TextEngine &other)=delete
Copy constructor.
virtual void Destroy()=0
frees up textEngine. Pure virtual
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
virtual ~TextEngine()
Destructor.
Definition SDL3pp_ttf.h:3870
constexpr TextEngine & operator=(TextEngine &&other) noexcept
Assignment operator.
Definition SDL3pp_ttf.h:3873
constexpr TextEngine(TextEngine &&other) noexcept
Move constructor.
Definition SDL3pp_ttf.h:3864
Text created with TextEngine.CreateText().
Definition SDL3pp_ttf.h:4157
const char * GetText() const
A copy of the UTF-8 string that this text object represents, useful for layout, debugging and retriev...
Definition SDL3pp_ttf.h:5005
int GetNumLines() const
The number of lines in the text, 0 if it's empty.
Definition SDL3pp_ttf.h:5008
SubStringIterator GetSubStringForPoint(Point p) const
Get the portion of a text string that is closest to a point.
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Text & operator=(const Text &other)=delete
Assignment operator.
SubStringIterator begin() const
Get iterator to first substring.
SubStringIterator end() const
Get iterator to one past last substring.
~Text()
Destructor.
Definition SDL3pp_ttf.h:4208
OwnArray< SubString * > GetSubStrings() const
Get all substrings of a text object.
Definition SDL3pp_ttf.h:4891
constexpr Text(TextRaw resource) noexcept
Constructs from raw Text.
Definition SDL3pp_ttf.h:4167
constexpr Text & operator=(Text &&other) noexcept
Assignment operator.
Definition SDL3pp_ttf.h:4211
constexpr Text(const Text &other)=delete
Copy constructor.
SubStringIterator GetSubStringForLine(int line) const
Get iterator to substring of a text object that contains the given line.
constexpr Text(Text &&other) noexcept
Move constructor.
Definition SDL3pp_ttf.h:4176