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 FontBase;
29
30// Forward decl
31struct Font;
32
34using FontRaw = TTF_Font*;
35
42
43// Forward decl
44struct TextEngine;
45
47using TextEngineRaw = TTF_TextEngine*;
48
55
56// Forward decl
57struct TextBase;
58
59// Forward decl
60struct Text;
61
63using TextRaw = TTF_Text*;
64
66using TextRawConst = const TTF_Text*;
67
74
77
78#ifdef SDL3PP_DOC
79
85#define SDL_TTF_MAJOR_VERSION
86
87#define SDL_TTF_MINOR_VERSION
88
89#define SDL_TTF_MICRO_VERSION
90
92
96#define SDL_TTF_VERSION \
97 SDL_VERSIONNUM( \
98 SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION)
99
103#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \
104 ((SDL_TTF_MAJOR_VERSION >= X) && \
105 (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \
106 (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || \
107 SDL_TTF_MICRO_VERSION >= Z))
108
109#endif // SDL3PP_DOC
110
111namespace TTF {
112
122inline int Version() { return TTF_Version(); }
123
139inline void Init() { CheckError(TTF_Init()); }
140
161inline void Quit() { TTF_Quit(); }
162
185inline int WasInit() { return TTF_WasInit(); }
186
187} // namespace TTF
188
204inline void GetFreeTypeVersion(int* major, int* minor, int* patch)
205{
206 TTF_GetFreeTypeVersion(major, minor, patch);
207}
208
222inline void GetHarfBuzzVersion(int* major, int* minor, int* patch)
223{
224 TTF_GetHarfBuzzVersion(major, minor, patch);
225}
226
240
241constexpr FontStyleFlags STYLE_NORMAL = TTF_STYLE_NORMAL;
242
243constexpr FontStyleFlags STYLE_BOLD = TTF_STYLE_BOLD;
244
245constexpr FontStyleFlags STYLE_ITALIC = TTF_STYLE_ITALIC;
246
248 TTF_STYLE_UNDERLINE;
249
251 TTF_STYLE_STRIKETHROUGH;
252
265using HintingFlags = TTF_HintingFlags;
266
267#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
268
269constexpr HintingFlags HINTING_INVALID = TTF_HINTING_INVALID;
270
271#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
272
274 TTF_HINTING_NORMAL;
275
277constexpr HintingFlags HINTING_LIGHT = TTF_HINTING_LIGHT;
278
283constexpr HintingFlags HINTING_MONO = TTF_HINTING_MONO;
284
286constexpr HintingFlags HINTING_NONE = TTF_HINTING_NONE;
287
289constexpr HintingFlags HINTING_LIGHT_SUBPIXEL = TTF_HINTING_LIGHT_SUBPIXEL;
290
296using HorizontalAlignment = TTF_HorizontalAlignment;
297
299 TTF_HORIZONTAL_ALIGN_INVALID;
300
302 TTF_HORIZONTAL_ALIGN_LEFT;
303
305 TTF_HORIZONTAL_ALIGN_CENTER;
306
308 TTF_HORIZONTAL_ALIGN_RIGHT;
309
321using Direction = TTF_Direction;
322
323constexpr Direction DIRECTION_INVALID = TTF_DIRECTION_INVALID;
324
325constexpr Direction DIRECTION_LTR = TTF_DIRECTION_LTR;
326
327constexpr Direction DIRECTION_RTL = TTF_DIRECTION_RTL;
328
329constexpr Direction DIRECTION_TTB = TTF_DIRECTION_TTB;
330
331constexpr Direction DIRECTION_BTT = TTF_DIRECTION_BTT;
332
338using ImageType = TTF_ImageType;
339
340constexpr ImageType IMAGE_INVALID = TTF_IMAGE_INVALID;
341
343 TTF_IMAGE_ALPHA;
344
346 TTF_IMAGE_COLOR;
347
349constexpr ImageType IMAGE_SDF = TTF_IMAGE_SDF;
350
356struct FontBase : ResourceBaseT<FontRaw>
357{
359
380 void Close();
381
398 Font Copy() const;
399
420
435 Uint32 GetGeneration() const;
436
458 void AddFallback(FontRef fallback);
459
475 void RemoveFallback(FontRef fallback);
476
490 void ClearFallbacks();
491
508 void SetSize(float ptsize);
509
529 void SetSizeDPI(float ptsize, int hdpi, int vdpi);
530
545 float GetSize() const;
546
561 void GetDPI(int* hdpi, int* vdpi) const;
562
586 void SetStyle(FontStyleFlags style);
587
607 FontStyleFlags GetStyle() const;
608
629 void SetOutline(int outline);
630
642 int GetOutline() const;
643
667 void SetHinting(HintingFlags hinting);
668
678 int GetNumFaces() const;
679
700 HintingFlags GetHinting() const;
701
724 void SetSDF(bool enabled);
725
737 bool GetSDF() const;
738
739#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
740
751 int GetWeight() const;
752
753#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
754
770
783
795 int GetHeight() const;
796
808 int GetAscent() const;
809
821 int GetDescent() const;
822
837 void SetLineSkip(int lineskip);
838
850 int GetLineSkip() const;
851
871 void SetKerning(bool enabled);
872
884 bool GetKerning() const;
885
901 bool IsFixedWidth() const;
902
916 bool IsScalable() const;
917
933 const char* GetFamilyName() const;
934
950 const char* GetStyleName() const;
951
968 void SetDirection(Direction direction);
969
982 Direction GetDirection() const;
983
1002 void SetScript(Uint32 script);
1003
1018 Uint32 GetScript() const;
1019
1035 static Uint32 GetGlyphScript(Uint32 ch);
1036
1054 void SetLanguage(StringParam language_bcp47);
1055
1067 bool HasGlyph(Uint32 ch) const;
1068
1083 Surface GetGlyphImage(Uint32 ch, ImageType* image_type) const;
1084
1103 ImageType* image_type) const;
1104
1132 void GetGlyphMetrics(Uint32 ch,
1133 int* minx,
1134 int* maxx,
1135 int* miny,
1136 int* maxy,
1137 int* advance) const;
1138
1152 int GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const;
1153
1169 Point GetStringSize(std::string_view text) const
1170 {
1171 Point p;
1172 GetStringSize(text, &p.x, &p.y);
1173 return p;
1174 }
1175
1192 void GetStringSize(std::string_view text, int* w, int* h) const;
1193
1215 Point GetStringSizeWrapped(std::string_view text, int wrap_width) const
1216 {
1217 Point p;
1218 GetStringSizeWrapped(text, wrap_width, &p.x, &p.y);
1219 return p;
1220 }
1221
1244 void GetStringSizeWrapped(std::string_view text,
1245 int wrap_width,
1246 int* w,
1247 int* h) const;
1248
1271 void MeasureString(std::string_view text,
1272 int max_width,
1273 int* measured_width,
1274 size_t* measured_length) const;
1275
1308 Surface RenderText_Solid(std::string_view text, Color fg) const;
1309
1341 Surface RenderText_Solid_Wrapped(std::string_view text,
1342 Color fg,
1343 int wrapLength) const;
1344
1372
1406 Surface RenderText_Shaded(std::string_view text, Color fg, Color bg) const;
1407
1441 Surface RenderText_Shaded_Wrapped(std::string_view text,
1442 Color fg,
1443 Color bg,
1444 int wrap_width) const;
1445
1475
1507 Surface RenderText_Blended(std::string_view text, Color fg) const;
1508
1540 Surface RenderText_Blended_Wrapped(std::string_view text,
1541 Color fg,
1542 int wrap_width) const;
1543
1571
1604 Surface RenderText_LCD(std::string_view text, Color fg, Color bg) const;
1605
1639 Surface RenderText_LCD_Wrapped(std::string_view text,
1640 Color fg,
1641 Color bg,
1642 int wrap_width) const;
1643
1673};
1674
1683{
1684 using FontBase::FontBase;
1685
1693 constexpr explicit Font(FontRaw resource) noexcept
1694 : FontBase(resource)
1695 {
1696 }
1697
1699 constexpr Font(Font&& other) noexcept
1700 : Font(other.release())
1701 {
1702 }
1703
1722 Font(StringParam file, float ptsize);
1723
1747 Font(IOStreamRef src, float ptsize, bool closeio = false);
1748
1791 Font(PropertiesRef props);
1792
1794 ~Font() { TTF_CloseFont(get()); }
1795
1797 constexpr Font& operator=(Font&& other) noexcept
1798 {
1799 swap(*this, other);
1800 return *this;
1801 }
1802};
1803
1824inline Font OpenFont(StringParam file, float ptsize)
1825{
1826 return Font(file, ptsize);
1827}
1828
1829inline Font::Font(StringParam file, float ptsize)
1830 : Font(CheckError(TTF_OpenFont(file, ptsize)))
1831{
1832}
1833
1834inline Font::Font(IOStreamRef src, float ptsize, bool closeio)
1835 : Font(CheckError(TTF_OpenFontIO(src, closeio, ptsize)))
1836{
1837}
1838
1840 : Font(CheckError(TTF_OpenFontWithProperties(props)))
1841{
1842}
1843
1869inline Font OpenFontIO(IOStreamRef src, float ptsize, bool closeio = false)
1870{
1871 return Font(src, ptsize, closeio);
1872}
1873
1916inline Font OpenFontWithProperties(PropertiesRef props) { return Font(props); }
1917
1924
1925constexpr auto FILENAME_STRING =
1926 TTF_PROP_FONT_CREATE_FILENAME_STRING;
1927
1928constexpr auto IOSTREAM_POINTER =
1929 TTF_PROP_FONT_CREATE_IOSTREAM_POINTER;
1930
1932 TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER;
1933
1935 TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN;
1937
1938constexpr auto SIZE_FLOAT =
1939 TTF_PROP_FONT_CREATE_SIZE_FLOAT;
1940
1941constexpr auto FACE_NUMBER =
1942 TTF_PROP_FONT_CREATE_FACE_NUMBER;
1943
1945 TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER;
1946
1947constexpr auto VERTICAL_DPI_NUMBER =
1948 TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER;
1949
1950#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
1951
1953 TTF_PROP_FONT_CREATE_EXISTING_FONT;
1954
1955#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
1956
1957} // namespace prop::Font::Create
1958
1978inline Font CopyFont(FontRef existing_font)
1979{
1980 return Font(CheckError(TTF_CopyFont(existing_font)));
1981}
1982
1983inline Font FontBase::Copy() const { return SDL::CopyFont(get()); }
1984
2006{
2007 return CheckError(TTF_GetFontProperties(font));
2008}
2009
2014
2025namespace prop::Font {
2026
2028 TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER;
2029
2031 TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER;
2032
2034 TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER;
2035
2036} // namespace prop::Font
2037
2054{
2055 return TTF_GetFontGeneration(font);
2056}
2057
2059{
2060 return SDL::GetFontGeneration(get());
2061}
2062
2085inline void AddFallbackFont(FontRef font, FontRef fallback)
2086{
2087 CheckError(TTF_AddFallbackFont(font, fallback));
2088}
2089
2090inline void FontBase::AddFallback(FontRef fallback)
2091{
2092 SDL::AddFallbackFont(get(), fallback);
2093}
2094
2111inline void RemoveFallbackFont(FontRef font, FontRef fallback)
2112{
2113 TTF_RemoveFallbackFont(font, fallback);
2114}
2115
2117{
2118 SDL::RemoveFallbackFont(get(), fallback);
2119}
2120
2136inline void ClearFallbackFonts(FontRef font) { TTF_ClearFallbackFonts(font); }
2137
2139
2157inline void SetFontSize(FontRef font, float ptsize)
2158{
2159 CheckError(TTF_SetFontSize(font, ptsize));
2160}
2161
2162inline void FontBase::SetSize(float ptsize) { SDL::SetFontSize(get(), ptsize); }
2163
2184inline void SetFontSizeDPI(FontRef font, float ptsize, int hdpi, int vdpi)
2185{
2186 CheckError(TTF_SetFontSizeDPI(font, ptsize, hdpi, vdpi));
2187}
2188
2189inline void FontBase::SetSizeDPI(float ptsize, int hdpi, int vdpi)
2190{
2191 SDL::SetFontSizeDPI(get(), ptsize, hdpi, vdpi);
2192}
2193
2209inline float GetFontSize(FontRef font) { return TTF_GetFontSize(font); }
2210
2211inline float FontBase::GetSize() const { return SDL::GetFontSize(get()); }
2212
2228inline void GetFontDPI(FontRef font, int* hdpi, int* vdpi)
2229{
2230 CheckError(TTF_GetFontDPI(font, hdpi, vdpi));
2231}
2232
2233inline void FontBase::GetDPI(int* hdpi, int* vdpi) const
2234{
2235 SDL::GetFontDPI(get(), hdpi, vdpi);
2236}
2237
2262inline void SetFontStyle(FontRef font, FontStyleFlags style)
2263{
2264 TTF_SetFontStyle(font, style);
2265}
2266
2268{
2269 SDL::SetFontStyle(get(), style);
2270}
2271
2293{
2294 return TTF_GetFontStyle(font);
2295}
2296
2298{
2299 return SDL::GetFontStyle(get());
2300}
2301
2323inline void SetFontOutline(FontRef font, int outline)
2324{
2325 CheckError(TTF_SetFontOutline(font, outline));
2326}
2327
2328inline void FontBase::SetOutline(int outline)
2329{
2330 SDL::SetFontOutline(get(), outline);
2331}
2332
2345inline int GetFontOutline(FontRef font) { return TTF_GetFontOutline(font); }
2346
2347inline int FontBase::GetOutline() const { return SDL::GetFontOutline(get()); }
2348
2373inline void SetFontHinting(FontRef font, HintingFlags hinting)
2374{
2375 TTF_SetFontHinting(font, hinting);
2376}
2377
2379{
2380 SDL::SetFontHinting(get(), hinting);
2381}
2382
2393inline int GetNumFontFaces(FontRef font) { return TTF_GetNumFontFaces(font); }
2394
2395inline int FontBase::GetNumFaces() const { return SDL::GetNumFontFaces(get()); }
2396
2419{
2420 return TTF_GetFontHinting(font);
2421}
2422
2424{
2425 return SDL::GetFontHinting(get());
2426}
2427
2451inline void SetFontSDF(FontRef font, bool enabled)
2452{
2453 CheckError(TTF_SetFontSDF(font, enabled));
2454}
2455
2456inline void FontBase::SetSDF(bool enabled) { SDL::SetFontSDF(get(), enabled); }
2457
2470inline bool GetFontSDF(FontRef font) { return TTF_GetFontSDF(font); }
2471
2472inline bool FontBase::GetSDF() const { return SDL::GetFontSDF(get()); }
2473
2474#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
2475
2487inline int GetFontWeight(FontRef font) { return TTF_GetFontWeight(font); }
2488
2489inline int FontBase::GetWeight() const { return SDL::GetFontWeight(get()); }
2490
2491constexpr int FONT_WEIGHT_THIN =
2492 TTF_FONT_WEIGHT_THIN;
2493
2495 TTF_FONT_WEIGHT_EXTRA_LIGHT;
2496
2497constexpr int FONT_WEIGHT_LIGHT =
2498 TTF_FONT_WEIGHT_LIGHT;
2499
2500constexpr int FONT_WEIGHT_NORMAL =
2501 TTF_FONT_WEIGHT_NORMAL;
2502
2503constexpr int FONT_WEIGHT_MEDIUM =
2504 TTF_FONT_WEIGHT_MEDIUM;
2505
2507 TTF_FONT_WEIGHT_SEMI_BOLD;
2508
2509constexpr int FONT_WEIGHT_BOLD =
2510 TTF_FONT_WEIGHT_BOLD;
2511
2513 TTF_FONT_WEIGHT_EXTRA_BOLD;
2514
2515constexpr int FONT_WEIGHT_BLACK =
2516 TTF_FONT_WEIGHT_BLACK;
2517
2519 TTF_FONT_WEIGHT_EXTRA_BLACK;
2520
2521#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
2522
2539{
2540 TTF_SetFontWrapAlignment(font, align);
2541}
2542
2547
2561{
2562 return TTF_GetFontWrapAlignment(font);
2563}
2564
2569
2582inline int GetFontHeight(FontRef font) { return TTF_GetFontHeight(font); }
2583
2584inline int FontBase::GetHeight() const { return SDL::GetFontHeight(get()); }
2585
2598inline int GetFontAscent(FontRef font) { return TTF_GetFontAscent(font); }
2599
2600inline int FontBase::GetAscent() const { return SDL::GetFontAscent(get()); }
2601
2614inline int GetFontDescent(FontRef font) { return TTF_GetFontDescent(font); }
2615
2616inline int FontBase::GetDescent() const { return SDL::GetFontDescent(get()); }
2617
2633inline void SetFontLineSkip(FontRef font, int lineskip)
2634{
2635 TTF_SetFontLineSkip(font, lineskip);
2636}
2637
2638inline void FontBase::SetLineSkip(int lineskip)
2639{
2640 SDL::SetFontLineSkip(get(), lineskip);
2641}
2642
2655inline int GetFontLineSkip(FontRef font) { return TTF_GetFontLineSkip(font); }
2656
2657inline int FontBase::GetLineSkip() const { return SDL::GetFontLineSkip(get()); }
2658
2679inline void SetFontKerning(FontRef font, bool enabled)
2680{
2681 TTF_SetFontKerning(font, enabled);
2682}
2683
2684inline void FontBase::SetKerning(bool enabled)
2685{
2686 SDL::SetFontKerning(get(), enabled);
2687}
2688
2701inline bool GetFontKerning(FontRef font) { return TTF_GetFontKerning(font); }
2702
2703inline bool FontBase::GetKerning() const { return SDL::GetFontKerning(get()); }
2704
2721inline bool FontIsFixedWidth(FontRef font)
2722{
2723 return TTF_FontIsFixedWidth(font);
2724}
2725
2726inline bool FontBase::IsFixedWidth() const
2727{
2728 return SDL::FontIsFixedWidth(get());
2729}
2730
2745inline bool FontIsScalable(FontRef font) { return TTF_FontIsScalable(font); }
2746
2747inline bool FontBase::IsScalable() const { return SDL::FontIsScalable(get()); }
2748
2765inline const char* GetFontFamilyName(FontRef font)
2766{
2767 return TTF_GetFontFamilyName(font);
2768}
2769
2770inline const char* FontBase::GetFamilyName() const
2771{
2772 return SDL::GetFontFamilyName(get());
2773}
2774
2791inline const char* GetFontStyleName(FontRef font)
2792{
2793 return TTF_GetFontStyleName(font);
2794}
2795
2796inline const char* FontBase::GetStyleName() const
2797{
2798 return SDL::GetFontStyleName(get());
2799}
2800
2818inline void SetFontDirection(FontRef font, Direction direction)
2819{
2820 CheckError(TTF_SetFontDirection(font, direction));
2821}
2822
2823inline void FontBase::SetDirection(Direction direction)
2824{
2825 SDL::SetFontDirection(get(), direction);
2826}
2827
2842{
2843 return TTF_GetFontDirection(font);
2844}
2845
2847{
2848 return SDL::GetFontDirection(get());
2849}
2850
2864{
2865 return TTF_StringToTag(string);
2866}
2867
2883inline void TagToString(Uint32 tag, char* string, size_t size)
2884{
2885 TTF_TagToString(tag, string, size);
2886}
2887
2907inline void SetFontScript(FontRef font, Uint32 script)
2908{
2909 CheckError(TTF_SetFontScript(font, script));
2910}
2911
2912inline void FontBase::SetScript(Uint32 script)
2913{
2914 SDL::SetFontScript(get(), script);
2915}
2916
2932inline Uint32 GetFontScript(FontRef font) { return TTF_GetFontScript(font); }
2933
2935
2951{
2952 return CheckError(TTF_GetGlyphScript(ch));
2953}
2954
2956{
2957 return SDL::GetGlyphScript(ch);
2958}
2959
2977inline void SetFontLanguage(FontRef font, StringParam language_bcp47)
2978{
2979 CheckError(TTF_SetFontLanguage(font, language_bcp47));
2980}
2981
2982inline void FontBase::SetLanguage(StringParam language_bcp47)
2983{
2984 SDL::SetFontLanguage(get(), language_bcp47);
2985}
2986
2999inline bool FontHasGlyph(FontRef font, Uint32 ch)
3000{
3001 return TTF_FontHasGlyph(font, ch);
3002}
3003
3004inline bool FontBase::HasGlyph(Uint32 ch) const
3005{
3006 return SDL::FontHasGlyph(get(), ch);
3007}
3008
3024inline Surface GetGlyphImage(FontRef font, Uint32 ch, ImageType* image_type)
3025{
3026 return Surface{CheckError(TTF_GetGlyphImage(font, ch, image_type))};
3027}
3028
3030{
3031 return SDL::GetGlyphImage(get(), ch, image_type);
3032}
3033
3053 Uint32 glyph_index,
3054 ImageType* image_type)
3055{
3056 return Surface(
3057 CheckError(TTF_GetGlyphImageForIndex(font, glyph_index, image_type)));
3058}
3059
3061 ImageType* image_type) const
3062{
3063 return SDL::GetGlyphImageForIndex(get(), glyph_index, image_type);
3064}
3065
3094inline void GetGlyphMetrics(FontRef font,
3095 Uint32 ch,
3096 int* minx,
3097 int* maxx,
3098 int* miny,
3099 int* maxy,
3100 int* advance)
3101{
3102 CheckError(TTF_GetGlyphMetrics(font, ch, minx, maxx, miny, maxy, advance));
3103}
3104
3106 int* minx,
3107 int* maxx,
3108 int* miny,
3109 int* maxy,
3110 int* advance) const
3111{
3112 SDL::GetGlyphMetrics(get(), ch, minx, maxx, miny, maxy, advance);
3113}
3114
3129inline int GetGlyphKerning(FontRef font, Uint32 previous_ch, Uint32 ch)
3130{
3131 if (int r; TTF_GetGlyphKerning(font, previous_ch, ch, &r)) return r;
3132 throw Error();
3133}
3134
3135inline int FontBase::GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const
3136{
3137 return SDL::GetGlyphKerning(get(), previous_ch, ch);
3138}
3139
3157inline void GetStringSize(FontRef font, std::string_view text, int* w, int* h)
3158{
3159 CheckError(TTF_GetStringSize(font, text.data(), text.size(), w, h));
3160}
3161
3162inline void FontBase::GetStringSize(std::string_view text, int* w, int* h) const
3163{
3164 SDL::GetStringSize(get(), text, w, h);
3165}
3166
3191 std::string_view text,
3192 int wrap_width,
3193 int* w,
3194 int* h)
3195{
3196 CheckError(
3197 TTF_GetStringSizeWrapped(font, text.data(), text.size(), wrap_width, w, h));
3198}
3199
3200inline void FontBase::GetStringSizeWrapped(std::string_view text,
3201 int wrap_width,
3202 int* w,
3203 int* h) const
3204{
3205 SDL::GetStringSizeWrapped(get(), text, wrap_width, w, h);
3206}
3207
3231inline void MeasureString(FontRef font,
3232 std::string_view text,
3233 int max_width,
3234 int* measured_width,
3235 size_t* measured_length)
3236{
3237 CheckError(TTF_MeasureString(font,
3238 text.data(),
3239 text.size(),
3240 max_width,
3241 measured_width,
3242 measured_length));
3243}
3244
3245inline void FontBase::MeasureString(std::string_view text,
3246 int max_width,
3247 int* measured_width,
3248 size_t* measured_length) const
3249{
3250 SDL::MeasureString(get(), text, max_width, measured_width, measured_length);
3251}
3252
3286inline Surface RenderText_Solid(FontRef font, std::string_view text, Color fg)
3287{
3288 return Surface{TTF_RenderText_Solid(font, text.data(), text.size(), fg)};
3289}
3290
3291inline Surface FontBase::RenderText_Solid(std::string_view text, Color fg) const
3292{
3293 return SDL::RenderText_Solid(get(), text, fg);
3294}
3295
3329 std::string_view text,
3330 Color fg,
3331 int wrapLength)
3332{
3333 return Surface(TTF_RenderText_Solid_Wrapped(
3334 font, text.data(), text.size(), fg, wrapLength));
3335}
3336
3337inline Surface FontBase::RenderText_Solid_Wrapped(std::string_view text,
3338 Color fg,
3339 int wrapLength) const
3340{
3341 return SDL::RenderText_Solid_Wrapped(get(), text, fg, wrapLength);
3342}
3343
3372{
3373 return Surface(TTF_RenderGlyph_Solid(font, ch, fg));
3374}
3375
3377{
3378 return SDL::RenderGlyph_Solid(get(), ch, fg);
3379}
3380
3416 std::string_view text,
3417 Color fg,
3418 Color bg)
3419{
3420 return Surface(TTF_RenderText_Shaded(font, text.data(), text.size(), fg, bg));
3421}
3422
3423inline Surface FontBase::RenderText_Shaded(std::string_view text,
3424 Color fg,
3425 Color bg) const
3426{
3427 return SDL::RenderText_Shaded(get(), text, fg, bg);
3428}
3429
3465 std::string_view text,
3466 Color fg,
3467 Color bg,
3468 int wrap_width)
3469{
3470 return Surface(TTF_RenderText_Shaded_Wrapped(
3471 font, text.data(), text.size(), fg, bg, wrap_width));
3472}
3473
3475 Color fg,
3476 Color bg,
3477 int wrap_width) const
3478{
3479 return SDL::RenderText_Shaded_Wrapped(get(), text, fg, bg, wrap_width);
3480}
3481
3512 Uint32 ch,
3513 ColorRaw fg,
3514 ColorRaw bg)
3515{
3516 return Surface(TTF_RenderGlyph_Shaded(font, ch, fg, bg));
3517}
3518
3520 ColorRaw fg,
3521 ColorRaw bg) const
3522{
3523 return SDL::RenderGlyph_Shaded(get(), ch, fg, bg);
3524}
3525
3558inline Surface RenderText_Blended(FontRef font, std::string_view text, Color fg)
3559{
3560 return Surface(TTF_RenderText_Blended(font, text.data(), text.size(), fg));
3561}
3562
3563inline Surface FontBase::RenderText_Blended(std::string_view text,
3564 Color fg) const
3565{
3566 return SDL::RenderText_Blended(get(), text, fg);
3567}
3568
3602 std::string_view text,
3603 Color fg,
3604 int wrap_width)
3605{
3606 return Surface(TTF_RenderText_Blended_Wrapped(
3607 font, text.data(), text.size(), fg, wrap_width));
3608}
3609
3611 Color fg,
3612 int wrap_width) const
3613{
3614 return SDL::RenderText_Blended_Wrapped(get(), text, fg, wrap_width);
3615}
3616
3645{
3646 return Surface(TTF_RenderGlyph_Blended(font, ch, fg));
3647}
3648
3650{
3651 return SDL::RenderGlyph_Blended(get(), ch, fg);
3652}
3653
3687 std::string_view text,
3688 Color fg,
3689 Color bg)
3690{
3691 return Surface(TTF_RenderText_LCD(font, text.data(), text.size(), fg, bg));
3692}
3693
3694inline Surface FontBase::RenderText_LCD(std::string_view text,
3695 Color fg,
3696 Color bg) const
3697{
3698 return SDL::RenderText_LCD(get(), text, fg, bg);
3699}
3700
3735 std::string_view text,
3736 Color fg,
3737 Color bg,
3738 int wrap_width)
3739{
3740 return Surface(TTF_RenderText_LCD_Wrapped(
3741 font, text.data(), text.size(), fg, bg, wrap_width));
3742}
3743
3744inline Surface FontBase::RenderText_LCD_Wrapped(std::string_view text,
3745 Color fg,
3746 Color bg,
3747 int wrap_width) const
3748{
3749 return SDL::RenderText_LCD_Wrapped(get(), text, fg, bg, wrap_width);
3750}
3751
3782 Uint32 ch,
3783 ColorRaw fg,
3784 ColorRaw bg)
3785{
3786 return Surface(TTF_RenderGlyph_LCD(font, ch, fg, bg));
3787}
3788
3790 ColorRaw fg,
3791 ColorRaw bg) const
3792{
3793 return SDL::RenderGlyph_LCD(get(), ch, fg, bg);
3794}
3795
3804
3806 TTF_SUBSTRING_DIRECTION_MASK;
3808
3810 TTF_SUBSTRING_TEXT_START;
3812
3814constexpr SubStringFlags SUBSTRING_LINE_START = TTF_SUBSTRING_LINE_START;
3815
3817constexpr SubStringFlags SUBSTRING_LINE_END = TTF_SUBSTRING_LINE_END;
3818
3820 TTF_SUBSTRING_TEXT_END;
3821
3827using GPUTextEngineWinding = TTF_GPUTextEngineWinding;
3828
3830 TTF_GPU_TEXTENGINE_WINDING_INVALID;
3831
3833 TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE;
3834
3836 TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE;
3837
3855struct TextEngine : ResourceBaseT<TextEngineRaw>
3856{
3858
3874 Text CreateText(FontRef font, std::string_view text);
3875};
3876
3879{
3880 using TextEngine::TextEngine;
3881
3889 constexpr explicit SurfaceTextEngine(TextEngineRaw resource) noexcept
3890 : TextEngine(resource)
3891 {
3892 }
3893
3895 constexpr SurfaceTextEngine(SurfaceTextEngine&& other) noexcept
3896 : TextEngine(other.release())
3897 {
3898 }
3899
3901 constexpr SurfaceTextEngine& operator=(SurfaceTextEngine&& other) noexcept
3902 {
3903 swap(*this, other);
3904 return *this;
3905 }
3906
3921
3924
3938 void Destroy();
3939};
3940
3943{
3944 using TextEngine::TextEngine;
3945
3953 constexpr explicit RendererTextEngine(TextEngineRaw resource) noexcept
3954 : TextEngine(resource)
3955 {
3956 }
3957
3959 constexpr RendererTextEngine(RendererTextEngine&& other) noexcept
3960 : TextEngine(other.release())
3961 {
3962 }
3963
3966 {
3967 swap(*this, other);
3968 return *this;
3969 }
3970
3988
4014
4017
4031 void Destroy();
4032};
4033
4036{
4037 using TextEngine::TextEngine;
4038
4046 constexpr explicit GPUTextEngine(TextEngineRaw resource) noexcept
4047 : TextEngine(resource)
4048 {
4049 }
4050
4052 constexpr GPUTextEngine(GPUTextEngine&& other) noexcept
4053 : TextEngine(other.release())
4054 {
4055 }
4056
4058 constexpr GPUTextEngine& operator=(GPUTextEngine&& other) noexcept
4059 {
4060 swap(*this, other);
4061 return *this;
4062 }
4063
4081
4107
4110
4124 void SetGPUWinding(GPUTextEngineWinding winding);
4125
4141
4155 void Destroy();
4156};
4157
4165using GPUAtlasDrawSequence = TTF_GPUAtlasDrawSequence;
4166
4179using SubString = TTF_SubString;
4180
4181// Forward decl
4182struct SubStringIterator;
4183
4189using TextData = TTF_TextData;
4190
4196struct TextBase : ResourceBaseT<TextRaw, TextRawConst>
4197{
4199
4201 constexpr operator TextConstRef() const noexcept { return get(); }
4202
4213 void Destroy();
4214
4234 void DrawSurface(Point p, SurfaceRef surface) const;
4235
4255 void DrawRenderer(FPoint p) const;
4256
4284
4297
4313 void SetEngine(TextEngineRef engine);
4314
4328 TextEngineRef GetEngine() const;
4329
4350 bool SetFont(FontRef font);
4351
4365 FontRef GetFont() const;
4366
4381 void SetDirection(Direction direction);
4382
4395 Direction GetDirection() const;
4396
4413 void SetScript(Uint32 script);
4414
4431 Uint32 GetScript() const;
4432
4449 void SetColor(Color c);
4450
4467 void SetColorFloat(FColor c);
4468
4490 void GetColor(Uint8* r, Uint8* g, Uint8* b, Uint8* a) const;
4491
4506 Color GetColor() const;
4507
4529 void GetColorFloat(float* r, float* g, float* b, float* a) const;
4530
4545 FColor GetColorFloat() const;
4546
4565 void SetPosition(const PointRaw& p);
4566
4583 void GetPosition(int* x, int* y) const;
4584
4599 Point GetPosition() const;
4600
4617 void SetWrapWidth(int wrap_width);
4618
4633 int GetWrapWidth() const;
4634
4656 void SetWrapWhitespaceVisible(bool visible);
4657
4671 bool IsWrapWhitespaceVisible() const;
4672
4690 void SetString(std::string_view string);
4691
4713 void InsertString(int offset, std::string_view string);
4714
4732 void AppendString(std::string_view string);
4733
4756 void DeleteString(int offset, int length);
4757
4775 void GetSize(int* w, int* h) const;
4776
4793 Point GetSize() const;
4794
4814 void GetSubString(int offset, SubString* substring) const;
4815
4820
4825
4842
4861 void GetSubStringForLine(int line, SubString* substring) const;
4862
4875 {
4876 return GetSubStringsForRange(0);
4877 }
4878
4895 OwnArray<SubString*> GetSubStringsForRange(int offset, int length = -1) const;
4896
4913
4930 void GetSubStringForPoint(Point p, SubString* substring) const;
4931
4948 void GetPreviousSubString(const SubString& substring,
4949 SubString* previous) const;
4950
4966 void GetNextSubString(const SubString& substring, SubString* next) const;
4967
4982 void Update();
4983
4988 const char* GetText() const { return get()->text; }
4989
4991 int GetNumLines() const { return get()->num_lines; }
4992};
4993
5006{
5007 using TextBase::TextBase;
5008
5016 constexpr explicit Text(TextRaw resource) noexcept
5017 : TextBase(resource)
5018 {
5019 }
5020
5022 constexpr Text(Text&& other) noexcept
5023 : Text(other.release())
5024 {
5025 }
5026
5044 Text(TextEngineRef engine, FontRef font, std::string_view text);
5045
5047 ~Text() { TTF_DestroyText(get()); }
5048
5050 constexpr Text& operator=(Text&& other) noexcept
5051 {
5052 swap(*this, other);
5053 return *this;
5054 }
5055};
5056
5061class SubStringIterator
5062{
5063 TextRef m_text;
5064
5065 SubString m_subString;
5066
5068 : m_text(text)
5069 , m_subString()
5070 {
5071 }
5072
5073public:
5076 : SubStringIterator(TextRef{})
5077 {
5078 }
5079
5081 constexpr operator bool() const { return bool(m_text); }
5082
5084 constexpr const SubString& operator*() const { return m_subString; }
5085
5087 constexpr const SubString* operator->() const { return &m_subString; }
5088
5090 constexpr bool operator==(const SubStringIterator& other) const
5091 {
5092 return m_subString.offset == other.m_subString.offset;
5093 }
5094
5096 SubStringIterator& operator++()
5097 {
5098 m_text.GetNextSubString(m_subString, &m_subString);
5099 return *this;
5100 }
5101
5103 SubStringIterator operator++(int)
5104 {
5105 auto curr = *this;
5106 m_text.GetNextSubString(m_subString, &m_subString);
5107 return curr;
5108 }
5109
5111 SubStringIterator& operator--()
5112 {
5113 m_text.GetPreviousSubString(m_subString, &m_subString);
5114 return *this;
5115 }
5116
5118 SubStringIterator operator--(int)
5119 {
5120 auto curr = *this;
5121 m_text.GetPreviousSubString(m_subString, &m_subString);
5122 return curr;
5123 }
5124
5125 friend class Text;
5126};
5127
5145
5147 : TextEngine(TTF_CreateSurfaceTextEngine())
5148{
5149}
5150
5171inline void DrawSurfaceText(TextConstRef text, Point p, SurfaceRef surface)
5172{
5173 CheckError(TTF_DrawSurfaceText(text, p.x, p.y, surface));
5174}
5175
5176inline void TextBase::DrawSurface(Point p, SurfaceRef surface) const
5177{
5178 SDL::DrawSurfaceText(get(), p, surface);
5179}
5180
5197{
5198 TTF_DestroySurfaceTextEngine(engine);
5199}
5200
5205
5223{
5224 return RendererTextEngine(renderer);
5225}
5226
5228 : TextEngine(TTF_CreateRendererTextEngine(renderer))
5229{
5230}
5231
5233 : TextEngine(TTF_CreateRendererTextEngineWithProperties(props))
5234{
5235}
5236
5266
5276
5277constexpr auto RENDERER_POINTER =
5278 TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER;
5279
5281 TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE;
5283
5284} // namespace prop::RendererTextEngine
5285
5307{
5308 CheckError(TTF_DrawRendererText(text, p.x, p.y));
5309}
5310
5311inline void TextBase::DrawRenderer(FPoint p) const
5312{
5314}
5315
5332{
5333 TTF_DestroyRendererTextEngine(engine);
5334}
5335
5340
5358{
5359 return GPUTextEngine(device);
5360}
5361
5363 : TextEngine(TTF_CreateGPUTextEngine(device))
5364{
5365}
5366
5368 : TextEngine(TTF_CreateGPUTextEngineWithProperties(props))
5369{
5370}
5371
5400
5410
5411constexpr auto DEVICE_POINTER =
5412 TTF_PROP_GPU_TEXT_ENGINE_DEVICE;
5413
5415 TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE;
5417
5418} // namespace prop::GpuTextEngine
5419
5446{
5447 return TTF_GetGPUTextDrawData(text);
5448}
5449
5454
5471{
5472 TTF_DestroyGPUTextEngine(engine);
5473}
5474
5476
5493 GPUTextEngineWinding winding)
5494{
5495 TTF_SetGPUTextEngineWinding(engine, winding);
5496}
5497
5502
5520{
5521 return TTF_GetGPUTextEngineWinding(engine);
5522}
5523
5528
5547 FontRef font,
5548 std::string_view text)
5549{
5550 return Text(engine, font, text);
5551}
5552
5553inline Text TextEngine::CreateText(FontRef font, std::string_view text)
5554{
5555 return Text(get(), font, text);
5556}
5557
5558inline Text::Text(TextEngineRef engine, FontRef font, std::string_view text)
5559 : Text(TTF_CreateText(engine, font, text.data(), text.size()))
5560{
5561}
5562
5576{
5577 return {CheckError(TTF_GetTextProperties(text))};
5578}
5579
5581{
5582 return SDL::GetTextProperties(get());
5583}
5584
5601inline void SetTextEngine(TextRef text, TextEngineRef engine)
5602{
5603 CheckError(TTF_SetTextEngine(text, engine));
5604}
5605
5607{
5608 SDL::SetTextEngine(get(), engine);
5609}
5610
5626{
5627 return CheckError(TTF_GetTextEngine(text));
5628}
5629
5631{
5632 return SDL::GetTextEngine(get());
5633}
5634
5656inline bool SetTextFont(TextRef text, FontRef font)
5657{
5658 return TTF_SetTextFont(text, font);
5659}
5660
5662{
5663 return SDL::SetTextFont(get(), font);
5664}
5665
5681{
5682 return CheckError(TTF_GetTextFont(text));
5683}
5684
5685inline FontRef TextBase::GetFont() const { return SDL::GetTextFont(get()); }
5686
5702inline void SetTextDirection(TextRef text, Direction direction)
5703{
5704 CheckError(TTF_SetTextDirection(text, direction));
5705}
5706
5707inline void TextBase::SetDirection(Direction direction)
5708{
5709 SDL::SetTextDirection(get(), direction);
5710}
5711
5726{
5727 return TTF_GetTextDirection(text);
5728}
5729
5731{
5732 return SDL::GetTextDirection(get());
5733}
5734
5752inline void SetTextScript(TextRef text, Uint32 script)
5753{
5754 CheckError(TTF_SetTextScript(text, script));
5755}
5756
5757inline void TextBase::SetScript(Uint32 script)
5758{
5759 SDL::SetTextScript(get(), script);
5760}
5761
5780{
5781 return TTF_GetTextScript(text);
5782}
5783
5785
5803inline void SetTextColor(TextRef text, Color c)
5804{
5805 CheckError(TTF_SetTextColor(text, c.r, c.g, c.b, c.a));
5806}
5807
5809
5828{
5829 CheckError(TTF_SetTextColorFloat(text, c.r, c.g, c.b, c.a));
5830}
5831
5833
5857 Uint8* r,
5858 Uint8* g,
5859 Uint8* b,
5860 Uint8* a)
5861{
5862 CheckError(TTF_GetTextColor(text, r, g, b, a));
5863}
5864
5881{
5882 Color c;
5883 GetTextColor(text, &c.r, &c.g, &c.b, &c.a);
5884 return c;
5885}
5886
5887inline void TextBase::GetColor(Uint8* r, Uint8* g, Uint8* b, Uint8* a) const
5888{
5889 SDL::GetTextColor(get(), r, g, b, a);
5890}
5891
5892inline Color TextBase::GetColor() const { return SDL::GetTextColor(get()); }
5893
5917 float* r,
5918 float* g,
5919 float* b,
5920 float* a)
5921{
5922 CheckError(TTF_GetTextColorFloat(text, r, g, b, a));
5923}
5924
5941{
5942 FColor c;
5943 GetTextColorFloat(text, &c.r, &c.g, &c.b, &c.a);
5944 return c;
5945}
5946
5947inline void TextBase::GetColorFloat(float* r,
5948 float* g,
5949 float* b,
5950 float* a) const
5951{
5952 SDL::GetTextColorFloat(get(), r, g, b, a);
5953}
5954
5956{
5957 return SDL::GetTextColorFloat(get());
5958}
5959
5979inline void SetTextPosition(TextRef text, const PointRaw& p)
5980{
5981 CheckError(TTF_SetTextPosition(text, p.x, p.y));
5982}
5983
5984inline void TextBase::SetPosition(const PointRaw& p)
5985{
5987}
5988
6006inline void GetTextPosition(TextConstRef text, int* x, int* y)
6007{
6008 CheckError(TTF_GetTextPosition(text, x, y));
6009}
6010
6027{
6028 Point p;
6029 GetTextPosition(text, &p.x, &p.y);
6030 return p;
6031}
6032
6033inline void TextBase::GetPosition(int* x, int* y) const
6034{
6035 SDL::GetTextPosition(get(), x, y);
6036}
6037
6038inline Point TextBase::GetPosition() const { return GetTextPosition(get()); }
6039
6057inline void SetTextWrapWidth(TextRef text, int wrap_width)
6058{
6059 CheckError(TTF_SetTextWrapWidth(text, wrap_width));
6060}
6061
6062inline void TextBase::SetWrapWidth(int wrap_width)
6063{
6064 SDL::SetTextWrapWidth(get(), wrap_width);
6065}
6066
6083{
6084 int w;
6085 CheckError(TTF_GetTextWrapWidth(text, &w));
6086 return w;
6087}
6088
6089inline int TextBase::GetWrapWidth() const { return GetTextWrapWidth(get()); }
6090
6111inline void SetTextWrapWhitespaceVisible(TextRef text, bool visible)
6112{
6113 CheckError(TTF_SetTextWrapWhitespaceVisible(text, visible));
6114}
6115
6116inline void TextBase::SetWrapWhitespaceVisible(bool visible)
6117{
6119}
6120
6135{
6136 return TTF_TextWrapWhitespaceVisible(text);
6137}
6138
6140{
6142}
6143
6162inline void SetTextString(TextRef text, std::string_view string)
6163{
6164 CheckError(TTF_SetTextString(text, string.data(), string.size()));
6165}
6166
6167inline void TextBase::SetString(std::string_view string)
6168{
6169 SDL::SetTextString(get(), string);
6170}
6171
6194inline void InsertTextString(TextRef text, int offset, std::string_view string)
6195{
6196 CheckError(TTF_InsertTextString(text, offset, string.data(), string.size()));
6197}
6198
6199inline void TextBase::InsertString(int offset, std::string_view string)
6200{
6201 SDL::InsertTextString(get(), offset, string);
6202}
6203
6222inline void AppendTextString(TextRef text, std::string_view string)
6223{
6224 CheckError(TTF_AppendTextString(text, string.data(), string.size()));
6225}
6226
6227inline void TextBase::AppendString(std::string_view string)
6228{
6229 SDL::AppendTextString(get(), string);
6230}
6231
6255inline void DeleteTextString(TextRef text, int offset, int length)
6256{
6257 CheckError(TTF_DeleteTextString(text, offset, length));
6258}
6259
6260inline void TextBase::DeleteString(int offset, int length)
6261{
6262 SDL::DeleteTextString(get(), offset, length);
6263}
6264
6282inline void GetTextSize(TextConstRef text, int* w, int* h)
6283{
6284 CheckError(TTF_GetTextSize(text, w, h));
6285}
6286
6303{
6304 Point p;
6305 GetTextSize(text, &p.x, &p.y);
6306 return p;
6307}
6308
6309inline void TextBase::GetSize(int* w, int* h) const
6310{
6311 SDL::GetTextSize(get(), w, h);
6312}
6313
6314inline Point TextBase::GetSize() const { return GetTextSize(get()); }
6315
6337 int offset,
6338 SubString* substring)
6339{
6340 CheckError(TTF_GetTextSubString(text, offset, substring));
6341}
6342
6343inline void TextBase::GetSubString(int offset, SubString* substring) const
6344{
6345 SDL::GetTextSubString(get(), offset, substring);
6346}
6347
6368 int line,
6369 SubString* substring)
6370{
6371 CheckError(TTF_GetTextSubStringForLine(text, line, substring));
6372}
6373
6374inline void TextBase::GetSubStringForLine(int line, SubString* substring) const
6375{
6376 SDL::GetTextSubStringForLine(get(), line, substring);
6377}
6378
6395 int offset,
6396 int length)
6397{
6398 int count = 0;
6399 auto data = TTF_GetTextSubStringsForRange(text, offset, length, &count);
6400 return OwnArray<SubString*>{data, size_t(count)};
6401}
6402
6404 int length) const
6405{
6406 return SDL::GetTextSubStringsForRange(get(), offset, length);
6407}
6408
6427 Point p,
6428 SubString* substring)
6429{
6430 CheckError(TTF_GetTextSubStringForPoint(text, p.x, p.y, substring));
6431}
6432
6433inline void TextBase::GetSubStringForPoint(Point p, SubString* substring) const
6434{
6435 SDL::GetTextSubStringForPoint(get(), p, substring);
6436}
6437
6456 const SubString& substring,
6457 SubString* previous)
6458{
6459 CheckError(TTF_GetPreviousTextSubString(text, &substring, previous));
6460}
6461
6462inline void TextBase::GetPreviousSubString(const SubString& substring,
6463 SubString* previous) const
6464{
6465 SDL::GetPreviousTextSubString(get(), substring, previous);
6466}
6467
6485 const SubString& substring,
6486 SubString* next)
6487{
6488 CheckError(TTF_GetNextTextSubString(text, &substring, next));
6489}
6490
6491inline void TextBase::GetNextSubString(const SubString& substring,
6492 SubString* next) const
6493{
6494 SDL::GetNextTextSubString(get(), substring, next);
6495}
6496
6512inline void UpdateText(TextRef text) { CheckError(TTF_UpdateText(text)); }
6513
6515
6528inline void DestroyText(TextRaw text) { TTF_DestroyText(text); }
6529
6531
6554inline void CloseFont(FontRaw font) { TTF_CloseFont(font); }
6555
6556inline void FontBase::Close() { CloseFont(release()); }
6557
6559
6560} // namespace SDL
6561
6562#endif // defined(SDL3PP_ENABLE_TTF) || defined(SDL3PP_DOC)
6563
6564#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 release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Const reference wrapper for a given resource,.
Definition SDL3pp_resource.h:115
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:58
Iterator for substrings.
Definition SDL3pp_ttf.h:5062
SubStringIterator()
Default constructor.
Definition SDL3pp_ttf.h:5075
SubStringIterator operator--(int)
Decrement operator.
Definition SDL3pp_ttf.h:5118
constexpr const SubString & operator*() const
Retrieve SubString.
Definition SDL3pp_ttf.h:5084
constexpr const SubString * operator->() const
Retrieve SubString.
Definition SDL3pp_ttf.h:5087
SubStringIterator & operator--()
Decrement operator.
Definition SDL3pp_ttf.h:5111
constexpr bool operator==(const SubStringIterator &other) const
Comparison.
Definition SDL3pp_ttf.h:5090
SubStringIterator & operator++()
Increment operator.
Definition SDL3pp_ttf.h:5096
SubStringIterator operator++(int)
Increment operator.
Definition SDL3pp_ttf.h:5103
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
ResourceRefT< GPUDeviceBase > GPUDeviceRef
Reference for GPUDevice.
Definition SDL3pp_gpu.h:387
ResourceRefT< IOStreamBase > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:37
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
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:55
SDL_Point PointRaw
Alias to raw representation for Point.
Definition SDL3pp_rect.h:22
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:3157
TTF_ImageType ImageType
The type of data in a glyph image.
Definition SDL3pp_ttf.h:338
void SetHinting(HintingFlags hinting)
Set a font's current hinter setting.
Definition SDL3pp_ttf.h:2378
constexpr FontStyleFlags STYLE_NORMAL
No special style.
Definition SDL3pp_ttf.h:241
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:3610
void Destroy()
Destroy a text object created by a text engine.
Definition SDL3pp_ttf.h:6530
void SetTextPosition(TextRef text, const PointRaw &p)
Set the position of a text object.
Definition SDL3pp_ttf.h:5979
Uint32 GetGlyphScript(Uint32 ch)
Get the script used by a 32-bit codepoint.
Definition SDL3pp_ttf.h:2950
constexpr SubStringFlags SUBSTRING_LINE_END
This substring contains the end of line line_index.
Definition SDL3pp_ttf.h:3817
constexpr HintingFlags HINTING_LIGHT
Light hinting applies subtle adjustments to improve rendering.
Definition SDL3pp_ttf.h:277
FontStyleFlags GetFontStyle(FontRef font)
Query a font's current style.
Definition SDL3pp_ttf.h:2292
bool IsWrapWhitespaceVisible() const
Return whether whitespace is shown when wrapping a text object.
Definition SDL3pp_ttf.h:6139
bool GetFontKerning(FontRef font)
Query whether or not kerning is enabled for a font.
Definition SDL3pp_ttf.h:2701
constexpr HorizontalAlignment HORIZONTAL_ALIGN_CENTER
CENTER.
Definition SDL3pp_ttf.h:304
ResourceRefT< TextEngine > TextEngineRef
Reference for TextEngine.
Definition SDL3pp_ttf.h:54
void GetPreviousTextSubString(TextConstRef text, const SubString &substring, SubString *previous)
Get the previous substring in a text object.
Definition SDL3pp_ttf.h:6455
PropertiesRef GetTextProperties(TextConstRef text)
Get the properties associated with a text object.
Definition SDL3pp_ttf.h:5575
void SetTextScript(TextRef text, Uint32 script)
Set the script to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5752
Font OpenFontIO(IOStreamRef src, float ptsize, bool closeio=false)
Create a font from an IOStream, using a specified point size.
Definition SDL3pp_ttf.h:1869
TTF_Text * TextRaw
Alias to raw representation for Text.
Definition SDL3pp_ttf.h:63
int GetFontDescent(FontRef font)
Query the offset from the baseline to the bottom of a font.
Definition SDL3pp_ttf.h:2614
constexpr HorizontalAlignment HORIZONTAL_ALIGN_RIGHT
RIGHT.
Definition SDL3pp_ttf.h:307
TTF_GPUTextEngineWinding GPUTextEngineWinding
The winding order of the vertices returned by GetGPUTextDrawData.
Definition SDL3pp_ttf.h:3827
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:3423
void SetWrapWidth(int wrap_width)
Set whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:6062
int GetFontWeight(FontRef font)
Query a font's weight, in terms of the lightness/heaviness of the strokes.
Definition SDL3pp_ttf.h:2487
void SetTextWrapWhitespaceVisible(TextRef text, bool visible)
Set whether whitespace should be visible when wrapping a text object.
Definition SDL3pp_ttf.h:6111
void SetFontLanguage(FontRef font, StringParam language_bcp47)
Set language to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2977
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE
COUNTER_CLOCKWISE.
Definition SDL3pp_ttf.h:3835
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:3328
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:3231
FontRef GetFont() const
Get the font used by a text object.
Definition SDL3pp_ttf.h:5685
const TTF_Text * TextRawConst
Alias to const raw representation for Text.
Definition SDL3pp_ttf.h:66
void GetDPI(int *hdpi, int *vdpi) const
Get font target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:2233
void SetFontStyle(FontRef font, FontStyleFlags style)
Set a font's current style.
Definition SDL3pp_ttf.h:2262
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:3734
GPUTextEngine CreateGPUTextEngineWithProperties(PropertiesRef props)
Create a text engine for drawing text with the SDL GPU API, with the specified properties.
Definition SDL3pp_ttf.h:5396
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:3563
void GetTextColorFloat(TextConstRef text, float *r, float *g, float *b, float *a)
Get the color of a text object.
Definition SDL3pp_ttf.h:5916
TTF_Direction Direction
Direction flags.
Definition SDL3pp_ttf.h:321
constexpr SubStringFlags SUBSTRING_TEXT_START
This substring contains the beginning of the text.
Definition SDL3pp_ttf.h:3809
void SetTextDirection(TextRef text, Direction direction)
Set the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5702
void SetScript(Uint32 script)
Set the script to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2912
void ClearFallbackFonts(FontRef font)
Remove all fallback fonts.
Definition SDL3pp_ttf.h:2136
void SetFontScript(FontRef font, Uint32 script)
Set the script to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2907
void Update()
Update the layout of a text object.
Definition SDL3pp_ttf.h:6514
Uint32 GetFontGeneration(FontRef font)
Get the font generation.
Definition SDL3pp_ttf.h:2053
bool GetKerning() const
Query whether or not kerning is enabled for a font.
Definition SDL3pp_ttf.h:2703
int GetDescent() const
Query the offset from the baseline to the bottom of a font.
Definition SDL3pp_ttf.h:2616
void AppendTextString(TextRef text, std::string_view string)
Append UTF-8 text to a text object.
Definition SDL3pp_ttf.h:6222
constexpr int FONT_WEIGHT_BLACK
Black (900) named font weight value.
Definition SDL3pp_ttf.h:2515
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:3519
void SetFontWrapAlignment(FontRef font, HorizontalAlignment align)
Set a font's current wrap alignment option.
Definition SDL3pp_ttf.h:2538
TextEngineRef GetTextEngine(TextConstRef text)
Get the text engine used by a text object.
Definition SDL3pp_ttf.h:5625
void DestroyRendererTextEngine(TextEngineRaw engine)
Destroy a text engine created for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:5331
constexpr SubStringFlags SUBSTRING_LINE_START
This substring contains the beginning of line line_index.
Definition SDL3pp_ttf.h:3814
void DestroyText(TextRaw text)
Destroy a text object created by a text engine.
Definition SDL3pp_ttf.h:6528
constexpr Direction DIRECTION_LTR
Left to Right.
Definition SDL3pp_ttf.h:325
TTF_SubString SubString
The representation of a substring within text.
Definition SDL3pp_ttf.h:4179
constexpr ImageType IMAGE_COLOR
The color channels have image data.
Definition SDL3pp_ttf.h:345
Surface GetGlyphImage(FontRef font, Uint32 ch, ImageType *image_type)
Get the pixel image for a UNICODE codepoint.
Definition SDL3pp_ttf.h:3024
bool IsFixedWidth() const
Query whether a font is fixed-width.
Definition SDL3pp_ttf.h:2726
void DeleteString(int offset, int length)
Delete UTF-8 text from a text object.
Definition SDL3pp_ttf.h:6260
Point GetPosition() const
Get the position of a text object.
Definition SDL3pp_ttf.h:6038
Uint32 GetTextScript(TextConstRef text)
Get the script used for text shaping a text object.
Definition SDL3pp_ttf.h:5779
Uint32 StringToTag(StringParam string)
Convert from a 4 character string to a 32-bit tag.
Definition SDL3pp_ttf.h:2863
void DrawSurface(Point p, SurfaceRef surface) const
Draw text to an SDL surface.
Definition SDL3pp_ttf.h:5176
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:3649
Direction GetTextDirection(TextConstRef text)
Get the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5725
void SetEngine(TextEngineRef engine)
Set the text engine used by a text object.
Definition SDL3pp_ttf.h:5606
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:3686
bool SetFont(FontRef font)
Set the font used by a text object.
Definition SDL3pp_ttf.h:5661
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:6426
void UpdateText(TextRef text)
Update the layout of a text object.
Definition SDL3pp_ttf.h:6512
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:3291
void DrawSurfaceText(TextConstRef text, Point p, SurfaceRef surface)
Draw text to an SDL surface.
Definition SDL3pp_ttf.h:5171
bool SetTextFont(TextRef text, FontRef font)
Set the font used by a text object.
Definition SDL3pp_ttf.h:5656
SurfaceTextEngine()
Create a text engine for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:5146
void SetSizeDPI(float ptsize, int hdpi, int vdpi)
Set font size dynamically with target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:2189
PropertiesRef GetProperties()
Get the properties associated with a font.
Definition SDL3pp_ttf.h:2010
void SetOutline(int outline)
Set a font's current outline.
Definition SDL3pp_ttf.h:2328
constexpr ImageType IMAGE_INVALID
INVALID.
Definition SDL3pp_ttf.h:340
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:5546
static Uint32 GetGlyphScript(Uint32 ch)
Get the script used by a 32-bit codepoint.
Definition SDL3pp_ttf.h:2955
float GetFontSize(FontRef font)
Get the size of a font.
Definition SDL3pp_ttf.h:2209
void Destroy()
Destroy a text engine created for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:5475
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:3415
void SetTextWrapWidth(TextRef text, int wrap_width)
Set whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:6057
void RemoveFallbackFont(FontRef font, FontRef fallback)
Remove a fallback font.
Definition SDL3pp_ttf.h:2111
void GetHarfBuzzVersion(int *major, int *minor, int *patch)
Query the version of the HarfBuzz library in use.
Definition SDL3pp_ttf.h:222
Font OpenFontWithProperties(PropertiesRef props)
Create a font with the specified properties.
Definition SDL3pp_ttf.h:1916
const char * GetFontStyleName(FontRef font)
Query a font's style name.
Definition SDL3pp_ttf.h:2791
void SetWrapAlignment(HorizontalAlignment align)
Set a font's current wrap alignment option.
Definition SDL3pp_ttf.h:2543
constexpr HintingFlags HINTING_INVALID
INVALID.
Definition SDL3pp_ttf.h:269
void AddFallbackFont(FontRef font, FontRef fallback)
Add a fallback font.
Definition SDL3pp_ttf.h:2085
bool FontHasGlyph(FontRef font, Uint32 ch)
Check whether a glyph is provided by the font for a UNICODE codepoint.
Definition SDL3pp_ttf.h:2999
GPUAtlasDrawSequence * GetGPUTextDrawData(TextConstRef text)
Get the geometry data needed for drawing the text.
Definition SDL3pp_ttf.h:5445
void DestroySurfaceTextEngine(TextEngineRaw engine)
Destroy a text engine created for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:5196
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:6403
constexpr int FONT_WEIGHT_EXTRA_LIGHT
ExtraLight (200) named font weight value.
Definition SDL3pp_ttf.h:2494
TTF_GPUAtlasDrawSequence GPUAtlasDrawSequence
Draw sequence returned by GetGPUTextDrawData.
Definition SDL3pp_ttf.h:4165
Surface GetGlyphImageForIndex(FontRef font, Uint32 glyph_index, ImageType *image_type)
Get the pixel image for a character index.
Definition SDL3pp_ttf.h:3052
void SetGPUWinding(GPUTextEngineWinding winding)
Sets the winding order of the vertices returned by GetGPUTextDrawData for a particular GPU text engin...
Definition SDL3pp_ttf.h:5498
bool FontIsFixedWidth(FontRef font)
Query whether a font is fixed-width.
Definition SDL3pp_ttf.h:2721
Uint32 FontStyleFlags
Font style flags for Font.
Definition SDL3pp_ttf.h:239
int GetWrapWidth() const
Get whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:6089
int GetLineSkip() const
Query the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:2657
bool TextWrapWhitespaceVisible(TextConstRef text)
Return whether whitespace is shown when wrapping a text object.
Definition SDL3pp_ttf.h:6134
int GetFontAscent(FontRef font)
Query the offset from the baseline to the top of a font.
Definition SDL3pp_ttf.h:2598
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:3094
bool HasGlyph(Uint32 ch) const
Check whether a glyph is provided by the font for a UNICODE codepoint.
Definition SDL3pp_ttf.h:3004
void SetTextColor(TextRef text, Color c)
Set the color of a text object.
Definition SDL3pp_ttf.h:5803
Surface GetGlyphImageForIndex(Uint32 glyph_index, ImageType *image_type) const
Get the pixel image for a character index.
Definition SDL3pp_ttf.h:3060
void SetSize(float ptsize)
Set a font's size dynamically.
Definition SDL3pp_ttf.h:2162
Uint32 GetGeneration() const
Get the font generation.
Definition SDL3pp_ttf.h:2058
Uint32 SubStringFlags
Flags for SubString.
Definition SDL3pp_ttf.h:3803
void SetFontLineSkip(FontRef font, int lineskip)
Set the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:2633
void Destroy()
Destroy a text engine created for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:5336
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:3464
void SetScript(Uint32 script)
Set the script to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5757
void GetPreviousSubString(const SubString &substring, SubString *previous) const
Get the previous substring in a text object.
Definition SDL3pp_ttf.h:6462
constexpr Direction DIRECTION_BTT
Bottom to Top.
Definition SDL3pp_ttf.h:331
constexpr HintingFlags HINTING_MONO
Monochrome hinting adjusts the font for better rendering at lower resolutions.
Definition SDL3pp_ttf.h:283
HorizontalAlignment GetWrapAlignment() const
Query a font's current wrap alignment option.
Definition SDL3pp_ttf.h:2565
int GetWeight() const
Query a font's weight, in terms of the lightness/heaviness of the strokes.
Definition SDL3pp_ttf.h:2489
FontRef GetTextFont(TextConstRef text)
Get the font used by a text object.
Definition SDL3pp_ttf.h:5680
constexpr int FONT_WEIGHT_EXTRA_BOLD
ExtraBold (800) named font weight value.
Definition SDL3pp_ttf.h:2512
void GetNextSubString(const SubString &substring, SubString *next) const
Get the next substring in a text object.
Definition SDL3pp_ttf.h:6491
void GetFontDPI(FontRef font, int *hdpi, int *vdpi)
Get font target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:2228
int GetNumFaces() const
Query the number of faces of a font.
Definition SDL3pp_ttf.h:2395
constexpr FontStyleFlags STYLE_ITALIC
Italic style.
Definition SDL3pp_ttf.h:245
Direction GetFontDirection(FontRef font)
Get the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2841
void SetColorFloat(FColor c)
Set the color of a text object.
Definition SDL3pp_ttf.h:5832
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:3105
GPUAtlasDrawSequence * GetGPUDrawData() const
Get the geometry data needed for drawing the text.
Definition SDL3pp_ttf.h:5450
HorizontalAlignment GetFontWrapAlignment(FontRef font)
Query a font's current wrap alignment option.
Definition SDL3pp_ttf.h:2560
bool GetSDF() const
Query whether Signed Distance Field rendering is enabled for a font.
Definition SDL3pp_ttf.h:2472
void AppendString(std::string_view string)
Append UTF-8 text to a text object.
Definition SDL3pp_ttf.h:6227
void GetSubString(int offset, SubString *substring) const
Get the substring of a text object that surrounds a text offset.
Definition SDL3pp_ttf.h:6343
GPUTextEngine CreateGPUTextEngine(GPUDeviceRef device)
Create a text engine for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:5357
void SetDirection(Direction direction)
Set the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2823
void GetFreeTypeVersion(int *major, int *minor, int *patch)
Query the version of the FreeType library in use.
Definition SDL3pp_ttf.h:204
void TagToString(Uint32 tag, char *string, size_t size)
Convert from a 32-bit tag to a 4 character string.
Definition SDL3pp_ttf.h:2883
bool GetFontSDF(FontRef font)
Query whether Signed Distance Field rendering is enabled for a font.
Definition SDL3pp_ttf.h:2470
void GetTextSubStringForLine(TextConstRef text, int line, SubString *substring)
Get the substring of a text object that contains the given line.
Definition SDL3pp_ttf.h:6367
constexpr FontStyleFlags STYLE_BOLD
Bold style.
Definition SDL3pp_ttf.h:243
constexpr FontStyleFlags STYLE_STRIKETHROUGH
Strikethrough text.
Definition SDL3pp_ttf.h:250
constexpr int FONT_WEIGHT_THIN
Thin (100) named font weight value.
Definition SDL3pp_ttf.h:2491
void SetTextEngine(TextRef text, TextEngineRef engine)
Set the text engine used by a text object.
Definition SDL3pp_ttf.h:5601
Font Copy() const
Create a copy of an existing font.
Definition SDL3pp_ttf.h:1983
void SetStyle(FontStyleFlags style)
Set a font's current style.
Definition SDL3pp_ttf.h:2267
void SetLanguage(StringParam language_bcp47)
Set language to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2982
const char * GetStyleName() const
Query a font's style name.
Definition SDL3pp_ttf.h:2796
Direction GetDirection() const
Get the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5730
void AddFallback(FontRef fallback)
Add a fallback font.
Definition SDL3pp_ttf.h:2090
TTF_TextEngine * TextEngineRaw
Alias to raw representation for TextEngine.
Definition SDL3pp_ttf.h:47
constexpr Direction DIRECTION_RTL
Right to Left.
Definition SDL3pp_ttf.h:327
const char * GetFontFamilyName(FontRef font)
Query a font's family name.
Definition SDL3pp_ttf.h:2765
HintingFlags GetFontHinting(FontRef font)
Query a font's current FreeType hinter setting.
Definition SDL3pp_ttf.h:2418
GPUTextEngineWinding GetGPUWinding() const
Get the winding order of the vertices returned by GetGPUTextDrawData for a particular GPU text engine...
Definition SDL3pp_ttf.h:5524
int GetAscent() const
Query the offset from the baseline to the top of a font.
Definition SDL3pp_ttf.h:2600
bool IsScalable() const
Query whether a font is scalable or not.
Definition SDL3pp_ttf.h:2747
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:3245
TextEngineRef GetEngine() const
Get the text engine used by a text object.
Definition SDL3pp_ttf.h:5630
Font CopyFont(FontRef existing_font)
Create a copy of an existing font.
Definition SDL3pp_ttf.h:1978
TTF_TextData TextData
Internal data for Text.
Definition SDL3pp_ttf.h:4189
int GetOutline() const
Query a font's current outline.
Definition SDL3pp_ttf.h:2347
void InsertString(int offset, std::string_view string)
Insert UTF-8 text into a text object.
Definition SDL3pp_ttf.h:6199
Color GetColor() const
Get the color of a text object.
Definition SDL3pp_ttf.h:5892
constexpr HintingFlags HINTING_NORMAL
Normal hinting applies standard grid-fitting.
Definition SDL3pp_ttf.h:273
constexpr HorizontalAlignment HORIZONTAL_ALIGN_INVALID
INVALID.
Definition SDL3pp_ttf.h:298
void SetKerning(bool enabled)
Set if kerning is enabled for a font.
Definition SDL3pp_ttf.h:2684
void SetFontSize(FontRef font, float ptsize)
Set a font's size dynamically.
Definition SDL3pp_ttf.h:2157
RendererTextEngine CreateRendererTextEngine(RendererRef renderer)
Create a text engine for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:5222
constexpr Direction DIRECTION_INVALID
INVALID.
Definition SDL3pp_ttf.h:323
constexpr HintingFlags HINTING_NONE
No hinting, the font is rendered without any grid-fitting.
Definition SDL3pp_ttf.h:286
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:3558
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:5492
constexpr int FONT_WEIGHT_BOLD
Bold (700) named font weight value.
Definition SDL3pp_ttf.h:2509
Point GetSize() const
Get the size of a text object.
Definition SDL3pp_ttf.h:6314
constexpr ImageType IMAGE_ALPHA
The color channels are white.
Definition SDL3pp_ttf.h:342
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:3337
void SetFontOutline(FontRef font, int outline)
Set a font's current outline.
Definition SDL3pp_ttf.h:2323
void DeleteTextString(TextRef text, int offset, int length)
Delete UTF-8 text from a text object.
Definition SDL3pp_ttf.h:6255
void Destroy()
Destroy a text engine created for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:5201
constexpr int FONT_WEIGHT_MEDIUM
Medium (500) named font weight value.
Definition SDL3pp_ttf.h:2503
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:3371
PropertiesRef GetProperties() const
Get the properties associated with a text object.
Definition SDL3pp_ttf.h:5580
TTF_Font * FontRaw
Alias to raw representation for Font.
Definition SDL3pp_ttf.h:34
float GetSize() const
Get the size of a font.
Definition SDL3pp_ttf.h:2211
void SetLineSkip(int lineskip)
Set the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:2638
int GetGlyphKerning(FontRef font, Uint32 previous_ch, Uint32 ch)
Query the kerning size between the glyphs of two UNICODE codepoints.
Definition SDL3pp_ttf.h:3129
const char * GetFamilyName() const
Query a font's family name.
Definition SDL3pp_ttf.h:2770
RendererTextEngine CreateRendererTextEngineWithProperties(PropertiesRef props)
Create a text engine for drawing text on an SDL renderer, with the specified properties.
Definition SDL3pp_ttf.h:5261
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_INVALID
INVALID.
Definition SDL3pp_ttf.h:3829
void SetFontKerning(FontRef font, bool enabled)
Set if kerning is enabled for a font.
Definition SDL3pp_ttf.h:2679
void ClearFallbacks()
Remove all fallback fonts.
Definition SDL3pp_ttf.h:2138
int GetHeight() const
Query the total height of a font.
Definition SDL3pp_ttf.h:2584
void SetTextColorFloat(TextRef text, FColor c)
Set the color of a text object.
Definition SDL3pp_ttf.h:5827
void DestroyGPUTextEngine(TextEngineRaw engine)
Destroy a text engine created for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:5470
void Close()
Dispose of a previously-created font.
Definition SDL3pp_ttf.h:6556
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:6394
void GetNextTextSubString(TextConstRef text, const SubString &substring, SubString *next)
Get the next substring in a text object.
Definition SDL3pp_ttf.h:6484
void SetFontHinting(FontRef font, HintingFlags hinting)
Set a font's current hinter setting.
Definition SDL3pp_ttf.h:2373
FontStyleFlags GetStyle() const
Query a font's current style.
Definition SDL3pp_ttf.h:2297
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:3376
void SetDirection(Direction direction)
Set the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:5707
void SetColor(Color c)
Set the color of a text object.
Definition SDL3pp_ttf.h:5808
Uint32 GetScript() const
Get the script used for text shaping a text object.
Definition SDL3pp_ttf.h:5784
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:3601
constexpr FontStyleFlags STYLE_UNDERLINE
Underlined text.
Definition SDL3pp_ttf.h:247
constexpr int FONT_WEIGHT_EXTRA_BLACK
ExtraBlack (950) named font weight value.
Definition SDL3pp_ttf.h:2518
void GetTextPosition(TextConstRef text, int *x, int *y)
Get the position of a text object.
Definition SDL3pp_ttf.h:6006
constexpr SubStringFlags SUBSTRING_TEXT_END
This substring contains the end of the text.
Definition SDL3pp_ttf.h:3819
void RemoveFallback(FontRef fallback)
Remove a fallback font.
Definition SDL3pp_ttf.h:2116
void GetTextSize(TextConstRef text, int *w, int *h)
Get the size of a text object.
Definition SDL3pp_ttf.h:6282
void GetTextSubString(TextConstRef text, int offset, SubString *substring)
Get the substring of a text object that surrounds a text offset.
Definition SDL3pp_ttf.h:6336
constexpr SubStringFlags SUBSTRING_DIRECTION_MASK
The mask for the flow direction for this substring.
Definition SDL3pp_ttf.h:3805
Surface GetGlyphImage(Uint32 ch, ImageType *image_type) const
Get the pixel image for a UNICODE codepoint.
Definition SDL3pp_ttf.h:3029
void GetTextColor(TextConstRef text, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
Get the color of a text object.
Definition SDL3pp_ttf.h:5856
int GetTextWrapWidth(TextConstRef text)
Get whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:6082
ResourceConstRef< TextRaw, TextRawConst > TextConstRef
Safely wrap Text for non owning const parameters.
Definition SDL3pp_ttf.h:76
constexpr Direction DIRECTION_TTB
Top to Bottom.
Definition SDL3pp_ttf.h:329
int GetFontHeight(FontRef font)
Query the total height of a font.
Definition SDL3pp_ttf.h:2582
Text CreateText(FontRef font, std::string_view text)
Create a text object from UTF-8 text and a text engine.
Definition SDL3pp_ttf.h:5553
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:3694
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:3286
Uint32 GetScript() const
Get the script used for text shaping a font.
Definition SDL3pp_ttf.h:2934
void SetString(std::string_view string)
Set the UTF-8 text used by a text object.
Definition SDL3pp_ttf.h:6167
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:3789
constexpr HintingFlags HINTING_LIGHT_SUBPIXEL
Light hinting with subpixel rendering for more precise font edges.
Definition SDL3pp_ttf.h:289
ResourceRefT< TextBase > TextRef
Reference for Text.
Definition SDL3pp_ttf.h:73
SurfaceTextEngine CreateSurfaceTextEngine()
Create a text engine for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:5141
Font OpenFont(StringParam file, float ptsize)
Create a font from a file, using a specified point size.
Definition SDL3pp_ttf.h:1824
void SetSDF(bool enabled)
Enable Signed Distance Field rendering for a font.
Definition SDL3pp_ttf.h:2456
Uint32 GetFontScript(FontRef font)
Get the script used for text shaping a font.
Definition SDL3pp_ttf.h:2932
Direction GetDirection() const
Get the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2846
void SetFontDirection(FontRef font, Direction direction)
Set the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:2818
void SetWrapWhitespaceVisible(bool visible)
Set whether whitespace should be visible when wrapping a text object.
Definition SDL3pp_ttf.h:6116
TTF_HintingFlags HintingFlags
Hinting flags for TTF (TrueType Fonts).
Definition SDL3pp_ttf.h:265
void SetPosition(const PointRaw &p)
Set the position of a text object.
Definition SDL3pp_ttf.h:5984
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:2184
int GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const
Query the kerning size between the glyphs of two UNICODE codepoints.
Definition SDL3pp_ttf.h:3135
void InsertTextString(TextRef text, int offset, std::string_view string)
Insert UTF-8 text into a text object.
Definition SDL3pp_ttf.h:6194
constexpr HorizontalAlignment HORIZONTAL_ALIGN_LEFT
LEFT.
Definition SDL3pp_ttf.h:301
bool FontIsScalable(FontRef font)
Query whether a font is scalable or not.
Definition SDL3pp_ttf.h:2745
constexpr int FONT_WEIGHT_SEMI_BOLD
SemiBold (600) named font weight value.
Definition SDL3pp_ttf.h:2506
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:3744
FColor GetColorFloat() const
Get the color of a text object.
Definition SDL3pp_ttf.h:5955
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:3781
HintingFlags GetHinting() const
Query a font's current FreeType hinter setting.
Definition SDL3pp_ttf.h:2423
void CloseFont(FontRaw font)
Dispose of a previously-created font.
Definition SDL3pp_ttf.h:6554
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:3644
ResourceRefT< FontBase > FontRef
Reference for Font.
Definition SDL3pp_ttf.h:41
void DrawRendererText(TextConstRef text, FPoint p)
Draw text to an SDL renderer.
Definition SDL3pp_ttf.h:5306
int GetFontLineSkip(FontRef font)
Query the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:2655
int GetFontOutline(FontRef font)
Query a font's current outline.
Definition SDL3pp_ttf.h:2345
constexpr int FONT_WEIGHT_NORMAL
Normal (400) named font weight value.
Definition SDL3pp_ttf.h:2500
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:3190
int GetNumFontFaces(FontRef font)
Query the number of faces of a font.
Definition SDL3pp_ttf.h:2393
void SetFontSDF(FontRef font, bool enabled)
Enable Signed Distance Field rendering for a font.
Definition SDL3pp_ttf.h:2451
void SetTextString(TextRef text, std::string_view string)
Set the UTF-8 text used by a text object.
Definition SDL3pp_ttf.h:6162
PropertiesRef GetFontProperties(FontRef font)
Get the properties associated with a font.
Definition SDL3pp_ttf.h:2005
constexpr ImageType IMAGE_SDF
The alpha channel has signed distance field information.
Definition SDL3pp_ttf.h:349
constexpr int FONT_WEIGHT_LIGHT
Light (300) 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:3474
void DrawRenderer(FPoint p) const
Draw text to an SDL renderer.
Definition SDL3pp_ttf.h:5311
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_CLOCKWISE
CLOCKWISE.
Definition SDL3pp_ttf.h:3832
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:5519
TTF_HorizontalAlignment HorizontalAlignment
The horizontal alignment used when rendering wrapped text.
Definition SDL3pp_ttf.h:296
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:3511
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:244
ResourceRefT< SurfaceBase > SurfaceRef
Reference for Surface.
Definition SDL3pp_surface.h:57
ResourceRefT< RendererBase > RendererRef
Reference for Renderer.
Definition SDL3pp_video.h:86
Properties for Font creation.
Definition SDL3pp_ttf.h:1923
constexpr auto HORIZONTAL_DPI_NUMBER
Number for horizontal dpi.
Definition SDL3pp_ttf.h:1944
constexpr auto IOSTREAM_AUTOCLOSE_BOOLEAN
Enable iostream autoclose.
Definition SDL3pp_ttf.h:1934
constexpr auto FILENAME_STRING
String for filename.
Definition SDL3pp_ttf.h:1925
constexpr auto IOSTREAM_OFFSET_NUMBER
Number for iostream offset.
Definition SDL3pp_ttf.h:1931
constexpr auto VERTICAL_DPI_NUMBER
Number for vertical dpi.
Definition SDL3pp_ttf.h:1947
constexpr auto SIZE_FLOAT
Float for size.
Definition SDL3pp_ttf.h:1938
constexpr auto IOSTREAM_POINTER
Pointer to iostream.
Definition SDL3pp_ttf.h:1928
constexpr auto EXISTING_FONT_POINTER
Pointer to existing font.
Definition SDL3pp_ttf.h:1952
constexpr auto FACE_NUMBER
Number for face.
Definition SDL3pp_ttf.h:1941
Properties for Font.
Definition SDL3pp_ttf.h:1923
constexpr auto OUTLINE_MITER_LIMIT_NUMBER
Number for outline miter limit.
Definition SDL3pp_ttf.h:2033
constexpr auto OUTLINE_LINE_JOIN_NUMBER
Number for outline line join.
Definition SDL3pp_ttf.h:2030
constexpr auto OUTLINE_LINE_CAP_NUMBER
Number for outline line cap.
Definition SDL3pp_ttf.h:2027
Properties for GPUTextEngine.
Definition SDL3pp_ttf.h:5409
constexpr auto ATLAS_TEXTURE_SIZE_NUMBER
Number for atlas texture size.
Definition SDL3pp_ttf.h:5414
constexpr auto DEVICE_POINTER
Pointer to device.
Definition SDL3pp_ttf.h:5411
Properties for RendererTextEngine.
Definition SDL3pp_ttf.h:5275
constexpr auto ATLAS_TEXTURE_SIZE_NUMBER
Number for atlas texture size.
Definition SDL3pp_ttf.h:5280
constexpr auto RENDERER_POINTER
Pointer to renderer.
Definition SDL3pp_ttf.h:5277
Main include header for the SDL3pp library.
A structure that represents a color as RGBA components.
Definition SDL3pp_pixels.h:2121
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition SDL3pp_pixels.h:2294
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:422
Base class to Font.
Definition SDL3pp_ttf.h:357
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:1215
Point GetStringSize(std::string_view text) const
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:1169
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The internal structure containing font information.
Definition SDL3pp_ttf.h:1683
constexpr Font(Font &&other) noexcept
Move constructor.
Definition SDL3pp_ttf.h:1699
~Font()
Destructor.
Definition SDL3pp_ttf.h:1794
constexpr Font(FontRaw resource) noexcept
Constructs from raw Font.
Definition SDL3pp_ttf.h:1693
constexpr Font & operator=(Font &&other) noexcept
Assignment operator.
Definition SDL3pp_ttf.h:1797
A GPU based text engine.
Definition SDL3pp_ttf.h:4036
~GPUTextEngine()
Destructor.
Definition SDL3pp_ttf.h:4109
constexpr GPUTextEngine & operator=(GPUTextEngine &&other) noexcept
Move assignment operator.
Definition SDL3pp_ttf.h:4058
constexpr GPUTextEngine(GPUTextEngine &&other) noexcept
Move constructor.
Definition SDL3pp_ttf.h:4052
constexpr GPUTextEngine(TextEngineRaw resource) noexcept
Constructs from raw TextEngine.
Definition SDL3pp_ttf.h:4046
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:97
A renderer based text engine.
Definition SDL3pp_ttf.h:3943
constexpr RendererTextEngine & operator=(RendererTextEngine &&other) noexcept
Move assignment operator.
Definition SDL3pp_ttf.h:3965
constexpr RendererTextEngine(TextEngineRaw resource) noexcept
Constructs from raw TextEngine.
Definition SDL3pp_ttf.h:3953
constexpr RendererTextEngine(RendererTextEngine &&other) noexcept
Move constructor.
Definition SDL3pp_ttf.h:3959
~RendererTextEngine()
Destructor.
Definition SDL3pp_ttf.h:4016
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
A surface based text engine.
Definition SDL3pp_ttf.h:3879
constexpr SurfaceTextEngine(SurfaceTextEngine &&other) noexcept
Move constructor.
Definition SDL3pp_ttf.h:3895
constexpr SurfaceTextEngine(TextEngineRaw resource) noexcept
Constructs from raw TextEngine.
Definition SDL3pp_ttf.h:3889
constexpr SurfaceTextEngine & operator=(SurfaceTextEngine &&other) noexcept
Move assignment operator.
Definition SDL3pp_ttf.h:3901
~SurfaceTextEngine()
Destructor.
Definition SDL3pp_ttf.h:3923
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:1677
Base class to Text.
Definition SDL3pp_ttf.h:4197
OwnArray< SubString * > GetSubStrings() const
Get all substrings of a text object.
Definition SDL3pp_ttf.h:4874
int GetNumLines() const
The number of lines in the text, 0 if it's empty.
Definition SDL3pp_ttf.h:4991
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:4988
SubStringIterator begin() const
Get iterator to first substring.
SubStringIterator GetSubStringForLine(int line) const
Get iterator to substring of a text object that contains the given line.
SubStringIterator GetSubStringForPoint(Point p) const
Get the portion of a text string that is closest to a point.
SubStringIterator end() const
Get iterator to one past last substring.
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A text engine used to create text objects.
Definition SDL3pp_ttf.h:3856
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Text created with CreateText().
Definition SDL3pp_ttf.h:5006
~Text()
Destructor.
Definition SDL3pp_ttf.h:5047
constexpr Text(TextRaw resource) noexcept
Constructs from raw Text.
Definition SDL3pp_ttf.h:5016
constexpr Text & operator=(Text &&other) noexcept
Assignment operator.
Definition SDL3pp_ttf.h:5050
constexpr Text(Text &&other) noexcept
Move constructor.
Definition SDL3pp_ttf.h:5022