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
42// Forward decl
43struct FontBase;
44
45// Forward decl
46struct FontRef;
47
48// Forward decl
49struct Font;
50
51// Forward decl
52struct TextEngineBase;
53
54// Forward decl
55struct TextEngineRef;
56
57// Forward decl
58struct TextEngine;
59
60// Forward decl
61struct TextBase;
62
63// Forward decl
64struct TextRef;
65
66// Forward decl
67struct Text;
68
86using FontStyleFlags = Uint32;
87
88constexpr FontStyleFlags STYLE_NORMAL = TTF_STYLE_NORMAL;
89
90constexpr FontStyleFlags STYLE_BOLD = TTF_STYLE_BOLD;
91
92constexpr FontStyleFlags STYLE_ITALIC = TTF_STYLE_ITALIC;
93
95 TTF_STYLE_UNDERLINE;
96
98 TTF_STYLE_STRIKETHROUGH;
99
101
119using HintingFlags = TTF_HintingFlags;
120
121constexpr HintingFlags HINTING_INVALID = TTF_HINTING_INVALID;
122
124 TTF_HINTING_NORMAL;
125
129constexpr HintingFlags HINTING_LIGHT = TTF_HINTING_LIGHT;
130
135constexpr HintingFlags HINTING_MONO = TTF_HINTING_MONO;
136
140constexpr HintingFlags HINTING_NONE = TTF_HINTING_NONE;
141
145constexpr HintingFlags HINTING_LIGHT_SUBPIXEL = TTF_HINTING_LIGHT_SUBPIXEL;
146
148
159using HorizontalAlignment = TTF_HorizontalAlignment;
160
162 TTF_HORIZONTAL_ALIGN_INVALID;
163
165 TTF_HORIZONTAL_ALIGN_LEFT;
166
168 TTF_HORIZONTAL_ALIGN_CENTER;
169
171 TTF_HORIZONTAL_ALIGN_RIGHT;
172
174
190using Direction = TTF_Direction;
191
192constexpr Direction DIRECTION_INVALID = TTF_DIRECTION_INVALID;
193
194constexpr Direction DIRECTION_LTR = TTF_DIRECTION_LTR;
195
196constexpr Direction DIRECTION_RTL = TTF_DIRECTION_RTL;
197
198constexpr Direction DIRECTION_TTB = TTF_DIRECTION_TTB;
199
200constexpr Direction DIRECTION_BTT = TTF_DIRECTION_BTT;
201
203
214using ImageType = TTF_ImageType;
215
216constexpr ImageType IMAGE_INVALID = TTF_IMAGE_INVALID;
217
219 TTF_IMAGE_ALPHA;
220
222 TTF_IMAGE_COLOR;
223
227constexpr ImageType IMAGE_SDF = TTF_IMAGE_SDF;
228
230
243using SubStringFlags = Uint32;
244
246 TTF_SUBSTRING_DIRECTION_MASK;
248
250 TTF_SUBSTRING_TEXT_START;
252
256constexpr SubStringFlags SUBSTRING_LINE_START = TTF_SUBSTRING_LINE_START;
257
261constexpr SubStringFlags SUBSTRING_LINE_END = TTF_SUBSTRING_LINE_END;
262
264 TTF_SUBSTRING_TEXT_END;
265
267
278using GPUTextEngineWinding = TTF_GPUTextEngineWinding;
279
281 TTF_GPU_TEXTENGINE_WINDING_INVALID;
282
284 TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE;
285
287 TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE;
288
290
291#ifdef SDL3PP_DOC
292
298#define SDL_TTF_MAJOR_VERSION
299
300#define SDL_TTF_MINOR_VERSION
301
302#define SDL_TTF_MICRO_VERSION
303
305
309#define SDL_TTF_VERSION \
310 SDL_VERSIONNUM( \
311 SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION)
312
316#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \
317 ((SDL_TTF_MAJOR_VERSION >= X) && \
318 (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \
319 (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || \
320 SDL_TTF_MICRO_VERSION >= Z))
321
322#endif // SDL3PP_DOC
323
333inline int TTF_Version() { return ::TTF_Version(); }
334
352inline void GetFreeTypeVersion(int* major, int* minor, int* patch)
353{
354 TTF_GetFreeTypeVersion(major, minor, patch);
355}
356
370inline void GetHarfBuzzVersion(int* major, int* minor, int* patch)
371{
372 TTF_GetHarfBuzzVersion(major, minor, patch);
373}
374
380using TextData = TTF_TextData;
381
390struct FontBase : Resource<TTF_Font*>
391{
392 using Resource::Resource;
393
410 FontBase(StringParam file, float ptsize)
411 : Resource(CheckError(TTF_OpenFont(file, ptsize)))
412 {
413 }
414
431 FontBase(IOStreamBase& src, float ptsize)
432 : Resource(CheckError(TTF_OpenFontIO(src.get(), false, ptsize)))
433 {
434 }
435
478 : Resource(CheckError(TTF_OpenFontWithProperties(props.get())))
479 {
480 }
481
496 Font Copy() const;
497
520 {
521 return CheckError(TTF_GetFontProperties(get()));
522 }
523
538 Uint32 GetGeneration() const { return TTF_GetFontGeneration(get()); }
539
561 void AddFallback(FontBase& fallback)
562 {
563 CheckError(TTF_AddFallbackFont(get(), fallback.get()));
564 }
565
581 void RemoveFallback(FontBase& fallback)
582 {
583 TTF_RemoveFallbackFont(get(), fallback.get());
584 }
585
600 void ClearFallbacks() { TTF_ClearFallbackFonts(get()); }
601
618 void SetSize(float ptsize) { CheckError(TTF_SetFontSize(get(), ptsize)); }
619
639 void SetSizeDPI(float ptsize, int hdpi, int vdpi)
640 {
641 CheckError(TTF_SetFontSizeDPI(get(), ptsize, hdpi, vdpi));
642 }
643
658 float GetSize() const { return TTF_GetFontSize(get()); }
659
674 void GetDPI(int* hdpi, int* vdpi) const
675 {
676 CheckError(TTF_GetFontDPI(get(), hdpi, vdpi));
677 }
678
702 void SetStyle(FontStyleFlags style) { TTF_SetFontStyle(get(), style); }
703
723 FontStyleFlags GetStyle() const { return TTF_GetFontStyle(get()); }
724
745 void SetOutline(int outline)
746 {
747 CheckError(TTF_SetFontOutline(get(), outline));
748 }
749
761 int GetOutline() const { return TTF_GetFontOutline(get()); }
762
786 void SetHinting(HintingFlags hinting) { TTF_SetFontHinting(get(), hinting); }
787
797 int GetNumFaces() const { return TTF_GetNumFontFaces(get()); }
798
819 HintingFlags GetHinting() const { return TTF_GetFontHinting(get()); }
820
843 void SetSDF(bool enabled) { CheckError(TTF_SetFontSDF(get(), enabled)); }
844
856 bool GetSDF() const { return TTF_GetFontSDF(get()); }
857
858#if SDL_TTF_VERSION_ATLEAST(3, 2, 2)
859
870 int GetWeight() const { return TTF_GetFontWeight(get()); }
871
872#endif // SDL_TTF_VERSION_ATLEAST(3, 2, 2)
873
889 {
890 TTF_SetFontWrapAlignment(get(), align);
891 }
892
905 {
906 return TTF_GetFontWrapAlignment(get());
907 }
908
920 int GetHeight() const { return TTF_GetFontHeight(get()); }
921
933 int GetAscent() const { return TTF_GetFontAscent(get()); }
934
946 int GetDescent() const { return TTF_GetFontDescent(get()); }
947
962 void SetLineSkip(int lineskip) { TTF_SetFontLineSkip(get(), lineskip); }
963
975 int GetLineSkip() const { return TTF_GetFontLineSkip(get()); }
976
996 void SetKerning(bool enabled) { TTF_SetFontKerning(get(), enabled); }
997
1009 bool GetKerning() const { return TTF_GetFontKerning(get()); }
1010
1026 bool IsFixedWidth() const { return TTF_FontIsFixedWidth(get()); }
1027
1041 bool IsScalable() const { return TTF_FontIsScalable(get()); }
1042
1058 const char* GetFamilyName() const { return TTF_GetFontFamilyName(get()); }
1059
1075 const char* GetStyleName() const { return TTF_GetFontStyleName(get()); }
1076
1093 void SetDirection(Direction direction)
1094 {
1095 CheckError(TTF_SetFontDirection(get(), direction));
1096 }
1097
1110 Direction GetDirection() const { return TTF_GetFontDirection(get()); }
1111
1130 void SetScript(Uint32 script)
1131 {
1132 CheckError(TTF_SetFontScript(get(), script));
1133 }
1134
1149 Uint32 GetScript() const { return TTF_GetFontScript(get()); }
1150
1166 static Uint32 GetGlyphScript(Uint32 ch) { return TTF_GetGlyphScript(ch); }
1167
1185 void SetLanguage(StringParam language_bcp47)
1186 {
1187 CheckError(TTF_SetFontLanguage(get(), language_bcp47));
1188 }
1189
1201 bool HasGlyph(Uint32 ch) const { return TTF_FontHasGlyph(get(), ch); }
1202
1217 SurfaceRef GetGlyphImage(Uint32 ch, ImageType* image_type = nullptr) const
1218 {
1219 return TTF_GetGlyphImage(get(), ch, image_type);
1220 }
1221
1240 ImageType* image_type = nullptr) const
1241 {
1242 return TTF_GetGlyphImageForIndex(get(), glyph_index, image_type);
1243 }
1244
1272 void GetGlyphMetrics(Uint32 ch,
1273 int* minx,
1274 int* maxx,
1275 int* miny,
1276 int* maxy,
1277 int* advance) const
1278 {
1279 CheckError(TTF_GetGlyphMetrics(get(), ch, minx, maxx, miny, maxy, advance));
1280 }
1281
1295 int GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const
1296 {
1297 if (int r; TTF_GetGlyphKerning(get(), previous_ch, ch, &r)) return r;
1298 throw Error();
1299 }
1300
1316 Point GetStringSize(std::string_view text) const
1317 {
1318 Point p;
1319 GetStringSize(text, &p.x, &p.y);
1320 return p;
1321 }
1322
1339 void GetStringSize(std::string_view text, int* w, int* h) const
1340 {
1341 CheckError(TTF_GetStringSize(get(), text.data(), text.size(), w, h));
1342 }
1343
1365 Point GetStringSizeWrapped(std::string_view text, int wrap_width) const
1366 {
1367 Point p;
1368 GetStringSizeWrapped(text, wrap_width, &p.x, &p.y);
1369 return p;
1370 }
1371
1394 void GetStringSizeWrapped(std::string_view text,
1395 int wrap_width,
1396 int* w,
1397 int* h) const
1398 {
1399 CheckError(TTF_GetStringSizeWrapped(
1400 get(), text.data(), text.size(), wrap_width, w, h));
1401 }
1402
1425 void MeasureString(std::string_view text,
1426 int max_width,
1427 int* measured_width,
1428 size_t* measured_length) const
1429 {
1430 CheckError(TTF_MeasureString(get(),
1431 text.data(),
1432 text.size(),
1433 max_width,
1434 measured_width,
1435 measured_length));
1436 }
1437
1470 Surface RenderText_Solid(std::string_view text, Color fg) const
1471 {
1472 return Surface{TTF_RenderText_Solid(get(), text.data(), text.size(), fg)};
1473 }
1474
1507 Surface RenderText_Solid_Wrapped(std::string_view text,
1508 Color fg,
1509 int wrapLength) const
1510 {
1511 return Surface{TTF_RenderText_Solid_Wrapped(
1512 get(), text.data(), text.size(), fg, wrapLength)};
1513 }
1514
1541 Surface RenderGlyph_Solid(Uint32 ch, Color fg) const
1542 {
1543 return Surface{TTF_RenderGlyph_Solid(get(), ch, fg)};
1544 }
1545
1579 Surface RenderText_Shaded(std::string_view text, Color fg, Color bg) const
1580 {
1581 return Surface{
1582 TTF_RenderText_Shaded(get(), text.data(), text.size(), fg, bg)};
1583 }
1584
1619 Surface RenderText_Shaded_Wrapped(std::string_view text,
1620 Color fg,
1621 Color bg,
1622 int wrap_width) const
1623 {
1624 return Surface{TTF_RenderText_Shaded_Wrapped(
1625 get(), text.data(), text.size(), fg, bg, wrap_width)};
1626 }
1627
1656 Surface RenderGlyph_Shaded(Uint32 ch, Color fg, Color bg) const
1657 {
1658 return Surface{TTF_RenderGlyph_Shaded(get(), ch, fg, bg)};
1659 }
1660
1692 Surface RenderText_Blended(std::string_view text, Color fg) const
1693 {
1694 return Surface{TTF_RenderText_Blended(get(), text.data(), text.size(), fg)};
1695 }
1696
1730 Color fg,
1731 int wrap_width) const
1732 {
1733 return Surface{TTF_RenderText_Blended_Wrapped(
1734 get(), text.data(), text.size(), fg, wrap_width)};
1735 }
1736
1763 Surface RenderGlyph_Blended(Uint32 ch, Color fg) const
1764 {
1765 return Surface{TTF_RenderGlyph_Blended(get(), ch, fg)};
1766 }
1767
1800 Surface RenderText_LCD(std::string_view text, Color fg, Color bg) const
1801 {
1802 return Surface{TTF_RenderText_LCD(get(), text.data(), text.size(), fg, bg)};
1803 }
1804
1839 Surface RenderText_LCD_Wrapped(std::string_view text,
1840 Color fg,
1841 Color bg,
1842 int wrap_width) const
1843 {
1844 return Surface{TTF_RenderText_LCD_Wrapped(
1845 get(), text.data(), text.size(), fg, bg, wrap_width)};
1846 }
1847
1876 Surface RenderGlyph_LCD(Uint32 ch, Color fg, Color bg) const
1877 {
1878 return Surface{TTF_RenderGlyph_LCD(get(), ch, fg, bg)};
1879 }
1880};
1881
1891{
1892 using FontBase::FontBase;
1893
1897 constexpr FontRef(const FontRef& other)
1898 : FontBase(other.get())
1899 {
1900 }
1901
1905 constexpr FontRef(FontRef&& other)
1906 : FontBase(other.release())
1907 {
1908 }
1909
1913 constexpr ~FontRef() = default;
1914
1919 {
1920 release(other.release());
1921 return *this;
1922 }
1923
1943 void reset(TTF_Font* newResource = {})
1944 {
1945 TTF_CloseFont(release(newResource));
1946 }
1947};
1948
1958{
1959 using FontRef::FontRef;
1960
1964 constexpr explicit Font(TTF_Font* resource = {})
1965 : FontRef(resource)
1966 {
1967 }
1968
1969 constexpr Font(const Font& other) = delete;
1970
1974 constexpr Font(Font&& other) = default;
1975
1979 ~Font() { reset(); }
1980
1985 {
1986 reset(other.release());
1987 return *this;
1988 }
1989};
1990
2007inline void InitSubSystem(TtfInitFlag _) { CheckError(TTF_Init()); }
2008
2029struct TextEngineBase : Resource<TTF_TextEngine*>
2030{
2031 using Resource::Resource;
2032
2033protected:
2035 void (*m_destroy)(TTF_TextEngine* engine) = nullptr;
2036
2037public:
2039 constexpr TextEngineBase(TTF_TextEngine* engine,
2040 void (*destroy)(TTF_TextEngine* engine))
2041 : Resource(engine)
2042 , m_destroy(destroy)
2043 {
2044 }
2045
2060 {
2061 TTF_SetGPUTextEngineWinding(get(), winding);
2062 }
2063
2079 {
2080 return TTF_GetGPUTextEngineWinding(get());
2081 }
2082};
2083
2093{
2095
2099 constexpr TextEngineRef(const TextEngineRef& other)
2100 : TextEngineBase(other.get(), other.m_destroy)
2101 {
2102 }
2103
2107 constexpr TextEngineRef(TextEngineRef&& other)
2108 : TextEngineBase(other.release(), other.m_destroy)
2109 {
2110 }
2111
2115 constexpr ~TextEngineRef() = default;
2116
2121 {
2122 release(other.release());
2123 m_destroy = other.m_destroy;
2124 other.m_destroy = nullptr;
2125 return *this;
2126 }
2127
2131 void reset(TTF_TextEngine* newResource = {})
2132 {
2133 auto prevValue = release(newResource);
2134 if (m_destroy) m_destroy(prevValue);
2135 m_destroy = nullptr;
2136 }
2137};
2138
2148{
2150
2154 constexpr explicit TextEngine(TTF_TextEngine* resource = {})
2155 : TextEngineRef(resource)
2156 {
2157 }
2158
2159 constexpr TextEngine(const TextEngine& other) = delete;
2160
2164 constexpr TextEngine(TextEngine&& other) = default;
2165
2170
2175 {
2176 reset(other.release());
2177 m_destroy = other.m_destroy;
2178 other.m_destroy = nullptr;
2179 return *this;
2180 }
2181};
2182
2190using GPUAtlasDrawSequence = TTF_GPUAtlasDrawSequence;
2191
2205using SubString = TTF_SubString;
2206
2207// Forward decl
2208struct SubStringIterator;
2209
2210namespace prop::Font {
2211
2212constexpr auto CREATE_FILENAME_STRING = TTF_PROP_FONT_CREATE_FILENAME_STRING;
2213
2214constexpr auto CREATE_IOSTREAM_POINTER = TTF_PROP_FONT_CREATE_IOSTREAM_POINTER;
2215
2216constexpr auto CREATE_IOSTREAM_OFFSET_NUMBER =
2217 TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER;
2218
2219constexpr auto CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN =
2220 TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN;
2221
2222constexpr auto CREATE_SIZE_FLOAT = TTF_PROP_FONT_CREATE_SIZE_FLOAT;
2223
2224constexpr auto CREATE_FACE_NUMBER = TTF_PROP_FONT_CREATE_FACE_NUMBER;
2225
2226constexpr auto CREATE_HORIZONTAL_DPI_NUMBER =
2227 TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER;
2228
2229constexpr auto CREATE_VERTICAL_DPI_NUMBER =
2230 TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER;
2231
2232constexpr auto CREATE_EXISTING_FONT = TTF_PROP_FONT_CREATE_EXISTING_FONT;
2233
2234constexpr auto OUTLINE_LINE_CAP_NUMBER = TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER;
2235
2236constexpr auto OUTLINE_LINE_JOIN_NUMBER =
2237 TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER;
2238
2239constexpr auto OUTLINE_MITER_LIMIT_NUMBER =
2240 TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER;
2241
2242} // namespace prop::Font
2243
2244inline Font FontBase::Copy() const { return Font{TTF_CopyFont(get())}; }
2245
2246#ifdef SDL3PP_DOC
2247
2251#define SDL_FONT_WEIGHT_THIN TTF_FONT_WEIGHT_THIN
2252
2256#define SDL_FONT_WEIGHT_EXTRA_LIGHT TTF_FONT_WEIGHT_EXTRA_LIGHT
2257
2261#define SDL_FONT_WEIGHT_LIGHT TTF_FONT_WEIGHT_LIGHT
2262
2266#define SDL_FONT_WEIGHT_NORMAL TTF_FONT_WEIGHT_NORMAL
2267
2271#define SDL_FONT_WEIGHT_MEDIUM TTF_FONT_WEIGHT_MEDIUM
2272
2276#define SDL_FONT_WEIGHT_SEMI_BOLD TTF_FONT_WEIGHT_SEMI_BOLD
2277
2281#define SDL_FONT_WEIGHT_BOLD TTF_FONT_WEIGHT_BOLD
2282
2286#define SDL_FONT_WEIGHT_EXTRA_BOLD TTF_FONT_WEIGHT_EXTRA_BOLD
2287
2291#define SDL_FONT_WEIGHT_BLACK TTF_FONT_WEIGHT_BLACK
2292
2296#define SDL_FONT_WEIGHT_EXTRA_BLACK TTF_FONT_WEIGHT_EXTRA_BLACK
2297
2298#endif // SDL3PP_DOC
2299
2312inline Uint32 StringToTag(StringParam string)
2313{
2314 return TTF_StringToTag(string);
2315}
2316
2332inline void TagToString(Uint32 tag, char* string, size_t size)
2333{
2334 TTF_TagToString(tag, string, size);
2335}
2336
2349struct TextBase : Resource<TTF_Text*>
2350{
2351 using Resource::Resource;
2352
2372 void DrawSurface(Point p, SurfaceRef surface) const
2373 {
2374 CheckError(TTF_DrawSurfaceText(get(), p.x, p.y, surface.get()));
2375 }
2376
2396 void DrawRenderer(FPoint p) const
2397 {
2398 CheckError(TTF_DrawRendererText(get(), p.x, p.y));
2399 }
2400
2428 {
2429 return TTF_GetGPUTextDrawData(get());
2430 }
2431
2449 TextBase(TextEngineBase& engine, FontRef font, std::string_view text)
2450 : Resource(
2451 TTF_CreateText(engine.get(), font.get(), text.data(), text.size()))
2452 {
2453 }
2454
2467 {
2468 return CheckError(TTF_GetTextProperties(get()));
2469 }
2470
2487 {
2488 CheckError(TTF_SetTextEngine(get(), engine.get()));
2489 }
2490
2505 {
2506 return CheckError(TTF_GetTextEngine(get()));
2507 }
2508
2529 bool SetFont(FontBase& font) { return TTF_SetTextFont(get(), font.get()); }
2530
2544 FontRef GetFont() const { return CheckError(TTF_GetTextFont(get())); }
2545
2560 void SetDirection(Direction direction)
2561 {
2562 CheckError(TTF_SetTextDirection(get(), direction));
2563 }
2564
2577 Direction GetDirection() const { return TTF_GetTextDirection(get()); }
2578
2595 void SetScript(Uint32 script)
2596 {
2597 CheckError(TTF_SetTextScript(get(), script));
2598 }
2599
2617 Uint32 GetScript() const { return TTF_GetTextScript(get()); }
2618
2636 {
2637 CheckError(TTF_SetTextColor(get(), c.r, c.g, c.b, c.a));
2638 }
2639
2657 {
2658 CheckError(TTF_SetTextColorFloat(get(), c.r, c.g, c.b, c.a));
2659 }
2660
2673 {
2674 FColor c;
2675 GetColor(&c);
2676 return c;
2677 }
2678
2693 void GetColor(Color* c) const
2694 {
2695 SDL_assert_paranoid(c != nullptr);
2696 GetColor(&c->r, &c->g, &c->b, &c->a);
2697 }
2698
2713 void GetColor(FColor* c) const
2714 {
2715 SDL_assert_paranoid(c != nullptr);
2716 GetColor(&c->r, &c->g, &c->b, &c->a);
2717 }
2718
2739 void GetColor(Uint8* r, Uint8* g, Uint8* b, Uint8* a) const
2740 {
2741 CheckError(TTF_GetTextColor(get(), r, g, b, a));
2742 }
2743
2764 void GetColor(float* r, float* g, float* b, float* a) const
2765 {
2766 CheckError(TTF_GetTextColorFloat(get(), r, g, b, a));
2767 }
2768
2786 bool SetPosition(Point p) { return TTF_SetTextPosition(get(), p.x, p.y); }
2787
2803 {
2804 Point p;
2805 GetPosition(&p.x, &p.y);
2806 return p;
2807 }
2808
2826 bool GetPosition(int* x, int* y) const
2827 {
2828 return TTF_GetTextPosition(get(), x, y);
2829 }
2830
2847 void SetWrapWidth(int wrap_width)
2848 {
2849 CheckError(TTF_SetTextWrapWidth(get(), wrap_width));
2850 }
2851
2866 int GetWrapWidth() const
2867 {
2868 int w;
2869 CheckError(TTF_GetTextWrapWidth(get(), &w));
2870 return w;
2871 }
2872
2894 void SetWrapWhitespaceVisible(bool visible)
2895 {
2896 CheckError(TTF_SetTextWrapWhitespaceVisible(get(), visible));
2897 }
2898
2913 {
2914 return TTF_TextWrapWhitespaceVisible(get());
2915 }
2916
2934 void SetString(std::string_view string)
2935 {
2936 CheckError(TTF_SetTextString(get(), string.data(), string.size()));
2937 }
2938
2960 void InsertString(int offset, std::string_view string)
2961 {
2962 CheckError(
2963 TTF_InsertTextString(get(), offset, string.data(), string.size()));
2964 }
2965
2983 void AppendString(std::string_view string)
2984 {
2985 CheckError(TTF_AppendTextString(get(), string.data(), string.size()));
2986 }
2987
3010 void DeleteString(int offset, int length = -1)
3011 {
3012 CheckError(TTF_DeleteTextString(get(), offset, length));
3013 }
3014
3032 {
3033 Point p;
3034 GetSize(&p.x, &p.y);
3035 return p;
3036 }
3037
3057 void GetSize(int* w, int* h) const
3058 {
3059 CheckError(TTF_GetTextSize(get(), w, h));
3060 }
3061
3081 void GetSubString(int offset, SubString* substring) const
3082 {
3083 CheckError(TTF_GetTextSubString(get(), offset, substring));
3084 }
3085
3089 SubStringIterator begin() const;
3090
3094 SubStringIterator end() const;
3095
3111 SubStringIterator GetSubStringForLine(int line) const;
3112
3131 void GetSubStringForLine(int line, SubString* substring) const
3132 {
3133 CheckError(TTF_GetTextSubStringForLine(get(), line, substring));
3134 }
3135
3148 {
3149 return GetSubStringsForRange(0);
3150 }
3151
3166 OwnArray<SubString*> GetSubStringsForRange(int offset, int length = -1) const
3167 {
3168 int count = 0;
3169 auto data = TTF_GetTextSubStringsForRange(get(), offset, length, &count);
3170 return OwnArray<SubString*>{data, size_t(count)};
3171 }
3172
3189
3206 void GetSubStringForPoint(Point p, SubString* substring) const
3207 {
3208 CheckError(TTF_GetTextSubStringForPoint(get(), p.x, p.y, substring));
3209 }
3210
3226 void GetPreviousSubString(const SubString& substring,
3227 SubString* previous) const
3228 {
3229 CheckError(TTF_GetPreviousTextSubString(get(), &substring, previous));
3230 }
3231
3247 void GetNextSubString(const SubString& substring, SubString* next) const
3248 {
3249 CheckError(TTF_GetNextTextSubString(get(), &substring, next));
3250 }
3251
3266 void Update() { CheckError(TTF_UpdateText(get())); }
3267
3272 const char* GetText() const { return get()->text; }
3273
3277 int GetNumLines() const { return get()->num_lines; }
3278};
3279
3289{
3290 using TextBase::TextBase;
3291
3295 constexpr TextRef(const TextRef& other)
3296 : TextBase(other.get())
3297 {
3298 }
3299
3303 constexpr TextRef(TextRef&& other)
3304 : TextBase(other.release())
3305 {
3306 }
3307
3311 constexpr ~TextRef() = default;
3312
3317 {
3318 release(other.release());
3319 return *this;
3320 }
3321
3332 void reset(TTF_Text* newResource = {})
3333 {
3334 TTF_DestroyText(release(newResource));
3335 }
3336};
3337
3347{
3348 using TextRef::TextRef;
3349
3353 constexpr explicit Text(TTF_Text* resource = {})
3354 : TextRef(resource)
3355 {
3356 }
3357
3358 constexpr Text(const Text& other) = delete;
3359
3363 constexpr Text(Text&& other) = default;
3364
3368 ~Text() { reset(); }
3369
3374 {
3375 reset(other.release());
3376 return *this;
3377 }
3378};
3379
3385{
3386 TextRef m_text;
3387
3388 SubString m_subString;
3389
3390 constexpr SubStringIterator(TextRef text)
3391 : m_text(std::move(text))
3392 , m_subString(0)
3393 {
3394 }
3395
3396public:
3399 : SubStringIterator(nullptr)
3400 {
3401 }
3402
3404 constexpr operator bool() const { return m_text != nullptr; }
3405
3407 constexpr const SubString& operator*() const { return m_subString; }
3408
3410 constexpr const SubString* operator->() const { return &m_subString; }
3411
3413 constexpr bool operator==(const SubStringIterator& other) const
3414 {
3415 return m_subString.offset == other.m_subString.offset;
3416 }
3417
3420 {
3421 m_text.GetNextSubString(m_subString, &m_subString);
3422 return *this;
3423 }
3424
3427 {
3428 auto curr = *this;
3429 m_text.GetNextSubString(m_subString, &m_subString);
3430 return curr;
3431 }
3432
3435 {
3436 m_text.GetPreviousSubString(m_subString, &m_subString);
3437 return *this;
3438 }
3439
3442 {
3443 auto curr = *this;
3444 m_text.GetPreviousSubString(m_subString, &m_subString);
3445 return curr;
3446 }
3447
3448 friend class TextBase;
3449};
3450
3465{
3466 return TextEngine{TTF_CreateSurfaceTextEngine(),
3467 TTF_DestroySurfaceTextEngine};
3468}
3469
3487{
3488 return TextEngine{TTF_CreateRendererTextEngine(renderer.get()),
3489 TTF_DestroyRendererTextEngine};
3490}
3491
3517{
3518 return TextEngine{TTF_CreateRendererTextEngineWithProperties(props.get()),
3519 TTF_DestroyRendererTextEngine};
3520}
3521
3522namespace prop::RendererTextEngine {
3523
3524constexpr auto RENDERER = TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER;
3525
3526constexpr auto ATLAS_TEXTURE_SIZE =
3527 TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE;
3528
3529} // namespace prop::RendererTextEngine
3530
3548inline TextEngine CreateGPUTextEngine(SDL_GPUDevice* device)
3549{
3550 return TextEngine{TTF_CreateGPUTextEngine(device), TTF_DestroyGPUTextEngine};
3551}
3552
3578{
3579 return TextEngine{TTF_CreateGPUTextEngineWithProperties(props.get()),
3580 TTF_DestroyGPUTextEngine};
3581}
3582
3583namespace prop::GpuTextEngine {
3584
3585constexpr auto DEVICE = TTF_PROP_GPU_TEXT_ENGINE_DEVICE;
3586
3587constexpr auto ATLAS_TEXTURE_SIZE = TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE;
3588
3589} // namespace prop::GpuTextEngine
3590
3610inline void QuitSubSystem(TtfInitFlag _) { TTF_Quit(); }
3611
3636inline int WasInit(TtfInitFlag _) { return TTF_WasInit(); }
3637
3639
3640#pragma region impl
3641
3643{
3644 SubStringIterator it{get()};
3645 GetSubString(0, &it.m_subString);
3646 return it;
3647}
3648
3650{
3651 SubStringIterator it{get()};
3652 GetSubString(INT_MAX, &it.m_subString);
3653 return it;
3654}
3655
3657{
3658 SubStringIterator it{get()};
3659 GetSubStringForLine(line, &it.m_subString);
3660 return it;
3661}
3662
3664{
3665 SubStringIterator it{get()};
3666 GetSubStringForPoint(p, &it.m_subString);
3667 return it;
3668}
3669
3670#pragma endregion impl
3671
3672} // namespace SDL
3673
3674#endif // defined(SDL3PP_ENABLE_TTF) || defined(SDL3PP_DOC)
3675
3676#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
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr TTF_Font * release(TTF_Font * newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr TTF_Font * get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Iterator for substrings.
Definition SDL3pp_ttf.h:3385
constexpr SubStringIterator()
Default constructor.
Definition SDL3pp_ttf.h:3398
constexpr SubStringIterator & operator--()
Decrement operator.
Definition SDL3pp_ttf.h:3434
constexpr const SubString & operator*() const
Retrieve SubString.
Definition SDL3pp_ttf.h:3407
constexpr const SubString * operator->() const
Retrieve SubString.
Definition SDL3pp_ttf.h:3410
constexpr bool operator==(const SubStringIterator &other) const
Comparison.
Definition SDL3pp_ttf.h:3413
constexpr SubStringIterator operator--(int)
Decrement operator.
Definition SDL3pp_ttf.h:3441
constexpr SubStringIterator operator++(int)
Increment operator.
Definition SDL3pp_ttf.h:3426
constexpr SubStringIterator & operator++()
Increment operator.
Definition SDL3pp_ttf.h:3419
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:374
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:283
bool WasInit(InitFlags flags)
Check if all of the specified subsystems which are currently initialized.
Definition SDL3pp_init.h:489
void QuitSubSystem(InitFlags flags)
Shut down specific SDL subsystems.
Definition SDL3pp_init.h:431
constexpr FontStyleFlags STYLE_NORMAL
No special style.
Definition SDL3pp_ttf.h:88
constexpr SubStringFlags SUBSTRING_LINE_END
This substring contains the end of line line_index
Definition SDL3pp_ttf.h:261
constexpr HintingFlags HINTING_LIGHT
Light hinting applies subtle adjustments to improve rendering.
Definition SDL3pp_ttf.h:129
TextEngine CreateSurfaceTextEngine()
Create a text engine for drawing text on SDL surfaces.
Definition SDL3pp_ttf.h:3464
constexpr HorizontalAlignment HORIZONTAL_ALIGN_CENTER
CENTER.
Definition SDL3pp_ttf.h:167
constexpr HorizontalAlignment HORIZONTAL_ALIGN_RIGHT
RIGHT.
Definition SDL3pp_ttf.h:170
TTF_GPUAtlasDrawSequence GPUAtlasDrawSequence
Draw sequence returned by TextBase.GetGPUDrawData.
Definition SDL3pp_ttf.h:2190
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE
COUNTER_CLOCKWISE.
Definition SDL3pp_ttf.h:286
constexpr SubStringFlags SUBSTRING_TEXT_START
This substring contains the beginning of the text.
Definition SDL3pp_ttf.h:249
constexpr SubStringFlags SUBSTRING_LINE_START
This substring contains the beginning of line line_index
Definition SDL3pp_ttf.h:256
TextEngine CreateGPUTextEngine(SDL_GPUDevice *device)
Create a text engine for drawing text with the SDL GPU API.
Definition SDL3pp_ttf.h:3548
constexpr Direction DIRECTION_LTR
Left to Right.
Definition SDL3pp_ttf.h:194
constexpr ImageType IMAGE_COLOR
The color channels have image data.
Definition SDL3pp_ttf.h:221
Uint32 StringToTag(StringParam string)
Convert from a 4 character string to a 32-bit tag.
Definition SDL3pp_ttf.h:2312
Uint32 SubStringFlags
Flags for SubString.
Definition SDL3pp_ttf.h:243
TTF_HintingFlags HintingFlags
Hinting flags for TTF (TrueType Fonts)
Definition SDL3pp_ttf.h:119
constexpr ImageType IMAGE_INVALID
INVALID.
Definition SDL3pp_ttf.h:216
int TTF_Version()
This function gets the version of the dynamically linked SDL_ttf library.
Definition SDL3pp_ttf.h:333
void GetHarfBuzzVersion(int *major, int *minor, int *patch)
Query the version of the HarfBuzz library in use.
Definition SDL3pp_ttf.h:370
constexpr HintingFlags HINTING_INVALID
INVALID.
Definition SDL3pp_ttf.h:121
Uint32 FontStyleFlags
Font style flags for FontBase.
Definition SDL3pp_ttf.h:86
constexpr Direction DIRECTION_BTT
Bottom to Top.
Definition SDL3pp_ttf.h:200
constexpr HintingFlags HINTING_MONO
Monochrome hinting adjusts the font for better rendering at lower resolutions.
Definition SDL3pp_ttf.h:135
constexpr FontStyleFlags STYLE_ITALIC
Italic style.
Definition SDL3pp_ttf.h:92
void GetFreeTypeVersion(int *major, int *minor, int *patch)
Query the version of the FreeType library in use.
Definition SDL3pp_ttf.h:352
void TagToString(Uint32 tag, char *string, size_t size)
Convert from a 32-bit tag to a 4 character string.
Definition SDL3pp_ttf.h:2332
TTF_GPUTextEngineWinding GPUTextEngineWinding
The winding order of the vertices returned by TextBase.GetGPUDrawData.
Definition SDL3pp_ttf.h:278
constexpr FontStyleFlags STYLE_BOLD
Bold style.
Definition SDL3pp_ttf.h:90
constexpr FontStyleFlags STYLE_STRIKETHROUGH
Strikethrough text.
Definition SDL3pp_ttf.h:97
Font Copy() const
Create a copy of an existing font.
Definition SDL3pp_ttf.h:2244
TextEngine CreateGPUTextEngineWithProperties(PropertiesBase &props)
Create a text engine for drawing text with the SDL GPU API, with the specified properties.
Definition SDL3pp_ttf.h:3577
constexpr Direction DIRECTION_RTL
Right to Left.
Definition SDL3pp_ttf.h:196
TTF_ImageType ImageType
The type of data in a glyph image.
Definition SDL3pp_ttf.h:214
TextEngine CreateRendererTextEngineWithProperties(PropertiesBase &props)
Create a text engine for drawing text on an SDL renderer, with the specified properties.
Definition SDL3pp_ttf.h:3516
SDL::TtfInitFlag INIT_TTF
Flag to init TTF support.
constexpr HintingFlags HINTING_NORMAL
Normal hinting applies standard grid-fitting.
Definition SDL3pp_ttf.h:123
constexpr HorizontalAlignment HORIZONTAL_ALIGN_INVALID
INVALID.
Definition SDL3pp_ttf.h:161
constexpr Direction DIRECTION_INVALID
INVALID.
Definition SDL3pp_ttf.h:192
constexpr HintingFlags HINTING_NONE
No hinting, the font is rendered without any grid-fitting.
Definition SDL3pp_ttf.h:140
TTF_SubString SubString
The representation of a substring within text.
Definition SDL3pp_ttf.h:2205
constexpr ImageType IMAGE_ALPHA
The color channels are white.
Definition SDL3pp_ttf.h:218
TextEngine CreateRendererTextEngine(RendererBase &renderer)
Create a text engine for drawing text on an SDL renderer.
Definition SDL3pp_ttf.h:3486
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_INVALID
INVALID.
Definition SDL3pp_ttf.h:280
TTF_TextData TextData
Internal data for TTF_Text.
Definition SDL3pp_ttf.h:380
constexpr FontStyleFlags STYLE_UNDERLINE
Underlined text.
Definition SDL3pp_ttf.h:94
constexpr SubStringFlags SUBSTRING_TEXT_END
This substring contains the end of the text.
Definition SDL3pp_ttf.h:263
constexpr SubStringFlags SUBSTRING_DIRECTION_MASK
The mask for the flow direction for this substring.
Definition SDL3pp_ttf.h:245
TTF_HorizontalAlignment HorizontalAlignment
The horizontal alignment used when rendering wrapped text.
Definition SDL3pp_ttf.h:159
constexpr Direction DIRECTION_TTB
Top to Bottom.
Definition SDL3pp_ttf.h:198
constexpr HintingFlags HINTING_LIGHT_SUBPIXEL
Light hinting with subpixel rendering for more precise font edges.
Definition SDL3pp_ttf.h:145
constexpr HorizontalAlignment HORIZONTAL_ALIGN_LEFT
LEFT.
Definition SDL3pp_ttf.h:164
TTF_Direction Direction
Direction flags.
Definition SDL3pp_ttf.h:190
constexpr ImageType IMAGE_SDF
The alpha channel has signed distance field information.
Definition SDL3pp_ttf.h:227
constexpr GPUTextEngineWinding GPU_TEXTENGINE_WINDING_CLOCKWISE
CLOCKWISE.
Definition SDL3pp_ttf.h:283
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:1621
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition SDL3pp_pixels.h:1816
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:479
The internal structure containing font information.
Definition SDL3pp_ttf.h:391
void SetHinting(HintingFlags hinting)
Set a font's current hinter setting.
Definition SDL3pp_ttf.h:786
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:1729
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:1579
void GetDPI(int *hdpi, int *vdpi) const
Get font target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:674
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:1692
void SetScript(Uint32 script)
Set the script to be used for text shaping by a font.
Definition SDL3pp_ttf.h:1130
bool GetKerning() const
Query whether or not kerning is enabled for a font.
Definition SDL3pp_ttf.h:1009
int GetDescent() const
Query the offset from the baseline to the bottom of a font.
Definition SDL3pp_ttf.h:946
void AddFallback(FontBase &fallback)
Add a fallback font.
Definition SDL3pp_ttf.h:561
bool IsFixedWidth() const
Query whether a font is fixed-width.
Definition SDL3pp_ttf.h:1026
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:1470
FontBase(StringParam file, float ptsize)
Create a font from a file, using a specified point size.
Definition SDL3pp_ttf.h:410
void SetSizeDPI(float ptsize, int hdpi, int vdpi)
Set font size dynamically with target resolutions, in dots per inch.
Definition SDL3pp_ttf.h:639
PropertiesRef GetProperties()
Get the properties associated with a font.
Definition SDL3pp_ttf.h:519
void SetOutline(int outline)
Set a font's current outline.
Definition SDL3pp_ttf.h:745
void SetWrapAlignment(HorizontalAlignment align)
Set a font's current wrap alignment option.
Definition SDL3pp_ttf.h:888
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:1394
int GetLineSkip() const
Query the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:975
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:1541
bool HasGlyph(Uint32 ch) const
Check whether a glyph is provided by the font for a UNICODE codepoint.
Definition SDL3pp_ttf.h:1201
void RemoveFallback(FontBase &fallback)
Remove a fallback font.
Definition SDL3pp_ttf.h:581
void SetSize(float ptsize)
Set a font's size dynamically.
Definition SDL3pp_ttf.h:618
Uint32 GetGeneration() const
Get the font generation.
Definition SDL3pp_ttf.h:538
SurfaceRef GetGlyphImage(Uint32 ch, ImageType *image_type=nullptr) const
Get the pixel image for a UNICODE codepoint.
Definition SDL3pp_ttf.h:1217
HorizontalAlignment GetWrapAlignment() const
Query a font's current wrap alignment option.
Definition SDL3pp_ttf.h:904
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:1365
Point GetStringSize(std::string_view text) const
Calculate the dimensions of a rendered string of UTF-8 text.
Definition SDL3pp_ttf.h:1316
int GetWeight() const
Query a font's weight, in terms of the lightness/heaviness of the strokes.
Definition SDL3pp_ttf.h:870
int GetNumFaces() const
Query the number of faces of a font.
Definition SDL3pp_ttf.h:797
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:1763
SurfaceRef GetGlyphImageForIndex(Uint32 glyph_index, ImageType *image_type=nullptr) const
Get the pixel image for a character index.
Definition SDL3pp_ttf.h:1239
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:1272
bool GetSDF() const
Query whether Signed Distance Field rendering is enabled for a font.
Definition SDL3pp_ttf.h:856
void SetDirection(Direction direction)
Set the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:1093
static Uint32 GetGlyphScript(Uint32 ch)
Get the script used by a 32-bit codepoint.
Definition SDL3pp_ttf.h:1166
void SetStyle(FontStyleFlags style)
Set a font's current style.
Definition SDL3pp_ttf.h:702
void SetLanguage(StringParam language_bcp47)
Set language to be used for text shaping by a font.
Definition SDL3pp_ttf.h:1185
const char * GetStyleName() const
Query a font's style name.
Definition SDL3pp_ttf.h:1075
int GetAscent() const
Query the offset from the baseline to the top of a font.
Definition SDL3pp_ttf.h:933
bool IsScalable() const
Query whether a font is scalable or not.
Definition SDL3pp_ttf.h:1041
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:1425
int GetOutline() const
Query a font's current outline.
Definition SDL3pp_ttf.h:761
void SetKerning(bool enabled)
Set if kerning is enabled for a font.
Definition SDL3pp_ttf.h:996
FontBase(PropertiesBase &props)
Create a font with the specified properties.
Definition SDL3pp_ttf.h:477
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:1507
FontBase(IOStreamBase &src, float ptsize)
Create a font from an IOStreamBase, using a specified point size.
Definition SDL3pp_ttf.h:431
float GetSize() const
Get the size of a font.
Definition SDL3pp_ttf.h:658
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:1339
void SetLineSkip(int lineskip)
Set the spacing between lines of text for a font.
Definition SDL3pp_ttf.h:962
const char * GetFamilyName() const
Query a font's family name.
Definition SDL3pp_ttf.h:1058
void ClearFallbacks()
Remove all fallback fonts.
Definition SDL3pp_ttf.h:600
int GetHeight() const
Query the total height of a font.
Definition SDL3pp_ttf.h:920
FontStyleFlags GetStyle() const
Query a font's current style.
Definition SDL3pp_ttf.h:723
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:1800
Uint32 GetScript() const
Get the script used for text shaping a font.
Definition SDL3pp_ttf.h:1149
void SetSDF(bool enabled)
Enable Signed Distance Field rendering for a font.
Definition SDL3pp_ttf.h:843
Direction GetDirection() const
Get the direction to be used for text shaping by a font.
Definition SDL3pp_ttf.h:1110
int GetGlyphKerning(Uint32 previous_ch, Uint32 ch) const
Query the kerning size between the glyphs of two UNICODE codepoints.
Definition SDL3pp_ttf.h:1295
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:1839
HintingFlags GetHinting() const
Query a font's current FreeType hinter setting.
Definition SDL3pp_ttf.h:819
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:1876
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:1656
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:1619
Handle to a non owned font.
Definition SDL3pp_ttf.h:1891
constexpr FontRef(FontRef &&other)
Move constructor.
Definition SDL3pp_ttf.h:1905
void reset(TTF_Font *newResource={})
Dispose of a previously-created font.
Definition SDL3pp_ttf.h:1943
constexpr ~FontRef()=default
Default constructor.
constexpr FontRef(const FontRef &other)
Copy constructor.
Definition SDL3pp_ttf.h:1897
FontRef & operator=(FontRef other)
Assignment operator.
Definition SDL3pp_ttf.h:1918
Handle to an owned font.
Definition SDL3pp_ttf.h:1958
constexpr Font(TTF_Font *resource={})
Constructs from the underlying resource.
Definition SDL3pp_ttf.h:1964
~Font()
Frees up resource when object goes out of scope.
Definition SDL3pp_ttf.h:1979
Font & operator=(Font other)
Assignment operator.
Definition SDL3pp_ttf.h:1984
constexpr Font(Font &&other)=default
Move constructor.
The read/write operation structure.
Definition SDL3pp_iostream.h:107
Initialization flags for SDL satellite libraries.
Definition SDL3pp_init.h:80
The structure that defines a point (using integers)
Definition SDL3pp_rect.h:41
Wrap properties id.
Definition SDL3pp_properties.h:203
Handle to a non owned properties.
Definition SDL3pp_properties.h:693
A structure representing rendering state.
Definition SDL3pp_render.h:157
Handle to a non owned surface.
Definition SDL3pp_surface.h:1814
Handle to an owned surface.
Definition SDL3pp_surface.h:1873
Text created with TextBase.TextBase()
Definition SDL3pp_ttf.h:2350
void GetColor(Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const
Get the color of a text object.
Definition SDL3pp_ttf.h:2739
OwnArray< SubString * > GetSubStrings() const
Get all substrings of a text object.
Definition SDL3pp_ttf.h:3147
bool IsWrapWhitespaceVisible() const
Return whether whitespace is shown when wrapping a text object.
Definition SDL3pp_ttf.h:2912
void GetSize(int *w, int *h) const
Get the size of a text object.
Definition SDL3pp_ttf.h:3057
void SetWrapWidth(int wrap_width)
Set whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:2847
FontRef GetFont() const
Get the font used by a text object.
Definition SDL3pp_ttf.h:2544
int GetNumLines() const
The number of lines in the text, 0 if it's empty.
Definition SDL3pp_ttf.h:3277
void Update()
Update the layout of a text object.
Definition SDL3pp_ttf.h:3266
Point GetPosition() const
Get the position of a text object.
Definition SDL3pp_ttf.h:2802
void DrawSurface(Point p, SurfaceRef surface) const
Draw text to an SDL surface.
Definition SDL3pp_ttf.h:2372
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:3272
void SetEngine(TextEngineBase &engine)
Set the text engine used by a text object.
Definition SDL3pp_ttf.h:2486
void DeleteString(int offset, int length=-1)
Delete UTF-8 text from a text object.
Definition SDL3pp_ttf.h:3010
void GetSubStringForPoint(Point p, SubString *substring) const
Get the portion of a text string that is closest to a point.
Definition SDL3pp_ttf.h:3206
FColor GetColor() const
Get the color of a text object.
Definition SDL3pp_ttf.h:2672
SubStringIterator begin() const
Get iterator to first substring.
Definition SDL3pp_ttf.h:3642
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:3166
TextBase(TextEngineBase &engine, FontRef font, std::string_view text)
Create a text object from UTF-8 text and a text engine.
Definition SDL3pp_ttf.h:2449
int GetWrapWidth() const
Get whether wrapping is enabled on a text object.
Definition SDL3pp_ttf.h:2866
void GetColor(FColor *c) const
Get the color of a text object.
Definition SDL3pp_ttf.h:2713
void SetScript(Uint32 script)
Set the script to be used for text shaping a text object.
Definition SDL3pp_ttf.h:2595
void GetPreviousSubString(const SubString &substring, SubString *previous) const
Get the previous substring in a text object.
Definition SDL3pp_ttf.h:3226
SubStringIterator GetSubStringForLine(int line) const
Get iterator to substring of a text object that contains the given line.
Definition SDL3pp_ttf.h:3656
void GetNextSubString(const SubString &substring, SubString *next) const
Get the next substring in a text object.
Definition SDL3pp_ttf.h:3247
GPUAtlasDrawSequence * GetGPUDrawData() const
Get the geometry data needed for drawing the text.
Definition SDL3pp_ttf.h:2427
void AppendString(std::string_view string)
Append UTF-8 text to a text object.
Definition SDL3pp_ttf.h:2983
void GetSubString(int offset, SubString *substring) const
Get the substring of a text object that surrounds a text offset.
Definition SDL3pp_ttf.h:3081
SubStringIterator GetSubStringForPoint(Point p) const
Get the portion of a text string that is closest to a point.
Definition SDL3pp_ttf.h:3663
Direction GetDirection() const
Get the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:2577
TextEngineRef GetEngine() const
Get the text engine used by a text object.
Definition SDL3pp_ttf.h:2504
bool SetPosition(Point p)
Set the position of a text object.
Definition SDL3pp_ttf.h:2786
void InsertString(int offset, std::string_view string)
Insert UTF-8 text into a text object.
Definition SDL3pp_ttf.h:2960
bool GetPosition(int *x, int *y) const
Get the position of a text object.
Definition SDL3pp_ttf.h:2826
void GetColor(Color *c) const
Get the color of a text object.
Definition SDL3pp_ttf.h:2693
void GetSubStringForLine(int line, SubString *substring) const
Get the substring of a text object that contains the given line.
Definition SDL3pp_ttf.h:3131
Point GetSize() const
Get the size of a text object.
Definition SDL3pp_ttf.h:3031
bool SetFont(FontBase &font)
Set the font used by a text object.
Definition SDL3pp_ttf.h:2529
PropertiesRef GetProperties() const
Get the properties associated with a text object.
Definition SDL3pp_ttf.h:2466
void GetColor(float *r, float *g, float *b, float *a) const
Get the color of a text object.
Definition SDL3pp_ttf.h:2764
void SetDirection(Direction direction)
Set the direction to be used for text shaping a text object.
Definition SDL3pp_ttf.h:2560
void SetColor(Color c)
Set the color of a text object.
Definition SDL3pp_ttf.h:2635
Uint32 GetScript() const
Get the script used for text shaping a text object.
Definition SDL3pp_ttf.h:2617
void SetString(std::string_view string)
Set the UTF-8 text used by a text object.
Definition SDL3pp_ttf.h:2934
SubStringIterator end() const
Get iterator to one past last substring.
Definition SDL3pp_ttf.h:3649
void SetWrapWhitespaceVisible(bool visible)
Set whether whitespace should be visible when wrapping a text object.
Definition SDL3pp_ttf.h:2894
void SetColor(FColor c)
Set the color of a text object.
Definition SDL3pp_ttf.h:2656
void DrawRenderer(FPoint p) const
Draw text to an SDL renderer.
Definition SDL3pp_ttf.h:2396
A text engine used to create text objects.
Definition SDL3pp_ttf.h:2030
void SetGPUWinding(GPUTextEngineWinding winding)
Sets the winding order of the vertices returned by TextBase.GetGPUDrawData for a particular GPU text ...
Definition SDL3pp_ttf.h:2059
void(* m_destroy)(TTF_TextEngine *engine)
Custom destroyer.
Definition SDL3pp_ttf.h:2035
constexpr TextEngineBase(TTF_TextEngine *engine, void(*destroy)(TTF_TextEngine *engine))
Create from engine and custom destroyer.
Definition SDL3pp_ttf.h:2039
GPUTextEngineWinding GetGPUWinding() const
Get the winding order of the vertices returned by TextBase.GetGPUDrawData for a particular GPU text e...
Definition SDL3pp_ttf.h:2078
Handle to a non owned textEngine.
Definition SDL3pp_ttf.h:2093
constexpr TextEngineRef(TextEngineRef &&other)
Move constructor.
Definition SDL3pp_ttf.h:2107
constexpr ~TextEngineRef()=default
Default constructor.
void reset(TTF_TextEngine *newResource={})
frees up TextEngineBase.
Definition SDL3pp_ttf.h:2131
TextEngineRef & operator=(TextEngineRef other)
Assignment operator.
Definition SDL3pp_ttf.h:2120
constexpr TextEngineRef(const TextEngineRef &other)
Copy constructor.
Definition SDL3pp_ttf.h:2099
Handle to an owned textEngine.
Definition SDL3pp_ttf.h:2148
~TextEngine()
Frees up resource when object goes out of scope.
Definition SDL3pp_ttf.h:2169
TextEngine & operator=(TextEngine other)
Assignment operator.
Definition SDL3pp_ttf.h:2174
constexpr TextEngine(TTF_TextEngine *resource={})
Constructs from the underlying resource.
Definition SDL3pp_ttf.h:2154
constexpr TextEngine(TextEngine &&other)=default
Move constructor.
Handle to a non owned text.
Definition SDL3pp_ttf.h:3289
TextRef & operator=(TextRef other)
Assignment operator.
Definition SDL3pp_ttf.h:3316
constexpr ~TextRef()=default
Default constructor.
void reset(TTF_Text *newResource={})
Destroy a text object created by a text engine.
Definition SDL3pp_ttf.h:3332
constexpr TextRef(TextRef &&other)
Move constructor.
Definition SDL3pp_ttf.h:3303
constexpr TextRef(const TextRef &other)
Copy constructor.
Definition SDL3pp_ttf.h:3295
Handle to an owned text.
Definition SDL3pp_ttf.h:3347
Text & operator=(Text other)
Assignment operator.
Definition SDL3pp_ttf.h:3373
constexpr Text(Text &&other)=default
Move constructor.
~Text()
Frees up resource when object goes out of scope.
Definition SDL3pp_ttf.h:3368
constexpr Text(TTF_Text *resource={})
Constructs from the underlying resource.
Definition SDL3pp_ttf.h:3353
Flag to init TTF.
Definition SDL3pp_ttf.h:39