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_error.h"
5#include "SDL3pp_init.h"
6#include "SDL3pp_rect.h"
7#include "SDL3pp_render.h"
8#include "SDL3pp_stdinc.h"
9#include "SDL3pp_surface.h"
10#include "SDL3pp_version.h"
11
12#if !defined(SDL3PP_DISABLE_TTF) && !defined(SDL3PP_ENABLE_TTF) && \
13 __has_include(<SDL3_ttf/SDL_ttf.h>)
14#define SDL3PP_ENABLE_TTF
15#endif
16
17#if defined(SDL3PP_ENABLE_TTF) || defined(SDL3PP_DOC)
18
19#include <SDL3_ttf/SDL_ttf.h>
20
21namespace SDL {
22
38constexpr struct TtfInitFlag : InitFlagsExtra
39{
41
43using TextEngineDeleter = void (*)(TTF_TextEngine*);
44
45// Forward decl
46struct FontRef;
47
48// Forward decl
49struct Font;
50
60
70
71// Forward decl
72struct TextEngineRef;
73
74// Forward decl
75struct TextEngine;
76
86
96
97// Forward decl
98struct TextRef;
99
100// Forward decl
101struct Text;
102
112
122
140using FontStyleFlags = Uint32;
141
142constexpr FontStyleFlags STYLE_NORMAL = TTF_STYLE_NORMAL;
143
144constexpr FontStyleFlags STYLE_BOLD = TTF_STYLE_BOLD;
145
146constexpr FontStyleFlags STYLE_ITALIC = TTF_STYLE_ITALIC;
147
149 TTF_STYLE_UNDERLINE;
150
152 TTF_STYLE_STRIKETHROUGH;
153
155
173using HintingFlags = TTF_HintingFlags;
174
175constexpr HintingFlags HINTING_INVALID = TTF_HINTING_INVALID;
176
178 TTF_HINTING_NORMAL;
179
183constexpr HintingFlags HINTING_LIGHT = TTF_HINTING_LIGHT;
184
189constexpr HintingFlags HINTING_MONO = TTF_HINTING_MONO;
190
194constexpr HintingFlags HINTING_NONE = TTF_HINTING_NONE;
195
199constexpr HintingFlags HINTING_LIGHT_SUBPIXEL = TTF_HINTING_LIGHT_SUBPIXEL;
200
202
213using HorizontalAlignment = TTF_HorizontalAlignment;
214
216 TTF_HORIZONTAL_ALIGN_INVALID;
217
219 TTF_HORIZONTAL_ALIGN_LEFT;
220
222 TTF_HORIZONTAL_ALIGN_CENTER;
223
225 TTF_HORIZONTAL_ALIGN_RIGHT;
226
228
244using Direction = TTF_Direction;
245
246constexpr Direction DIRECTION_INVALID = TTF_DIRECTION_INVALID;
247
248constexpr Direction DIRECTION_LTR = TTF_DIRECTION_LTR;
249
250constexpr Direction DIRECTION_RTL = TTF_DIRECTION_RTL;
251
252constexpr Direction DIRECTION_TTB = TTF_DIRECTION_TTB;
253
254constexpr Direction DIRECTION_BTT = TTF_DIRECTION_BTT;
255
257
268using ImageType = TTF_ImageType;
269
270constexpr ImageType IMAGE_INVALID = TTF_IMAGE_INVALID;
271
273 TTF_IMAGE_ALPHA;
274
276 TTF_IMAGE_COLOR;
277
281constexpr ImageType IMAGE_SDF = TTF_IMAGE_SDF;
282
284
297using SubStringFlags = Uint32;
298
300 TTF_SUBSTRING_DIRECTION_MASK;
302
304 TTF_SUBSTRING_TEXT_START;
306
310constexpr SubStringFlags SUBSTRING_LINE_START = TTF_SUBSTRING_LINE_START;
311
315constexpr SubStringFlags SUBSTRING_LINE_END = TTF_SUBSTRING_LINE_END;
316
318 TTF_SUBSTRING_TEXT_END;
319
321
332using GPUTextEngineWinding = TTF_GPUTextEngineWinding;
333
335 TTF_GPU_TEXTENGINE_WINDING_INVALID;
336
338 TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE;
339
341 TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE;
342
344
345#ifdef SDL3PP_DOC
346
352#define SDL_TTF_MAJOR_VERSION
353
354#define SDL_TTF_MINOR_VERSION
355
356#define SDL_TTF_MICRO_VERSION
357
359
363#define SDL_TTF_VERSION \
364 SDL_VERSIONNUM( \
365 SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION)
366
370#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \
371 ((SDL_TTF_MAJOR_VERSION >= X) && \
372 (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \
373 (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || \
374 SDL_TTF_MICRO_VERSION >= Z))
375
376#endif // SDL3PP_DOC
377
387inline int TTF_Version() { return ::TTF_Version(); }
388
406inline void GetFreeTypeVersion(int* major, int* minor, int* patch)
407{
408 TTF_GetFreeTypeVersion(major, minor, patch);
409}
410
424inline void GetHarfBuzzVersion(int* major, int* minor, int* patch)
425{
426 TTF_GetHarfBuzzVersion(major, minor, patch);
427}
428
434using TextData = TTF_TextData;
435
443struct FontRef : Resource<TTF_Font*>
444{
445 using Resource::Resource;
446
463 Font Copy() const;
464
487 {
488 return CheckError(TTF_GetFontProperties(get()));
489 }
490
505 Uint32 GetGeneration() const { return TTF_GetFontGeneration(get()); }
506
528 void AddFallback(FontRef fallback)
529 {
530 CheckError(TTF_AddFallbackFont(get(), fallback.get()));
531 }
532
548 void RemoveFallback(FontRef fallback)
549 {
550 TTF_RemoveFallbackFont(get(), fallback.get());
551 }
552
567 void ClearFallbacks() { TTF_ClearFallbackFonts(get()); }
568
585 void SetSize(float ptsize) { CheckError(TTF_SetFontSize(get(), ptsize)); }
586
606 void SetSizeDPI(float ptsize, int hdpi, int vdpi)
607 {
608 CheckError(TTF_SetFontSizeDPI(get(), ptsize, hdpi, vdpi));
609 }
610
625 float GetSize() const { return TTF_GetFontSize(get()); }
626
641 void GetDPI(int* hdpi, int* vdpi) const
642 {
643 CheckError(TTF_GetFontDPI(get(), hdpi, vdpi));
644 }
645
669 void SetStyle(FontStyleFlags style) { TTF_SetFontStyle(get(), style); }
670
690 FontStyleFlags GetStyle() const { return TTF_GetFontStyle(get()); }
691
712 void SetOutline(int outline)
713 {
714 CheckError(TTF_SetFontOutline(get(), outline));
715 }
716
728 int GetOutline() const { return TTF_GetFontOutline(get()); }
729
753 void SetHinting(HintingFlags hinting) { TTF_SetFontHinting(get(), hinting); }
754
764 int GetNumFaces() const { return TTF_GetNumFontFaces(get()); }
765
786 HintingFlags GetHinting() const { return TTF_GetFontHinting(get()); }
787
810 void SetSDF(bool enabled) { CheckError(TTF_SetFontSDF(get(), enabled)); }
811
823 bool GetSDF() const { return TTF_GetFontSDF(get()); }
824
825#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
826
837 int GetWeight() const { return TTF_GetFontWeight(get()); }
838
839#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
840
856 {
857 TTF_SetFontWrapAlignment(get(), align);
858 }
859
872 {
873 return TTF_GetFontWrapAlignment(get());
874 }
875
887 int GetHeight() const { return TTF_GetFontHeight(get()); }
888
900 int GetAscent() const { return TTF_GetFontAscent(get()); }
901
913 int GetDescent() const { return TTF_GetFontDescent(get()); }
914
929 void SetLineSkip(int lineskip) { TTF_SetFontLineSkip(get(), lineskip); }
930
942 int GetLineSkip() const { return TTF_GetFontLineSkip(get()); }
943
963 void SetKerning(bool enabled) { TTF_SetFontKerning(get(), enabled); }
964
976 bool GetKerning() const { return TTF_GetFontKerning(get()); }
977
993 bool IsFixedWidth() const { return TTF_FontIsFixedWidth(get()); }
994
1008 bool IsScalable() const { return TTF_FontIsScalable(get()); }
1009
1025 const char* GetFamilyName() const { return TTF_GetFontFamilyName(get()); }
1026
1042 const char* GetStyleName() const { return TTF_GetFontStyleName(get()); }
1043
1060 void SetDirection(Direction direction)
1061 {
1062 CheckError(TTF_SetFontDirection(get(), direction));
1063 }
1064
1077 Direction GetDirection() const { return TTF_GetFontDirection(get()); }
1078
1097 void SetScript(Uint32 script)
1098 {
1099 CheckError(TTF_SetFontScript(get(), script));
1100 }
1101
1116 Uint32 GetScript() const { return TTF_GetFontScript(get()); }
1117
1133 static Uint32 GetGlyphScript(Uint32 ch) { return TTF_GetGlyphScript(ch); }
1134
1152 void SetLanguage(StringParam language_bcp47)
1153 {
1154 CheckError(TTF_SetFontLanguage(get(), language_bcp47));
1155 }
1156
1168 bool HasGlyph(Uint32 ch) const { return TTF_FontHasGlyph(get(), ch); }
1169
1184 SurfaceRef GetGlyphImage(Uint32 ch, ImageType* image_type = nullptr) const
1185 {
1186 return TTF_GetGlyphImage(get(), ch, image_type);
1187 }
1188
1207 ImageType* image_type = nullptr) const
1208 {
1209 return TTF_GetGlyphImageForIndex(get(), glyph_index, image_type);
1210 }
1211
1239 void GetGlyphMetrics(Uint32 ch,
1240 int* minx,
1241 int* maxx,
1242 int* miny,
1243 int* maxy,
1244 int* advance) const
1245 {
1246 CheckError(TTF_GetGlyphMetrics(get(), ch, minx, maxx, miny, maxy, advance));
1247 }
1248
1262 int GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const
1263 {
1264 if (int r; TTF_GetGlyphKerning(get(), previous_ch, ch, &r)) return r;
1265 throw Error();
1266 }
1267
1283 Point GetStringSize(std::string_view text) const
1284 {
1285 Point p;
1286 GetStringSize(text, &p.x, &p.y);
1287 return p;
1288 }
1289
1306 void GetStringSize(std::string_view text, int* w, int* h) const
1307 {
1308 CheckError(TTF_GetStringSize(get(), text.data(), text.size(), w, h));
1309 }
1310
1332 Point GetStringSizeWrapped(std::string_view text, int wrap_width) const
1333 {
1334 Point p;
1335 GetStringSizeWrapped(text, wrap_width, &p.x, &p.y);
1336 return p;
1337 }
1338
1361 void GetStringSizeWrapped(std::string_view text,
1362 int wrap_width,
1363 int* w,
1364 int* h) const
1365 {
1366 CheckError(TTF_GetStringSizeWrapped(
1367 get(), text.data(), text.size(), wrap_width, w, h));
1368 }
1369
1392 void MeasureString(std::string_view text,
1393 int max_width,
1394 int* measured_width,
1395 size_t* measured_length) const
1396 {
1397 CheckError(TTF_MeasureString(get(),
1398 text.data(),
1399 text.size(),
1400 max_width,
1401 measured_width,
1402 measured_length));
1403 }
1404
1437 Surface RenderText_Solid(std::string_view text, Color fg) const
1438 {
1439 return Surface{TTF_RenderText_Solid(get(), text.data(), text.size(), fg)};
1440 }
1441
1474 Surface RenderText_Solid_Wrapped(std::string_view text,
1475 Color fg,
1476 int wrapLength) const
1477 {
1478 return Surface{TTF_RenderText_Solid_Wrapped(
1479 get(), text.data(), text.size(), fg, wrapLength)};
1480 }
1481
1508 Surface RenderGlyph_Solid(Uint32 ch, Color fg) const
1509 {
1510 return Surface{TTF_RenderGlyph_Solid(get(), ch, fg)};
1511 }
1512
1546 Surface RenderText_Shaded(std::string_view text, Color fg, Color bg) const
1547 {
1548 return Surface{
1549 TTF_RenderText_Shaded(get(), text.data(), text.size(), fg, bg)};
1550 }
1551
1586 Surface RenderText_Shaded_Wrapped(std::string_view text,
1587 Color fg,
1588 Color bg,
1589 int wrap_width) const
1590 {
1591 return Surface{TTF_RenderText_Shaded_Wrapped(
1592 get(), text.data(), text.size(), fg, bg, wrap_width)};
1593 }
1594
1623 Surface RenderGlyph_Shaded(Uint32 ch, Color fg, Color bg) const
1624 {
1625 return Surface{TTF_RenderGlyph_Shaded(get(), ch, fg, bg)};
1626 }
1627
1659 Surface RenderText_Blended(std::string_view text, Color fg) const
1660 {
1661 return Surface{TTF_RenderText_Blended(get(), text.data(), text.size(), fg)};
1662 }
1663
1697 Color fg,
1698 int wrap_width) const
1699 {
1700 return Surface{TTF_RenderText_Blended_Wrapped(
1701 get(), text.data(), text.size(), fg, wrap_width)};
1702 }
1703
1730 Surface RenderGlyph_Blended(Uint32 ch, Color fg) const
1731 {
1732 return Surface{TTF_RenderGlyph_Blended(get(), ch, fg)};
1733 }
1734
1767 Surface RenderText_LCD(std::string_view text, Color fg, Color bg) const
1768 {
1769 return Surface{TTF_RenderText_LCD(get(), text.data(), text.size(), fg, bg)};
1770 }
1771
1806 Surface RenderText_LCD_Wrapped(std::string_view text,
1807 Color fg,
1808 Color bg,
1809 int wrap_width) const
1810 {
1811 return Surface{TTF_RenderText_LCD_Wrapped(
1812 get(), text.data(), text.size(), fg, bg, wrap_width)};
1813 }
1814
1843 Surface RenderGlyph_LCD(Uint32 ch, Color fg, Color bg) const
1844 {
1845 return Surface{TTF_RenderGlyph_LCD(get(), ch, fg, bg)};
1846 }
1847
1870 static void reset(TTF_Font* resource) { TTF_CloseFont(resource); }
1871};
1872
1880struct Font : ResourceUnique<FontRef>
1881{
1883
1902 static Font Open(StringParam file, float ptsize)
1903 {
1904 return Font(CheckError(TTF_OpenFont(file, ptsize)));
1905 }
1906
1925 static Font Open(IOStreamRef src, float ptsize)
1926 {
1927 return Font(CheckError(TTF_OpenFontIO(src, false, ptsize)));
1928 }
1929
1974 {
1975 return Font(CheckError(TTF_OpenFontWithProperties(props)));
1976 }
1977
1998 void Close() { reset(); }
2002 FontShared share();
2003
2004};
2005
2006
2008{
2009 return FontShared(std::move(*this));
2010}
2011
2022{
2024
2028 constexpr explicit FontUnsafe(Font&& other)
2029 : FontUnsafe(other.release())
2030 {
2031 }
2032};
2033
2050inline void InitSubSystem(TtfInitFlag _) { CheckError(TTF_Init()); }
2051
2071struct TextEngineRef : Resource<TTF_TextEngine*>
2072{
2073 using Resource::Resource;
2074
2089 {
2090 TTF_SetGPUTextEngineWinding(get(), winding);
2091 }
2092
2108 {
2109 return TTF_GetGPUTextEngineWinding(get());
2110 }
2127 static void DestroySurface(TTF_TextEngine* engine)
2128 {
2129 TTF_DestroySurfaceTextEngine(engine);
2130 }
2131
2148 static void DestroyRenderer(TTF_TextEngine* engine)
2149 {
2150 TTF_DestroyRendererTextEngine(engine);
2151 }
2152
2169 static void DestroyGPU(TTF_TextEngine* engine)
2170 {
2171 TTF_DestroyGPUTextEngine(engine);
2172 }
2173};
2174
2182struct TextEngine : ResourceUnique<TextEngineRef, TextEngineDeleter>
2183{
2185
2200 {
2201 return TextEngine(TTF_CreateSurfaceTextEngine(),
2203 }
2204
2222 {
2223 return TextEngine(TTF_CreateRendererTextEngine(renderer),
2225 }
2226
2252 {
2253 return TextEngine(TTF_CreateRendererTextEngineWithProperties(props),
2255 }
2256
2274 static TextEngine CreateGPU(SDL_GPUDevice* device)
2275 {
2276 return TextEngine(TTF_CreateGPUTextEngine(device),
2278 }
2279
2305 {
2306 return TextEngine(TTF_CreateGPUTextEngineWithProperties(props),
2308 }
2313
2314};
2315
2316
2318{
2319 return TextEngineShared(std::move(*this));
2320}
2321
2331struct TextEngineUnsafe : ResourceUnsafe<TextEngineRef, TextEngineDeleter>
2332{
2334
2338 constexpr explicit TextEngineUnsafe(TextEngine&& other)
2339 : TextEngineUnsafe(other.release())
2340 {
2341 }
2342};
2343
2351using GPUAtlasDrawSequence = TTF_GPUAtlasDrawSequence;
2352
2366using SubString = TTF_SubString;
2367
2368// Forward decl
2369struct SubStringIterator;
2370
2371namespace prop::Font {
2372
2373constexpr auto CREATE_FILENAME_STRING = TTF_PROP_FONT_CREATE_FILENAME_STRING;
2374
2375constexpr auto CREATE_IOSTREAM_POINTER = TTF_PROP_FONT_CREATE_IOSTREAM_POINTER;
2376
2377constexpr auto CREATE_IOSTREAM_OFFSET_NUMBER =
2378 TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER;
2379
2380constexpr auto CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN =
2381 TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN;
2382
2383constexpr auto CREATE_SIZE_FLOAT = TTF_PROP_FONT_CREATE_SIZE_FLOAT;
2384
2385constexpr auto CREATE_FACE_NUMBER = TTF_PROP_FONT_CREATE_FACE_NUMBER;
2386
2387constexpr auto CREATE_HORIZONTAL_DPI_NUMBER =
2388 TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER;
2389
2390constexpr auto CREATE_VERTICAL_DPI_NUMBER =
2391 TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER;
2392
2393#if SDL_TTF_VERSION_ATLEAST(3, 2, 3)
2394
2395constexpr auto CREATE_EXISTING_FONT_POINTER =
2396 TTF_PROP_FONT_CREATE_EXISTING_FONT_POINTER;
2397
2398#else
2399
2400constexpr auto CREATE_EXISTING_FONT_POINTER =
2401 TTF_PROP_FONT_CREATE_EXISTING_FONT;
2402
2403#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 3)
2404
2405constexpr auto OUTLINE_LINE_CAP_NUMBER = TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER;
2406
2407constexpr auto OUTLINE_LINE_JOIN_NUMBER =
2408 TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER;
2409
2410constexpr auto OUTLINE_MITER_LIMIT_NUMBER =
2411 TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER;
2412
2413} // namespace prop::Font
2414
2415inline Font FontRef::Copy() const { return Font{TTF_CopyFont(get())}; }
2416
2417#ifdef SDL3PP_DOC
2418
2422#define SDL_FONT_WEIGHT_THIN TTF_FONT_WEIGHT_THIN
2423
2427#define SDL_FONT_WEIGHT_EXTRA_LIGHT TTF_FONT_WEIGHT_EXTRA_LIGHT
2428
2432#define SDL_FONT_WEIGHT_LIGHT TTF_FONT_WEIGHT_LIGHT
2433
2437#define SDL_FONT_WEIGHT_NORMAL TTF_FONT_WEIGHT_NORMAL
2438
2442#define SDL_FONT_WEIGHT_MEDIUM TTF_FONT_WEIGHT_MEDIUM
2443
2447#define SDL_FONT_WEIGHT_SEMI_BOLD TTF_FONT_WEIGHT_SEMI_BOLD
2448
2452#define SDL_FONT_WEIGHT_BOLD TTF_FONT_WEIGHT_BOLD
2453
2457#define SDL_FONT_WEIGHT_EXTRA_BOLD TTF_FONT_WEIGHT_EXTRA_BOLD
2458
2462#define SDL_FONT_WEIGHT_BLACK TTF_FONT_WEIGHT_BLACK
2463
2467#define SDL_FONT_WEIGHT_EXTRA_BLACK TTF_FONT_WEIGHT_EXTRA_BLACK
2468
2469#endif // SDL3PP_DOC
2470
2483inline Uint32 StringToTag(StringParam string)
2484{
2485 return TTF_StringToTag(string);
2486}
2487
2503inline void TagToString(Uint32 tag, char* string, size_t size)
2504{
2505 TTF_TagToString(tag, string, size);
2506}
2507
2520struct TextRef : Resource<TTF_Text*>
2521{
2522 using Resource::Resource;
2523
2543 void DrawSurface(Point p, SurfaceRef surface) const
2544 {
2545 CheckError(TTF_DrawSurfaceText(get(), p.x, p.y, surface.get()));
2546 }
2547
2567 void DrawRenderer(FPoint p) const
2568 {
2569 CheckError(TTF_DrawRendererText(get(), p.x, p.y));
2570 }
2571
2599 {
2600 return TTF_GetGPUTextDrawData(get());
2601 }
2602
2615 {
2616 return CheckError(TTF_GetTextProperties(get()));
2617 }
2618
2635 {
2636 CheckError(TTF_SetTextEngine(get(), engine));
2637 }
2638
2653 {
2654 return CheckError(TTF_GetTextEngine(get()));
2655 }
2656
2677 bool SetFont(FontRef font) { return TTF_SetTextFont(get(), font); }
2678
2692 FontRef GetFont() const { return CheckError(TTF_GetTextFont(get())); }
2693
2708 void SetDirection(Direction direction)
2709 {
2710 CheckError(TTF_SetTextDirection(get(), direction));
2711 }
2712
2725 Direction GetDirection() const { return TTF_GetTextDirection(get()); }
2726
2743 void SetScript(Uint32 script)
2744 {
2745 CheckError(TTF_SetTextScript(get(), script));
2746 }
2747
2765 Uint32 GetScript() const { return TTF_GetTextScript(get()); }
2766
2784 {
2785 CheckError(TTF_SetTextColor(get(), c.r, c.g, c.b, c.a));
2786 }
2787
2805 {
2806 CheckError(TTF_SetTextColorFloat(get(), c.r, c.g, c.b, c.a));
2807 }
2808
2821 {
2822 FColor c;
2823 GetColor(&c);
2824 return c;
2825 }
2826
2841 void GetColor(Color* c) const
2842 {
2843 SDL_assert_paranoid(c != nullptr);
2844 GetColor(&c->r, &c->g, &c->b, &c->a);
2845 }
2846
2861 void GetColor(FColor* c) const
2862 {
2863 SDL_assert_paranoid(c != nullptr);
2864 GetColor(&c->r, &c->g, &c->b, &c->a);
2865 }
2866
2887 void GetColor(Uint8* r, Uint8* g, Uint8* b, Uint8* a) const
2888 {
2889 CheckError(TTF_GetTextColor(get(), r, g, b, a));
2890 }
2891
2912 void GetColor(float* r, float* g, float* b, float* a) const
2913 {
2914 CheckError(TTF_GetTextColorFloat(get(), r, g, b, a));
2915 }
2916
2934 bool SetPosition(Point p) { return TTF_SetTextPosition(get(), p.x, p.y); }
2935
2951 {
2952 Point p;
2953 GetPosition(&p.x, &p.y);
2954 return p;
2955 }
2956
2974 bool GetPosition(int* x, int* y) const
2975 {
2976 return TTF_GetTextPosition(get(), x, y);
2977 }
2978
2995 void SetWrapWidth(int wrap_width)
2996 {
2997 CheckError(TTF_SetTextWrapWidth(get(), wrap_width));
2998 }
2999
3014 int GetWrapWidth() const
3015 {
3016 int w;
3017 CheckError(TTF_GetTextWrapWidth(get(), &w));
3018 return w;
3019 }
3020
3042 void SetWrapWhitespaceVisible(bool visible)
3043 {
3044 CheckError(TTF_SetTextWrapWhitespaceVisible(get(), visible));
3045 }
3046
3061 {
3062 return TTF_TextWrapWhitespaceVisible(get());
3063 }
3064
3082 void SetString(std::string_view string)
3083 {
3084 CheckError(TTF_SetTextString(get(), string.data(), string.size()));
3085 }
3086
3108 void InsertString(int offset, std::string_view string)
3109 {
3110 CheckError(
3111 TTF_InsertTextString(get(), offset, string.data(), string.size()));
3112 }
3113
3131 void AppendString(std::string_view string)
3132 {
3133 CheckError(TTF_AppendTextString(get(), string.data(), string.size()));
3134 }
3135
3158 void DeleteString(int offset, int length = -1)
3159 {
3160 CheckError(TTF_DeleteTextString(get(), offset, length));
3161 }
3162
3180 {
3181 Point p;
3182 GetSize(&p.x, &p.y);
3183 return p;
3184 }
3185
3203 void GetSize(int* w, int* h) const
3204 {
3205 CheckError(TTF_GetTextSize(get(), w, h));
3206 }
3207
3227 void GetSubString(int offset, SubString* substring) const
3228 {
3229 CheckError(TTF_GetTextSubString(get(), offset, substring));
3230 }
3231
3235 SubStringIterator begin() const;
3236
3240 SubStringIterator end() const;
3241
3257 SubStringIterator GetSubStringForLine(int line) const;
3258
3277 void GetSubStringForLine(int line, SubString* substring) const
3278 {
3279 CheckError(TTF_GetTextSubStringForLine(get(), line, substring));
3280 }
3281
3294 {
3295 return GetSubStringsForRange(0);
3296 }
3297
3312 OwnArray<SubString*> GetSubStringsForRange(int offset, int length = -1) const
3313 {
3314 int count = 0;
3315 auto data = TTF_GetTextSubStringsForRange(get(), offset, length, &count);
3316 return OwnArray<SubString*>{data, size_t(count)};
3317 }
3318
3335
3352 void GetSubStringForPoint(Point p, SubString* substring) const
3353 {
3354 CheckError(TTF_GetTextSubStringForPoint(get(), p.x, p.y, substring));
3355 }
3356
3372 void GetPreviousSubString(const SubString& substring,
3373 SubString* previous) const
3374 {
3375 CheckError(TTF_GetPreviousTextSubString(get(), &substring, previous));
3376 }
3377
3393 void GetNextSubString(const SubString& substring, SubString* next) const
3394 {
3395 CheckError(TTF_GetNextTextSubString(get(), &substring, next));
3396 }
3397
3412 void Update() { CheckError(TTF_UpdateText(get())); }
3413
3418 const char* GetText() const { return get()->text; }
3419
3423 int GetNumLines() const { return get()->num_lines; }
3424
3437 static void reset(TTF_Text* resource) { TTF_DestroyText(resource); }
3438};
3439
3447struct Text : ResourceUnique<TextRef>
3448{
3450
3468 static Text Create(TextEngineRef engine, FontRef font, std::string_view text)
3469 {
3470 return Text(TTF_CreateText(engine, font, text.data(), text.size()));
3471 }
3472
3484 void Destroy() { reset(); }
3488 TextShared share();
3489
3490};
3491
3492
3494{
3495 return TextShared(std::move(*this));
3496}
3497
3508{
3510
3514 constexpr explicit TextUnsafe(Text&& other)
3515 : TextUnsafe(other.release())
3516 {
3517 }
3518};
3519
3525{
3526 TextRef m_text;
3527
3528 SubString m_subString;
3529
3530 constexpr SubStringIterator(TextRef text)
3531 : m_text(std::move(text))
3532 , m_subString(0)
3533 {
3534 }
3535
3536public:
3539 : SubStringIterator(nullptr)
3540 {
3541 }
3542
3544 constexpr operator bool() const { return m_text != nullptr; }
3545
3547 constexpr const SubString& operator*() const { return m_subString; }
3548
3550 constexpr const SubString* operator->() const { return &m_subString; }
3551
3553 constexpr bool operator==(const SubStringIterator& other) const
3554 {
3555 return m_subString.offset == other.m_subString.offset;
3556 }
3557
3560 {
3561 m_text.GetNextSubString(m_subString, &m_subString);
3562 return *this;
3563 }
3564
3567 {
3568 auto curr = *this;
3569 m_text.GetNextSubString(m_subString, &m_subString);
3570 return curr;
3571 }
3572
3575 {
3576 m_text.GetPreviousSubString(m_subString, &m_subString);
3577 return *this;
3578 }
3579
3582 {
3583 auto curr = *this;
3584 m_text.GetPreviousSubString(m_subString, &m_subString);
3585 return curr;
3586 }
3587
3588 friend class TextRef;
3589};
3590
3591namespace prop::RendererTextEngine {
3592
3593#if SDL_TTF_VERSION_ATLEAST(3, 2, 3)
3594
3595constexpr auto RENDERER_POINTER =
3596 TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER_POINTER;
3597
3598constexpr auto ATLAS_TEXTURE_SIZE_NUMBER =
3599 TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE_NUMBER;
3600
3601#else
3602
3603constexpr auto RENDERER_POINTER = TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER;
3604
3605constexpr auto ATLAS_TEXTURE_SIZE_NUMBER =
3606 TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE;
3607
3608#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 3)
3609
3610} // namespace prop::RendererTextEngine
3611
3612namespace prop::GpuTextEngine {
3613
3614#if SDL_TTF_VERSION_ATLEAST(3, 2, 3)
3615
3616constexpr auto DEVICE_POINTER = TTF_PROP_GPU_TEXT_ENGINE_DEVICE_POINTER;
3617
3618constexpr auto ATLAS_TEXTURE_SIZE_NUMBER =
3619 TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE_NUMBER;
3620
3621#else
3622
3623constexpr auto DEVICE_POINTER = TTF_PROP_GPU_TEXT_ENGINE_DEVICE;
3624
3625constexpr auto ATLAS_TEXTURE_SIZE_NUMBER =
3626 TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE;
3627
3628#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 3)
3629
3630} // namespace prop::GpuTextEngine
3631
3651inline void QuitSubSystem(TtfInitFlag _) { TTF_Quit(); }
3652
3677inline int WasInit(TtfInitFlag _) { return TTF_WasInit(); }
3678
3680
3681#pragma region impl
3682
3684{
3685 SubStringIterator it{get()};
3686 GetSubString(0, &it.m_subString);
3687 return it;
3688}
3689
3691{
3692 SubStringIterator it{get()};
3693 GetSubString(INT_MAX, &it.m_subString);
3694 return it;
3695}
3696
3698{
3699 SubStringIterator it{get()};
3700 GetSubStringForLine(line, &it.m_subString);
3701 return it;
3702}
3703
3705{
3706 SubStringIterator it{get()};
3707 GetSubStringForPoint(p, &it.m_subString);
3708 return it;
3709}
3710
3711#pragma endregion impl
3712
3713} // namespace SDL
3714
3715#endif // defined(SDL3PP_ENABLE_TTF) || defined(SDL3PP_DOC)
3716
3717#endif /* SDL3PP_TTF_H_ */
An exception that returns GetError()
Definition SDL3pp_error.h:167
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
RESOURCE release()
Returns reference and reset this.
Definition SDL3pp_resource.h:178
Implement shared ownership for a resource.
Definition SDL3pp_resource.h:283
Implement unique ownership for a resource.
Definition SDL3pp_resource.h:226
constexpr ResourceUnique(std::nullptr_t=nullptr)
Default constructor.
Definition SDL3pp_resource.h:231
void reset()
Resets the value, destroying the resource if not nullptr.
Definition SDL3pp_resource.h:265
A dumb pointer to resource.
Definition SDL3pp_resource.h:197
constexpr ResourceUnsafe()=default
Default constructor.
Implement weak ownership for a resource.
Definition SDL3pp_resource.h:328
A SDL managed resource.
Definition SDL3pp_resource.h:29
constexpr Resource(T resource={})
Constructs from the underlying resource.
Definition SDL3pp_resource.h:37
constexpr TTF_Font * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Iterator for substrings.
Definition SDL3pp_ttf.h:3525
constexpr SubStringIterator()
Default constructor.
Definition SDL3pp_ttf.h:3538
constexpr SubStringIterator & operator--()
Decrement operator.
Definition SDL3pp_ttf.h:3574
constexpr const SubString & operator*() const
Retrieve SubString.
Definition SDL3pp_ttf.h:3547
constexpr const SubString * operator->() const
Retrieve SubString.
Definition SDL3pp_ttf.h:3550
constexpr bool operator==(const SubStringIterator &other) const
Comparison.
Definition SDL3pp_ttf.h:3553
constexpr SubStringIterator operator--(int)
Decrement operator.
Definition SDL3pp_ttf.h:3581
constexpr SubStringIterator operator++(int)
Increment operator.
Definition SDL3pp_ttf.h:3566
constexpr SubStringIterator & operator++()
Increment operator.
Definition SDL3pp_ttf.h:3559
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:364
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
void InitSubSystem(InitFlags flags)
Initialize the SDL library.
Definition SDL3pp_init.h:279
bool WasInit(InitFlags flags)
Check if all of the specified subsystems which are currently initialized.
Definition SDL3pp_init.h:485
void QuitSubSystem(InitFlags flags)
Shut down specific SDL subsystems.
Definition SDL3pp_init.h:427
constexpr FontStyleFlags STYLE_NORMAL
No special style.
Definition SDL3pp_ttf.h:142
TextShared share()
Move this text into a TextShared.
Definition SDL3pp_ttf.h:3493
constexpr SubStringFlags SUBSTRING_LINE_END
This substring contains the end of line line_index
Definition SDL3pp_ttf.h:315
constexpr HintingFlags HINTING_LIGHT
Light hinting applies subtle adjustments to improve rendering.
Definition SDL3pp_ttf.h:183
constexpr HorizontalAlignment HORIZONTAL_ALIGN_CENTER
CENTER.
Definition SDL3pp_ttf.h:221
constexpr HorizontalAlignment HORIZONTAL_ALIGN_RIGHT
RIGHT.
Definition SDL3pp_ttf.h:224
TextEngineShared share()
Move this textEngine into a TextEngineShared.
Definition SDL3pp_ttf.h:2317
TTF_GPUAtlasDrawSequence GPUAtlasDrawSequence
Draw sequence returned by TextRef.GetGPUDrawData.
Definition SDL3pp_ttf.h:2351
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE
COUNTER_CLOCKWISE.
Definition SDL3pp_ttf.h:340
constexpr SubStringFlags SUBSTRING_TEXT_START
This substring contains the beginning of the text.
Definition SDL3pp_ttf.h:303
constexpr SubStringFlags SUBSTRING_LINE_START
This substring contains the beginning of line line_index
Definition SDL3pp_ttf.h:310
constexpr Direction DIRECTION_LTR
Left to Right.
Definition SDL3pp_ttf.h:248
constexpr ImageType IMAGE_COLOR
The color channels have image data.
Definition SDL3pp_ttf.h:275
FontShared share()
Move this font into a FontShared.
Definition SDL3pp_ttf.h:2007
Uint32 StringToTag(StringParam string)
Convert from a 4 character string to a 32-bit tag.
Definition SDL3pp_ttf.h:2483
Uint32 SubStringFlags
Flags for SubString.
Definition SDL3pp_ttf.h:297
TTF_HintingFlags HintingFlags
Hinting flags for TTF (TrueType Fonts)
Definition SDL3pp_ttf.h:173
constexpr ImageType IMAGE_INVALID
INVALID.
Definition SDL3pp_ttf.h:270
int TTF_Version()
This function gets the version of the dynamically linked SDL_ttf library.
Definition SDL3pp_ttf.h:387
ResourceShared< Font > FontShared
Handle to a shared font.
Definition SDL3pp_ttf.h:59
void GetHarfBuzzVersion(int *major, int *minor, int *patch)
Query the version of the HarfBuzz library in use.
Definition SDL3pp_ttf.h:424
constexpr HintingFlags HINTING_INVALID
INVALID.
Definition SDL3pp_ttf.h:175
Uint32 FontStyleFlags
Font style flags for Font.
Definition SDL3pp_ttf.h:140
Font Copy() const
Create a copy of an existing font.
Definition SDL3pp_ttf.h:2415
constexpr Direction DIRECTION_BTT
Bottom to Top.
Definition SDL3pp_ttf.h:254
constexpr HintingFlags HINTING_MONO
Monochrome hinting adjusts the font for better rendering at lower resolutions.
Definition SDL3pp_ttf.h:189
constexpr FontStyleFlags STYLE_ITALIC
Italic style.
Definition SDL3pp_ttf.h:146
void GetFreeTypeVersion(int *major, int *minor, int *patch)
Query the version of the FreeType library in use.
Definition SDL3pp_ttf.h:406
void TagToString(Uint32 tag, char *string, size_t size)
Convert from a 32-bit tag to a 4 character string.
Definition SDL3pp_ttf.h:2503
TTF_GPUTextEngineWinding GPUTextEngineWinding
The winding order of the vertices returned by TextRef.GetGPUDrawData.
Definition SDL3pp_ttf.h:332
constexpr FontStyleFlags STYLE_BOLD
Bold style.
Definition SDL3pp_ttf.h:144
constexpr FontStyleFlags STYLE_STRIKETHROUGH
Strikethrough text.
Definition SDL3pp_ttf.h:151
constexpr Direction DIRECTION_RTL
Right to Left.
Definition SDL3pp_ttf.h:250
TTF_ImageType ImageType
The type of data in a glyph image.
Definition SDL3pp_ttf.h:268
SDL::TtfInitFlag INIT_TTF
Flag to init TTF support.
constexpr HintingFlags HINTING_NORMAL
Normal hinting applies standard grid-fitting.
Definition SDL3pp_ttf.h:177
constexpr HorizontalAlignment HORIZONTAL_ALIGN_INVALID
INVALID.
Definition SDL3pp_ttf.h:215
constexpr Direction DIRECTION_INVALID
INVALID.
Definition SDL3pp_ttf.h:246
constexpr HintingFlags HINTING_NONE
No hinting, the font is rendered without any grid-fitting.
Definition SDL3pp_ttf.h:194
TTF_SubString SubString
The representation of a substring within text.
Definition SDL3pp_ttf.h:2366
constexpr ImageType IMAGE_ALPHA
The color channels are white.
Definition SDL3pp_ttf.h:272
void(*)(TTF_TextEngine *) TextEngineDeleter
Deleter for TextEngine.
Definition SDL3pp_ttf.h:43
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_INVALID
INVALID.
Definition SDL3pp_ttf.h:334
ResourceShared< Text > TextShared
Handle to a shared text.
Definition SDL3pp_ttf.h:111
TTF_TextData TextData
Internal data for TTF_Text.
Definition SDL3pp_ttf.h:434
constexpr FontStyleFlags STYLE_UNDERLINE
Underlined text.
Definition SDL3pp_ttf.h:148
constexpr SubStringFlags SUBSTRING_TEXT_END
This substring contains the end of the text.
Definition SDL3pp_ttf.h:317
constexpr SubStringFlags SUBSTRING_DIRECTION_MASK
The mask for the flow direction for this substring.
Definition SDL3pp_ttf.h:299
ResourceShared< TextEngine > TextEngineShared
Handle to a shared textEngine.
Definition SDL3pp_ttf.h:85
TTF_HorizontalAlignment HorizontalAlignment
The horizontal alignment used when rendering wrapped text.
Definition SDL3pp_ttf.h:213
constexpr Direction DIRECTION_TTB
Top to Bottom.
Definition SDL3pp_ttf.h:252
constexpr HintingFlags HINTING_LIGHT_SUBPIXEL
Light hinting with subpixel rendering for more precise font edges.
Definition SDL3pp_ttf.h:199
constexpr HorizontalAlignment HORIZONTAL_ALIGN_LEFT
LEFT.
Definition SDL3pp_ttf.h:218
TTF_Direction Direction
Direction flags.
Definition SDL3pp_ttf.h:244
constexpr ImageType IMAGE_SDF
The alpha channel has signed distance field information.
Definition SDL3pp_ttf.h:281
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_CLOCKWISE
CLOCKWISE.
Definition SDL3pp_ttf.h:337
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
A structure that represents a color as RGBA components.
Definition SDL3pp_pixels.h:1638
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition SDL3pp_pixels.h:1833
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:487
The internal structure containing font information.
Definition SDL3pp_ttf.h:444
Direction GetDirection() const
Get the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:1077
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:1546
Surface RenderGlyph_Shaded(Uint32 ch, Color fg, Color bg) const
Render a single UNICODE codepoint at high quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:1623
int GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const
Query the kerning size between the glyphs of two UNICODE codepoints.
Definition SDL3pp_ttf.h:1262
const char * GetStyleName() const
Query a font's style name.
Definition SDL3pp_ttf.h:1042
void GetStringSizeWrapped(std::string_view text, int wrap_width, int *w, int *h) const
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:1361
Uint32 GetGeneration() const
Get the font generation.
Definition SDL3pp_ttf.h:505
bool GetKerning() const
Query whether or not kerning is enabled for a font.
Definition SDL3pp_ttf.h:976
static Uint32 GetGlyphScript(Uint32 ch)
Get the script used by a 32-bit codepoint.
Definition SDL3pp_ttf.h:1133
Point GetStringSize(std::string_view text) const
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:1283
void SetSize(float ptsize)
Set a font's size dynamically.
Definition SDL3pp_ttf.h:585
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:1239
HorizontalAlignment GetWrapAlignment() const
Query a font's current wrap alignment option.
Definition SDL3pp_ttf.h:871
Surface RenderGlyph_LCD(Uint32 ch, Color fg, Color bg) const
Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB surface.
Definition SDL3pp_ttf.h:1843
int GetOutline() const
Query a font's current outline.
Definition SDL3pp_ttf.h:728
void SetLineSkip(int lineskip)
Set the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:929
void SetWrapAlignment(HorizontalAlignment align)
Set a font's current wrap alignment option.
Definition SDL3pp_ttf.h:855
void SetKerning(bool enabled)
Set if kerning is enabled for a font.
Definition SDL3pp_ttf.h:963
HintingFlags GetHinting() const
Query a font's current FreeType hinter setting.
Definition SDL3pp_ttf.h:786
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:1767
void RemoveFallback(FontRef fallback)
Remove a fallback font.
Definition SDL3pp_ttf.h:548
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:1659
FontStyleFlags GetStyle() const
Query a font's current style.
Definition SDL3pp_ttf.h:690
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:1696
void SetScript(Uint32 script)
Set the script to be used for text shaping by a font.
Definition SDL3pp_ttf.h:1097
int GetNumFaces() const
Query the number of faces of a font.
Definition SDL3pp_ttf.h:764
int GetLineSkip() const
Query the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:942
int GetHeight() const
Query the total height of a font.
Definition SDL3pp_ttf.h:887
void SetOutline(int outline)
Set a font's current outline.
Definition SDL3pp_ttf.h:712
void SetSDF(bool enabled)
Enable Signed Distance Field rendering for a font.
Definition SDL3pp_ttf.h:810
SurfaceRef GetGlyphImage(Uint32 ch, ImageType *image_type=nullptr) const
Get the pixel image for a UNICODE codepoint.
Definition SDL3pp_ttf.h:1184
int GetAscent() const
Query the offset from the baseline to the top of a font.
Definition SDL3pp_ttf.h:900
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:1332
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:1586
int GetDescent() const
Query the offset from the baseline to the bottom of a font.
Definition SDL3pp_ttf.h:913
bool GetSDF() const
Query whether Signed Distance Field rendering is enabled for a font.
Definition SDL3pp_ttf.h:823
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:1437
SurfaceRef GetGlyphImageForIndex(Uint32 glyph_index, ImageType *image_type=nullptr) const
Get the pixel image for a character index.
Definition SDL3pp_ttf.h:1206
static void reset(TTF_Font *resource)
Dispose of a previously-created font.
Definition SDL3pp_ttf.h:1870
Uint32 GetScript() const
Get the script used for text shaping a font.
Definition SDL3pp_ttf.h:1116
void AddFallback(FontRef fallback)
Add a fallback font.
Definition SDL3pp_ttf.h:528
bool IsFixedWidth() const
Query whether a font is fixed-width.
Definition SDL3pp_ttf.h:993
void SetSizeDPI(float ptsize, int hdpi, int vdpi)
Set font size dynamically with target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:606
bool HasGlyph(Uint32 ch) const
Check whether a glyph is provided by the font for a UNICODE codepoint.
Definition SDL3pp_ttf.h:1168
void GetDPI(int *hdpi, int *vdpi) const
Get font target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:641
Surface RenderGlyph_Blended(Uint32 ch, Color fg) const
Render a single UNICODE codepoint at high quality to a new ARGB surface.
Definition SDL3pp_ttf.h:1730
bool IsScalable() const
Query whether a font is scalable or not.
Definition SDL3pp_ttf.h:1008
float GetSize() const
Get the size of a font.
Definition SDL3pp_ttf.h:625
void SetHinting(HintingFlags hinting)
Set a font's current hinter setting.
Definition SDL3pp_ttf.h:753
void SetDirection(Direction direction)
Set the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:1060
PropertiesRef GetProperties()
Get the properties associated with a font.
Definition SDL3pp_ttf.h:486
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:1806
int GetWeight() const
Query a font's weight, in terms of the lightness/heaviness of the strokes.
Definition SDL3pp_ttf.h:837
void SetStyle(FontStyleFlags style)
Set a font's current style.
Definition SDL3pp_ttf.h:669
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:1392
Surface RenderGlyph_Solid(Uint32 ch, Color fg) const
Render a single 32-bit glyph at fast quality to a new 8-bit surface.
Definition SDL3pp_ttf.h:1508
void SetLanguage(StringParam language_bcp47)
Set language to be used for text shaping by a font.
Definition SDL3pp_ttf.h:1152
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:1474
const char * GetFamilyName() const
Query a font's family name.
Definition SDL3pp_ttf.h:1025
void ClearFallbacks()
Remove all fallback fonts.
Definition SDL3pp_ttf.h:567
void GetStringSize(std::string_view text, int *w, int *h) const
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:1306
Unsafe Handle to font.
Definition SDL3pp_ttf.h:2022
constexpr FontUnsafe(Font &&other)
Constructs FontUnsafe from Font.
Definition SDL3pp_ttf.h:2028
Handle to an owned font.
Definition SDL3pp_ttf.h:1881
static Font Open(IOStreamRef src, float ptsize)
Create a font from an IOStreamRef, using a specified point size.
Definition SDL3pp_ttf.h:1925
static Font Open(StringParam file, float ptsize)
Create a font from a file, using a specified point size.
Definition SDL3pp_ttf.h:1902
static Font OpenWithProperties(PropertiesRef props)
Create a font with the specified properties.
Definition SDL3pp_ttf.h:1973
void Close()
Dispose of a previously-created font.
Definition SDL3pp_ttf.h:1998
The read/write operation structure.
Definition SDL3pp_iostream.h:123
Initialization flags for SDL satellite libraries.
Definition SDL3pp_init.h:80
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:46
SDL properties ID.
Definition SDL3pp_properties.h:209
A structure representing rendering state.
Definition SDL3pp_render.h:182
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:153
Handle to an owned surface.
Definition SDL3pp_surface.h:1824
A text engine used to create text objects.
Definition SDL3pp_ttf.h:2072
GPUTextEngineWinding GetGPUWinding() const
Get the winding order of the vertices returned by TextRef.GetGPUDrawData for a particular GPU text en...
Definition SDL3pp_ttf.h:2107
static void DestroySurface(TTF_TextEngine *engine)
Destroy a text engine created for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:2127
static void DestroyRenderer(TTF_TextEngine *engine)
Destroy a text engine created for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:2148
void SetGPUWinding(GPUTextEngineWinding winding)
Sets the winding order of the vertices returned by TextRef.GetGPUDrawData for a particular GPU text e...
Definition SDL3pp_ttf.h:2088
static void DestroyGPU(TTF_TextEngine *engine)
Destroy a text engine created for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:2169
Unsafe Handle to textEngine.
Definition SDL3pp_ttf.h:2332
constexpr TextEngineUnsafe(TextEngine &&other)
Constructs TextEngineUnsafe from TextEngine.
Definition SDL3pp_ttf.h:2338
Handle to an owned textEngine.
Definition SDL3pp_ttf.h:2183
static TextEngine CreateGPU(SDL_GPUDevice *device)
Create a text engine for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:2274
static TextEngine CreateSurface()
Create a text engine for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:2199
static TextEngine CreateRendererWithProperties(PropertiesRef props)
Create a text engine for drawing text on an SDL renderer, with the specified properties.
Definition SDL3pp_ttf.h:2251
static TextEngine CreateRenderer(RendererRef renderer)
Create a text engine for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:2221
static TextEngine CreateGPUWithProperties(PropertiesRef props)
Create a text engine for drawing text with the SDL GPU API, with the specified properties.
Definition SDL3pp_ttf.h:2304
Text created with Text.Create()
Definition SDL3pp_ttf.h:2521
void Update()
Update the layout of a text object.
Definition SDL3pp_ttf.h:3412
SubStringIterator GetSubStringForPoint(Point p) const
Get the portion of a text string that is closest to a point.
Definition SDL3pp_ttf.h:3704
bool SetPosition(Point p)
Set the position of a text object.
Definition SDL3pp_ttf.h:2934
void InsertString(int offset, std::string_view string)
Insert UTF-8 text into a text object.
Definition SDL3pp_ttf.h:3108
void GetNextSubString(const SubString &substring, SubString *next) const
Get the next substring in a text object.
Definition SDL3pp_ttf.h:3393
Point GetSize() const
Get the size of a text object.
Definition SDL3pp_ttf.h:3179
void GetSubStringForPoint(Point p, SubString *substring) const
Get the portion of a text string that is closest to a point.
Definition SDL3pp_ttf.h:3352
void SetWrapWidth(int wrap_width)
Set whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:2995
void AppendString(std::string_view string)
Append UTF-8 text to a text object.
Definition SDL3pp_ttf.h:3131
void GetSubStringForLine(int line, SubString *substring) const
Get the substring of a text object that contains the given line.
Definition SDL3pp_ttf.h:3277
void SetEngine(TextEngineRef engine)
Set the text engine used by a text object.
Definition SDL3pp_ttf.h:2634
int GetWrapWidth() const
Get whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:3014
void SetScript(Uint32 script)
Set the script to be used for text shaping a text object.
Definition SDL3pp_ttf.h:2743
bool SetFont(FontRef font)
Set the font used by a text object.
Definition SDL3pp_ttf.h:2677
Direction GetDirection() const
Get the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:2725
void GetColor(FColor *c) const
Get the color of a text object.
Definition SDL3pp_ttf.h:2861
SubStringIterator end() const
Get iterator to one past last substring.
Definition SDL3pp_ttf.h:3690
void DrawSurface(Point p, SurfaceRef surface) const
Draw text to an SDL surface.
Definition SDL3pp_ttf.h:2543
Uint32 GetScript() const
Get the script used for text shaping a text object.
Definition SDL3pp_ttf.h:2765
void GetSize(int *w, int *h) const
Get the size of a text object.
Definition SDL3pp_ttf.h:3203
void SetDirection(Direction direction)
Set the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:2708
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:3418
void GetColor(float *r, float *g, float *b, float *a) const
Get the color of a text object.
Definition SDL3pp_ttf.h:2912
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:3312
void SetString(std::string_view string)
Set the UTF-8 text used by a text object.
Definition SDL3pp_ttf.h:3082
FontRef GetFont() const
Get the font used by a text object.
Definition SDL3pp_ttf.h:2692
void DeleteString(int offset, int length=-1)
Delete UTF-8 text from a text object.
Definition SDL3pp_ttf.h:3158
int GetNumLines() const
The number of lines in the text, 0 if it's empty.
Definition SDL3pp_ttf.h:3423
void SetColor(Color c)
Set the color of a text object.
Definition SDL3pp_ttf.h:2783
void SetColor(FColor c)
Set the color of a text object.
Definition SDL3pp_ttf.h:2804
GPUAtlasDrawSequence * GetGPUDrawData() const
Get the geometry data needed for drawing the text.
Definition SDL3pp_ttf.h:2598
void GetColor(Color *c) const
Get the color of a text object.
Definition SDL3pp_ttf.h:2841
PropertiesRef GetProperties() const
Get the properties associated with a text object.
Definition SDL3pp_ttf.h:2614
bool GetPosition(int *x, int *y) const
Get the position of a text object.
Definition SDL3pp_ttf.h:2974
static void reset(TTF_Text *resource)
Destroy a text object created by a text engine.
Definition SDL3pp_ttf.h:3437
SubStringIterator GetSubStringForLine(int line) const
Get iterator to substring of a text object that contains the given line.
Definition SDL3pp_ttf.h:3697
FColor GetColor() const
Get the color of a text object.
Definition SDL3pp_ttf.h:2820
void SetWrapWhitespaceVisible(bool visible)
Set whether whitespace should be visible when wrapping a text object.
Definition SDL3pp_ttf.h:3042
TextEngineRef GetEngine() const
Get the text engine used by a text object.
Definition SDL3pp_ttf.h:2652
void GetPreviousSubString(const SubString &substring, SubString *previous) const
Get the previous substring in a text object.
Definition SDL3pp_ttf.h:3372
void DrawRenderer(FPoint p) const
Draw text to an SDL renderer.
Definition SDL3pp_ttf.h:2567
bool IsWrapWhitespaceVisible() const
Return whether whitespace is shown when wrapping a text object.
Definition SDL3pp_ttf.h:3060
OwnArray< SubString * > GetSubStrings() const
Get all substrings of a text object.
Definition SDL3pp_ttf.h:3293
SubStringIterator begin() const
Get iterator to first substring.
Definition SDL3pp_ttf.h:3683
Point GetPosition() const
Get the position of a text object.
Definition SDL3pp_ttf.h:2950
void GetSubString(int offset, SubString *substring) const
Get the substring of a text object that surrounds a text offset.
Definition SDL3pp_ttf.h:3227
void GetColor(Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const
Get the color of a text object.
Definition SDL3pp_ttf.h:2887
Unsafe Handle to text.
Definition SDL3pp_ttf.h:3508
constexpr TextUnsafe(Text &&other)
Constructs TextUnsafe from Text.
Definition SDL3pp_ttf.h:3514
Handle to an owned text.
Definition SDL3pp_ttf.h:3448
static Text Create(TextEngineRef engine, FontRef font, std::string_view text)
Create a text object from UTF-8 text and a text engine.
Definition SDL3pp_ttf.h:3468
void Destroy()
Destroy a text object created by a text engine.
Definition SDL3pp_ttf.h:3484
Flag to init TTF.
Definition SDL3pp_ttf.h:39