sdl3_ttf_sys/generated/ttf.rs
1//! Header file for SDL_ttf library
2//!
3//! This library is a wrapper around the excellent FreeType 2.0 library,
4//! available at: <https://www.freetype.org/>
5
6use sdl3_sys::everything::*;
7
8/// * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
9pub const SDL_TTF_MAJOR_VERSION: ::core::primitive::i32 = 3;
10
11pub const SDL_TTF_MINOR_VERSION: ::core::primitive::i32 = 2;
12
13pub const SDL_TTF_MICRO_VERSION: ::core::primitive::i32 = 0;
14
15/// * This is the version number macro for the current SDL_ttf version.
16pub const SDL_TTF_VERSION: ::core::primitive::i32 = SDL_VERSIONNUM(
17 SDL_TTF_MAJOR_VERSION,
18 SDL_TTF_MINOR_VERSION,
19 SDL_TTF_MICRO_VERSION,
20);
21
22/// * This macro will evaluate to true if compiled with SDL_ttf at least X.Y.Z.
23#[inline(always)]
24pub const fn SDL_TTF_VERSION_ATLEAST(
25 X: ::core::primitive::i32,
26 Y: ::core::primitive::i32,
27 Z: ::core::primitive::i32,
28) -> ::core::primitive::bool {
29 (((SDL_TTF_MAJOR_VERSION >= X)
30 && ((SDL_TTF_MAJOR_VERSION > X) || (SDL_TTF_MINOR_VERSION >= Y)))
31 && (((SDL_TTF_MAJOR_VERSION > X) || (SDL_TTF_MINOR_VERSION > Y))
32 || (SDL_TTF_MICRO_VERSION >= Z)))
33}
34
35extern "C" {
36 /// This function gets the version of the dynamically linked SDL_ttf library.
37 ///
38 /// ### Return value
39 /// Returns SDL_ttf version.
40 ///
41 /// ### Thread safety
42 /// It is safe to call this function from any thread.
43 ///
44 /// ### Availability
45 /// This function is available since SDL_ttf 3.0.0.
46 pub fn TTF_Version() -> ::core::ffi::c_int;
47}
48
49extern "C" {
50 /// Query the version of the FreeType library in use.
51 ///
52 /// [`TTF_Init()`] should be called before calling this function.
53 ///
54 /// ### Parameters
55 /// - `major`: to be filled in with the major version number. Can be NULL.
56 /// - `minor`: to be filled in with the minor version number. Can be NULL.
57 /// - `patch`: to be filled in with the param version number. Can be NULL.
58 ///
59 /// ### Thread safety
60 /// It is safe to call this function from any thread.
61 ///
62 /// ### Availability
63 /// This function is available since SDL_ttf 3.0.0.
64 ///
65 /// ### See also
66 /// - [`TTF_Init`]
67 pub fn TTF_GetFreeTypeVersion(
68 major: *mut ::core::ffi::c_int,
69 minor: *mut ::core::ffi::c_int,
70 patch: *mut ::core::ffi::c_int,
71 );
72}
73
74extern "C" {
75 /// Query the version of the HarfBuzz library in use.
76 ///
77 /// If HarfBuzz is not available, the version reported is 0.0.0.
78 ///
79 /// ### Parameters
80 /// - `major`: to be filled in with the major version number. Can be NULL.
81 /// - `minor`: to be filled in with the minor version number. Can be NULL.
82 /// - `patch`: to be filled in with the param version number. Can be NULL.
83 ///
84 /// ### Thread safety
85 /// It is safe to call this function from any thread.
86 ///
87 /// ### Availability
88 /// This function is available since SDL_ttf 3.0.0.
89 pub fn TTF_GetHarfBuzzVersion(
90 major: *mut ::core::ffi::c_int,
91 minor: *mut ::core::ffi::c_int,
92 patch: *mut ::core::ffi::c_int,
93 );
94}
95
96extern "C" {
97 /// Initialize SDL_ttf.
98 ///
99 /// You must successfully call this function before it is safe to call any
100 /// other function in this library.
101 ///
102 /// It is safe to call this more than once, and each successful [`TTF_Init()`] call
103 /// should be paired with a matching [`TTF_Quit()`] call.
104 ///
105 /// ### Return value
106 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
107 /// information.
108 ///
109 /// ### Availability
110 /// This function is available since SDL_ttf 3.0.0.
111 ///
112 /// ### See also
113 /// - [`TTF_Quit`]
114 pub fn TTF_Init() -> ::core::primitive::bool;
115}
116
117extern "C" {
118 /// Create a font from a file, using a specified point size.
119 ///
120 /// Some .fon fonts will have several sizes embedded in the file, so the point
121 /// size becomes the index of choosing which size. If the value is too high,
122 /// the last indexed size will be the default.
123 ///
124 /// When done with the returned [`TTF_Font`], use [`TTF_CloseFont()`] to dispose of it.
125 ///
126 /// ### Parameters
127 /// - `file`: path to font file.
128 /// - `ptsize`: point size to use for the newly-opened font.
129 ///
130 /// ### Return value
131 /// Returns a valid [`TTF_Font`], or NULL on failure; call [`SDL_GetError()`] for more
132 /// information.
133 ///
134 /// ### Thread safety
135 /// It is safe to call this function from any thread.
136 ///
137 /// ### Availability
138 /// This function is available since SDL_ttf 3.0.0.
139 ///
140 /// ### See also
141 /// - [`TTF_CloseFont`]
142 pub fn TTF_OpenFont(
143 file: *const ::core::ffi::c_char,
144 ptsize: ::core::ffi::c_float,
145 ) -> *mut TTF_Font;
146}
147
148extern "C" {
149 /// Create a font from an [`SDL_IOStream`], using a specified point size.
150 ///
151 /// Some .fon fonts will have several sizes embedded in the file, so the point
152 /// size becomes the index of choosing which size. If the value is too high,
153 /// the last indexed size will be the default.
154 ///
155 /// If `closeio` is true, `src` will be automatically closed once the font is
156 /// closed. Otherwise you should close `src` yourself after closing the font.
157 ///
158 /// When done with the returned [`TTF_Font`], use [`TTF_CloseFont()`] to dispose of it.
159 ///
160 /// ### Parameters
161 /// - `src`: an [`SDL_IOStream`] to provide a font file's data.
162 /// - `closeio`: true to close `src` when the font is closed, false to leave
163 /// it open.
164 /// - `ptsize`: point size to use for the newly-opened font.
165 ///
166 /// ### Return value
167 /// Returns a valid [`TTF_Font`], or NULL on failure; call [`SDL_GetError()`] for more
168 /// information.
169 ///
170 /// ### Thread safety
171 /// It is safe to call this function from any thread.
172 ///
173 /// ### Availability
174 /// This function is available since SDL_ttf 3.0.0.
175 ///
176 /// ### See also
177 /// - [`TTF_CloseFont`]
178 pub fn TTF_OpenFontIO(
179 src: *mut SDL_IOStream,
180 closeio: ::core::primitive::bool,
181 ptsize: ::core::ffi::c_float,
182 ) -> *mut TTF_Font;
183}
184
185extern "C" {
186 /// Create a font with the specified properties.
187 ///
188 /// These are the supported properties:
189 ///
190 /// - [`TTF_PROP_FONT_CREATE_FILENAME_STRING`]\: the font file to open, if an
191 /// [`SDL_IOStream`] isn't being used. This is required if
192 /// [`TTF_PROP_FONT_CREATE_IOSTREAM_POINTER`] and
193 /// [`TTF_PROP_FONT_CREATE_EXISTING_FONT`] aren't set.
194 /// - [`TTF_PROP_FONT_CREATE_IOSTREAM_POINTER`]\: an [`SDL_IOStream`] containing the
195 /// font to be opened. This should not be closed until the font is closed.
196 /// This is required if [`TTF_PROP_FONT_CREATE_FILENAME_STRING`] and
197 /// [`TTF_PROP_FONT_CREATE_EXISTING_FONT`] aren't set.
198 /// - [`TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER`]\: the offset in the iostream
199 /// for the beginning of the font, defaults to 0.
200 /// - [`TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN`]\: true if closing the
201 /// font should also close the associated [`SDL_IOStream`].
202 /// - [`TTF_PROP_FONT_CREATE_SIZE_FLOAT`]\: the point size of the font. Some .fon
203 /// fonts will have several sizes embedded in the file, so the point size
204 /// becomes the index of choosing which size. If the value is too high, the
205 /// last indexed size will be the default.
206 /// - [`TTF_PROP_FONT_CREATE_FACE_NUMBER`]\: the face index of the font, if the
207 /// font contains multiple font faces.
208 /// - [`TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER`]\: the horizontal DPI to use
209 /// for font rendering, defaults to
210 /// [`TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER`] if set, or 72 otherwise.
211 /// - [`TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER`]\: the vertical DPI to use for
212 /// font rendering, defaults to [`TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER`]
213 /// if set, or 72 otherwise.
214 /// - [`TTF_PROP_FONT_CREATE_EXISTING_FONT`]\: an optional [`TTF_Font`] that, if set,
215 /// will be used as the font data source and the initial size and style of
216 /// the new font.
217 ///
218 /// ### Parameters
219 /// - `props`: the properties to use.
220 ///
221 /// ### Return value
222 /// Returns a valid [`TTF_Font`], or NULL on failure; call [`SDL_GetError()`] for more
223 /// information.
224 ///
225 /// ### Thread safety
226 /// It is safe to call this function from any thread.
227 ///
228 /// ### Availability
229 /// This function is available since SDL_ttf 3.0.0.
230 ///
231 /// ### See also
232 /// - [`TTF_CloseFont`]
233 pub fn TTF_OpenFontWithProperties(props: SDL_PropertiesID) -> *mut TTF_Font;
234}
235
236pub const TTF_PROP_FONT_CREATE_FILENAME_STRING: *const ::core::ffi::c_char =
237 c"SDL_ttf.font.create.filename".as_ptr();
238
239pub const TTF_PROP_FONT_CREATE_IOSTREAM_POINTER: *const ::core::ffi::c_char =
240 c"SDL_ttf.font.create.iostream".as_ptr();
241
242pub const TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER: *const ::core::ffi::c_char =
243 c"SDL_ttf.font.create.iostream.offset".as_ptr();
244
245pub const TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN: *const ::core::ffi::c_char =
246 c"SDL_ttf.font.create.iostream.autoclose".as_ptr();
247
248pub const TTF_PROP_FONT_CREATE_SIZE_FLOAT: *const ::core::ffi::c_char =
249 c"SDL_ttf.font.create.size".as_ptr();
250
251pub const TTF_PROP_FONT_CREATE_FACE_NUMBER: *const ::core::ffi::c_char =
252 c"SDL_ttf.font.create.face".as_ptr();
253
254pub const TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER: *const ::core::ffi::c_char =
255 c"SDL_ttf.font.create.hdpi".as_ptr();
256
257pub const TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER: *const ::core::ffi::c_char =
258 c"SDL_ttf.font.create.vdpi".as_ptr();
259
260pub const TTF_PROP_FONT_CREATE_EXISTING_FONT: *const ::core::ffi::c_char =
261 c"SDL_ttf.font.create.existing_font".as_ptr();
262
263extern "C" {
264 /// Create a copy of an existing font.
265 ///
266 /// The copy will be distinct from the original, but will share the font file
267 /// and have the same size and style as the original.
268 ///
269 /// When done with the returned [`TTF_Font`], use [`TTF_CloseFont()`] to dispose of it.
270 ///
271 /// ### Parameters
272 /// - `existing_font`: the font to copy.
273 ///
274 /// ### Return value
275 /// Returns a valid [`TTF_Font`], or NULL on failure; call [`SDL_GetError()`] for more
276 /// information.
277 ///
278 /// ### Thread safety
279 /// This function should be called on the thread that created the
280 /// original font.
281 ///
282 /// ### Availability
283 /// This function is available since SDL_ttf 3.0.0.
284 ///
285 /// ### See also
286 /// - [`TTF_CloseFont`]
287 pub fn TTF_CopyFont(existing_font: *mut TTF_Font) -> *mut TTF_Font;
288}
289
290extern "C" {
291 /// Get the properties associated with a font.
292 ///
293 /// The following read-write properties are provided by SDL:
294 ///
295 /// - [`TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`]\: The FT_Stroker_LineCap value
296 /// used when setting the font outline, defaults to
297 /// `FT_STROKER_LINECAP_ROUND`.
298 /// - [`TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`]\: The FT_Stroker_LineJoin value
299 /// used when setting the font outline, defaults to
300 /// `FT_STROKER_LINEJOIN_ROUND`.
301 /// - [`TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER`]\: The FT_Fixed miter limit used
302 /// when setting the font outline, defaults to 0.
303 ///
304 /// ### Parameters
305 /// - `font`: the font to query.
306 ///
307 /// ### Return value
308 /// Returns a valid property ID on success or 0 on failure; call
309 /// [`SDL_GetError()`] for more information.
310 ///
311 /// ### Thread safety
312 /// It is safe to call this function from any thread.
313 ///
314 /// ### Availability
315 /// This function is available since SDL_ttf 3.0.0.
316 pub fn TTF_GetFontProperties(font: *mut TTF_Font) -> SDL_PropertiesID;
317}
318
319pub const TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER: *const ::core::ffi::c_char =
320 c"SDL_ttf.font.outline.line_cap".as_ptr();
321
322pub const TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER: *const ::core::ffi::c_char =
323 c"SDL_ttf.font.outline.line_join".as_ptr();
324
325pub const TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER: *const ::core::ffi::c_char =
326 c"SDL_ttf.font.outline.miter_limit".as_ptr();
327
328extern "C" {
329 /// Get the font generation.
330 ///
331 /// The generation is incremented each time font properties change that require
332 /// rebuilding glyphs, such as style, size, etc.
333 ///
334 /// ### Parameters
335 /// - `font`: the font to query.
336 ///
337 /// ### Return value
338 /// Returns the font generation or 0 on failure; call [`SDL_GetError()`] for more
339 /// information.
340 ///
341 /// ### Thread safety
342 /// This function should be called on the thread that created the
343 /// font.
344 ///
345 /// ### Availability
346 /// This function is available since SDL_ttf 3.0.0.
347 pub fn TTF_GetFontGeneration(font: *mut TTF_Font) -> Uint32;
348}
349
350extern "C" {
351 /// Add a fallback font.
352 ///
353 /// Add a font that will be used for glyphs that are not in the current font.
354 /// The fallback font should have the same size and style as the current font.
355 ///
356 /// If there are multiple fallback fonts, they are used in the order added.
357 ///
358 /// This updates any [`TTF_Text`] objects using this font.
359 ///
360 /// ### Parameters
361 /// - `font`: the font to modify.
362 /// - `fallback`: the font to add as a fallback.
363 ///
364 /// ### Return value
365 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
366 /// information.
367 ///
368 /// ### Thread safety
369 /// This function should be called on the thread that created
370 /// both fonts.
371 ///
372 /// ### Availability
373 /// This function is available since SDL_ttf 3.0.0.
374 ///
375 /// ### See also
376 /// - [`TTF_ClearFallbackFonts`]
377 /// - [`TTF_RemoveFallbackFont`]
378 pub fn TTF_AddFallbackFont(
379 font: *mut TTF_Font,
380 fallback: *mut TTF_Font,
381 ) -> ::core::primitive::bool;
382}
383
384extern "C" {
385 /// Remove a fallback font.
386 ///
387 /// This updates any [`TTF_Text`] objects using this font.
388 ///
389 /// ### Parameters
390 /// - `font`: the font to modify.
391 /// - `fallback`: the font to remove as a fallback.
392 ///
393 /// ### Thread safety
394 /// This function should be called on the thread that created
395 /// both fonts.
396 ///
397 /// ### Availability
398 /// This function is available since SDL_ttf 3.0.0.
399 ///
400 /// ### See also
401 /// - [`TTF_AddFallbackFont`]
402 /// - [`TTF_ClearFallbackFonts`]
403 pub fn TTF_RemoveFallbackFont(font: *mut TTF_Font, fallback: *mut TTF_Font);
404}
405
406extern "C" {
407 /// Remove all fallback fonts.
408 ///
409 /// This updates any [`TTF_Text`] objects using this font.
410 ///
411 /// ### Parameters
412 /// - `font`: the font to modify.
413 ///
414 /// ### Thread safety
415 /// This function should be called on the thread that created the
416 /// font.
417 ///
418 /// ### Availability
419 /// This function is available since SDL_ttf 3.0.0.
420 ///
421 /// ### See also
422 /// - [`TTF_AddFallbackFont`]
423 /// - [`TTF_RemoveFallbackFont`]
424 pub fn TTF_ClearFallbackFonts(font: *mut TTF_Font);
425}
426
427extern "C" {
428 /// Set a font's size dynamically.
429 ///
430 /// This updates any [`TTF_Text`] objects using this font, and clears
431 /// already-generated glyphs, if any, from the cache.
432 ///
433 /// ### Parameters
434 /// - `font`: the font to resize.
435 /// - `ptsize`: the new point size.
436 ///
437 /// ### Return value
438 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
439 /// information.
440 ///
441 /// ### Thread safety
442 /// This function should be called on the thread that created the
443 /// font.
444 ///
445 /// ### Availability
446 /// This function is available since SDL_ttf 3.0.0.
447 ///
448 /// ### See also
449 /// - [`TTF_GetFontSize`]
450 pub fn TTF_SetFontSize(
451 font: *mut TTF_Font,
452 ptsize: ::core::ffi::c_float,
453 ) -> ::core::primitive::bool;
454}
455
456extern "C" {
457 /// Set font size dynamically with target resolutions, in dots per inch.
458 ///
459 /// This updates any [`TTF_Text`] objects using this font, and clears
460 /// already-generated glyphs, if any, from the cache.
461 ///
462 /// ### Parameters
463 /// - `font`: the font to resize.
464 /// - `ptsize`: the new point size.
465 /// - `hdpi`: the target horizontal DPI.
466 /// - `vdpi`: the target vertical DPI.
467 ///
468 /// ### Return value
469 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
470 /// information.
471 ///
472 /// ### Thread safety
473 /// This function should be called on the thread that created the
474 /// font.
475 ///
476 /// ### Availability
477 /// This function is available since SDL_ttf 3.0.0.
478 ///
479 /// ### See also
480 /// - [`TTF_GetFontSize`]
481 /// - [`TTF_GetFontSizeDPI`]
482 pub fn TTF_SetFontSizeDPI(
483 font: *mut TTF_Font,
484 ptsize: ::core::ffi::c_float,
485 hdpi: ::core::ffi::c_int,
486 vdpi: ::core::ffi::c_int,
487 ) -> ::core::primitive::bool;
488}
489
490extern "C" {
491 /// Get the size of a font.
492 ///
493 /// ### Parameters
494 /// - `font`: the font to query.
495 ///
496 /// ### Return value
497 /// Returns the size of the font, or 0.0f on failure; call [`SDL_GetError()`] for
498 /// more information.
499 ///
500 /// ### Thread safety
501 /// This function should be called on the thread that created the
502 /// font.
503 ///
504 /// ### Availability
505 /// This function is available since SDL_ttf 3.0.0.
506 ///
507 /// ### See also
508 /// - [`TTF_SetFontSize`]
509 /// - [`TTF_SetFontSizeDPI`]
510 pub fn TTF_GetFontSize(font: *mut TTF_Font) -> ::core::ffi::c_float;
511}
512
513extern "C" {
514 /// Get font target resolutions, in dots per inch.
515 ///
516 /// ### Parameters
517 /// - `font`: the font to query.
518 /// - `hdpi`: a pointer filled in with the target horizontal DPI.
519 /// - `vdpi`: a pointer filled in with the target vertical DPI.
520 ///
521 /// ### Return value
522 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
523 /// information.
524 ///
525 /// ### Thread safety
526 /// This function should be called on the thread that created the
527 /// font.
528 ///
529 /// ### Availability
530 /// This function is available since SDL_ttf 3.0.0.
531 ///
532 /// ### See also
533 /// - [`TTF_SetFontSizeDPI`]
534 pub fn TTF_GetFontDPI(
535 font: *mut TTF_Font,
536 hdpi: *mut ::core::ffi::c_int,
537 vdpi: *mut ::core::ffi::c_int,
538 ) -> ::core::primitive::bool;
539}
540
541/// Font style flags for [`TTF_Font`]
542///
543/// These are the flags which can be used to set the style of a font in
544/// SDL_ttf. A combination of these flags can be used with functions that set
545/// or query font style, such as [`TTF_SetFontStyle`] or [`TTF_GetFontStyle`].
546///
547/// ### Availability
548/// This function is available since SDL_ttf 3.0.0.
549///
550/// ### See also
551/// - [`TTF_SetFontStyle`]
552/// - [`TTF_GetFontStyle`]
553///
554/// ### Known values (`sdl3-sys`)
555/// | Constant | Description |
556/// | -------- | ----------- |
557/// | [`TTF_STYLE_NORMAL`] | No special style |
558/// | [`TTF_STYLE_BOLD`] | Bold style |
559/// | [`TTF_STYLE_ITALIC`] | Italic style |
560/// | [`TTF_STYLE_UNDERLINE`] | Underlined text |
561/// | [`TTF_STYLE_STRIKETHROUGH`] | Strikethrough text |
562pub type TTF_FontStyleFlags = Uint32;
563
564/// No special style
565pub const TTF_STYLE_NORMAL: TTF_FontStyleFlags = (0x00 as TTF_FontStyleFlags);
566
567/// Bold style
568pub const TTF_STYLE_BOLD: TTF_FontStyleFlags = (0x01 as TTF_FontStyleFlags);
569
570/// Italic style
571pub const TTF_STYLE_ITALIC: TTF_FontStyleFlags = (0x02 as TTF_FontStyleFlags);
572
573/// Underlined text
574pub const TTF_STYLE_UNDERLINE: TTF_FontStyleFlags = (0x04 as TTF_FontStyleFlags);
575
576/// Strikethrough text
577pub const TTF_STYLE_STRIKETHROUGH: TTF_FontStyleFlags = (0x08 as TTF_FontStyleFlags);
578
579extern "C" {
580 /// Set a font's current style.
581 ///
582 /// This updates any [`TTF_Text`] objects using this font, and clears
583 /// already-generated glyphs, if any, from the cache.
584 ///
585 /// The font styles are a set of bit flags, OR'd together:
586 ///
587 /// - [`TTF_STYLE_NORMAL`] (is zero)
588 /// - [`TTF_STYLE_BOLD`]
589 /// - [`TTF_STYLE_ITALIC`]
590 /// - [`TTF_STYLE_UNDERLINE`]
591 /// - [`TTF_STYLE_STRIKETHROUGH`]
592 ///
593 /// ### Parameters
594 /// - `font`: the font to set a new style on.
595 /// - `style`: the new style values to set, OR'd together.
596 ///
597 /// ### Thread safety
598 /// This function should be called on the thread that created the
599 /// font.
600 ///
601 /// ### Availability
602 /// This function is available since SDL_ttf 3.0.0.
603 ///
604 /// ### See also
605 /// - [`TTF_GetFontStyle`]
606 pub fn TTF_SetFontStyle(font: *mut TTF_Font, style: TTF_FontStyleFlags);
607}
608
609extern "C" {
610 /// Query a font's current style.
611 ///
612 /// The font styles are a set of bit flags, OR'd together:
613 ///
614 /// - [`TTF_STYLE_NORMAL`] (is zero)
615 /// - [`TTF_STYLE_BOLD`]
616 /// - [`TTF_STYLE_ITALIC`]
617 /// - [`TTF_STYLE_UNDERLINE`]
618 /// - [`TTF_STYLE_STRIKETHROUGH`]
619 ///
620 /// ### Parameters
621 /// - `font`: the font to query.
622 ///
623 /// ### Return value
624 /// Returns the current font style, as a set of bit flags.
625 ///
626 /// ### Thread safety
627 /// It is safe to call this function from any thread.
628 ///
629 /// ### Availability
630 /// This function is available since SDL_ttf 3.0.0.
631 ///
632 /// ### See also
633 /// - [`TTF_SetFontStyle`]
634 pub fn TTF_GetFontStyle(font: *const TTF_Font) -> TTF_FontStyleFlags;
635}
636
637extern "C" {
638 /// Set a font's current outline.
639 ///
640 /// This uses the font properties [`TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`],
641 /// [`TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`], and
642 /// [`TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER`] when setting the font outline.
643 ///
644 /// This updates any [`TTF_Text`] objects using this font, and clears
645 /// already-generated glyphs, if any, from the cache.
646 ///
647 /// ### Parameters
648 /// - `font`: the font to set a new outline on.
649 /// - `outline`: positive outline value, 0 to default.
650 ///
651 /// ### Return value
652 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
653 /// information.
654 ///
655 /// ### Thread safety
656 /// This function should be called on the thread that created the
657 /// font.
658 ///
659 /// ### Availability
660 /// This function is available since SDL_ttf 3.0.0.
661 ///
662 /// ### See also
663 /// - [`TTF_GetFontOutline`]
664 pub fn TTF_SetFontOutline(
665 font: *mut TTF_Font,
666 outline: ::core::ffi::c_int,
667 ) -> ::core::primitive::bool;
668}
669
670extern "C" {
671 /// Query a font's current outline.
672 ///
673 /// ### Parameters
674 /// - `font`: the font to query.
675 ///
676 /// ### Return value
677 /// Returns the font's current outline value.
678 ///
679 /// ### Thread safety
680 /// It is safe to call this function from any thread.
681 ///
682 /// ### Availability
683 /// This function is available since SDL_ttf 3.0.0.
684 ///
685 /// ### See also
686 /// - [`TTF_SetFontOutline`]
687 pub fn TTF_GetFontOutline(font: *const TTF_Font) -> ::core::ffi::c_int;
688}
689
690/// Hinting flags for TTF (TrueType Fonts)
691///
692/// This enum specifies the level of hinting to be applied to the font
693/// rendering. The hinting level determines how much the font's outlines are
694/// adjusted for better alignment on the pixel grid.
695///
696/// ### Availability
697/// This enum is available since SDL_ttf 3.0.0.
698///
699/// ### See also
700/// - [`TTF_SetFontHinting`]
701/// - [`TTF_GetFontHinting`]
702///
703/// ### Known values (`sdl3-sys`)
704/// | Associated constant | Global constant | Description |
705/// | ------------------- | --------------- | ----------- |
706/// | [`NORMAL`](TTF_HintingFlags::NORMAL) | [`TTF_HINTING_NORMAL`] | Normal hinting applies standard grid-fitting. |
707/// | [`LIGHT`](TTF_HintingFlags::LIGHT) | [`TTF_HINTING_LIGHT`] | Light hinting applies subtle adjustments to improve rendering. |
708/// | [`MONO`](TTF_HintingFlags::MONO) | [`TTF_HINTING_MONO`] | Monochrome hinting adjusts the font for better rendering at lower resolutions. |
709/// | [`NONE`](TTF_HintingFlags::NONE) | [`TTF_HINTING_NONE`] | No hinting, the font is rendered without any grid-fitting. |
710/// | [`LIGHT_SUBPIXEL`](TTF_HintingFlags::LIGHT_SUBPIXEL) | [`TTF_HINTING_LIGHT_SUBPIXEL`] | Light hinting with subpixel rendering for more precise font edges. |
711#[repr(transparent)]
712#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
713pub struct TTF_HintingFlags(pub ::core::ffi::c_int);
714
715impl From<TTF_HintingFlags> for ::core::ffi::c_int {
716 #[inline(always)]
717 fn from(value: TTF_HintingFlags) -> Self {
718 value.0
719 }
720}
721
722#[cfg(feature = "debug-impls")]
723impl ::core::fmt::Debug for TTF_HintingFlags {
724 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
725 #[allow(unreachable_patterns)]
726 f.write_str(match *self {
727 Self::NORMAL => "TTF_HINTING_NORMAL",
728 Self::LIGHT => "TTF_HINTING_LIGHT",
729 Self::MONO => "TTF_HINTING_MONO",
730 Self::NONE => "TTF_HINTING_NONE",
731 Self::LIGHT_SUBPIXEL => "TTF_HINTING_LIGHT_SUBPIXEL",
732
733 _ => return write!(f, "TTF_HintingFlags({})", self.0),
734 })
735 }
736}
737
738impl TTF_HintingFlags {
739 /// Normal hinting applies standard grid-fitting.
740 pub const NORMAL: Self = Self(0);
741 /// Light hinting applies subtle adjustments to improve rendering.
742 pub const LIGHT: Self = Self(1);
743 /// Monochrome hinting adjusts the font for better rendering at lower resolutions.
744 pub const MONO: Self = Self(2);
745 /// No hinting, the font is rendered without any grid-fitting.
746 pub const NONE: Self = Self(3);
747 /// Light hinting with subpixel rendering for more precise font edges.
748 pub const LIGHT_SUBPIXEL: Self = Self(4);
749}
750
751/// Normal hinting applies standard grid-fitting.
752pub const TTF_HINTING_NORMAL: TTF_HintingFlags = TTF_HintingFlags::NORMAL;
753/// Light hinting applies subtle adjustments to improve rendering.
754pub const TTF_HINTING_LIGHT: TTF_HintingFlags = TTF_HintingFlags::LIGHT;
755/// Monochrome hinting adjusts the font for better rendering at lower resolutions.
756pub const TTF_HINTING_MONO: TTF_HintingFlags = TTF_HintingFlags::MONO;
757/// No hinting, the font is rendered without any grid-fitting.
758pub const TTF_HINTING_NONE: TTF_HintingFlags = TTF_HintingFlags::NONE;
759/// Light hinting with subpixel rendering for more precise font edges.
760pub const TTF_HINTING_LIGHT_SUBPIXEL: TTF_HintingFlags = TTF_HintingFlags::LIGHT_SUBPIXEL;
761
762extern "C" {
763 /// Set a font's current hinter setting.
764 ///
765 /// This updates any [`TTF_Text`] objects using this font, and clears
766 /// already-generated glyphs, if any, from the cache.
767 ///
768 /// The hinter setting is a single value:
769 ///
770 /// - [`TTF_HINTING_NORMAL`]
771 /// - [`TTF_HINTING_LIGHT`]
772 /// - [`TTF_HINTING_MONO`]
773 /// - [`TTF_HINTING_NONE`]
774 /// - [`TTF_HINTING_LIGHT_SUBPIXEL`] (available in SDL_ttf 3.0.0 and later)
775 ///
776 /// ### Parameters
777 /// - `font`: the font to set a new hinter setting on.
778 /// - `hinting`: the new hinter setting.
779 ///
780 /// ### Thread safety
781 /// This function should be called on the thread that created the
782 /// font.
783 ///
784 /// ### Availability
785 /// This function is available since SDL_ttf 3.0.0.
786 ///
787 /// ### See also
788 /// - [`TTF_GetFontHinting`]
789 pub fn TTF_SetFontHinting(font: *mut TTF_Font, hinting: TTF_HintingFlags);
790}
791
792extern "C" {
793 /// Query the number of faces of a font.
794 ///
795 /// ### Parameters
796 /// - `font`: the font to query.
797 ///
798 /// ### Return value
799 /// Returns the number of FreeType font faces.
800 ///
801 /// ### Thread safety
802 /// It is safe to call this function from any thread.
803 ///
804 /// ### Availability
805 /// This function is available since SDL_ttf 3.0.0.
806 pub fn TTF_GetNumFontFaces(font: *const TTF_Font) -> ::core::ffi::c_int;
807}
808
809extern "C" {
810 /// Query a font's current FreeType hinter setting.
811 ///
812 /// The hinter setting is a single value:
813 ///
814 /// - [`TTF_HINTING_NORMAL`]
815 /// - [`TTF_HINTING_LIGHT`]
816 /// - [`TTF_HINTING_MONO`]
817 /// - [`TTF_HINTING_NONE`]
818 /// - [`TTF_HINTING_LIGHT_SUBPIXEL`] (available in SDL_ttf 3.0.0 and later)
819 ///
820 /// ### Parameters
821 /// - `font`: the font to query.
822 ///
823 /// ### Return value
824 /// Returns the font's current hinter value.
825 ///
826 /// ### Thread safety
827 /// It is safe to call this function from any thread.
828 ///
829 /// ### Availability
830 /// This function is available since SDL_ttf 3.0.0.
831 ///
832 /// ### See also
833 /// - [`TTF_SetFontHinting`]
834 pub fn TTF_GetFontHinting(font: *const TTF_Font) -> TTF_HintingFlags;
835}
836
837extern "C" {
838 /// Enable Signed Distance Field rendering for a font.
839 ///
840 /// SDF is a technique that helps fonts look sharp even when scaling and
841 /// rotating, and requires special shader support for display.
842 ///
843 /// This works with Blended APIs, and generates the raw signed distance values
844 /// in the alpha channel of the resulting texture.
845 ///
846 /// This updates any [`TTF_Text`] objects using this font, and clears
847 /// already-generated glyphs, if any, from the cache.
848 ///
849 /// ### Parameters
850 /// - `font`: the font to set SDF support on.
851 /// - `enabled`: true to enable SDF, false to disable.
852 ///
853 /// ### Return value
854 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
855 /// information.
856 ///
857 /// ### Thread safety
858 /// This function should be called on the thread that created the
859 /// font.
860 ///
861 /// ### Availability
862 /// This function is available since SDL_ttf 3.0.0.
863 ///
864 /// ### See also
865 /// - [`TTF_GetFontSDF`]
866 pub fn TTF_SetFontSDF(
867 font: *mut TTF_Font,
868 enabled: ::core::primitive::bool,
869 ) -> ::core::primitive::bool;
870}
871
872extern "C" {
873 /// Query whether Signed Distance Field rendering is enabled for a font.
874 ///
875 /// ### Parameters
876 /// - `font`: the font to query.
877 ///
878 /// ### Return value
879 /// Returns true if enabled, false otherwise.
880 ///
881 /// ### Thread safety
882 /// It is safe to call this function from any thread.
883 ///
884 /// ### Availability
885 /// This function is available since SDL_ttf 3.0.0.
886 ///
887 /// ### See also
888 /// - [`TTF_SetFontSDF`]
889 pub fn TTF_GetFontSDF(font: *const TTF_Font) -> ::core::primitive::bool;
890}
891
892/// The horizontal alignment used when rendering wrapped text.
893///
894/// ### Availability
895/// This enum is available since SDL_ttf 3.0.0.
896///
897/// ### Known values (`sdl3-sys`)
898/// | Associated constant | Global constant | Description |
899/// | ------------------- | --------------- | ----------- |
900/// | [`INVALID`](TTF_HorizontalAlignment::INVALID) | [`TTF_HORIZONTAL_ALIGN_INVALID`] | |
901/// | [`LEFT`](TTF_HorizontalAlignment::LEFT) | [`TTF_HORIZONTAL_ALIGN_LEFT`] | |
902/// | [`CENTER`](TTF_HorizontalAlignment::CENTER) | [`TTF_HORIZONTAL_ALIGN_CENTER`] | |
903/// | [`RIGHT`](TTF_HorizontalAlignment::RIGHT) | [`TTF_HORIZONTAL_ALIGN_RIGHT`] | |
904#[repr(transparent)]
905#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
906pub struct TTF_HorizontalAlignment(pub ::core::ffi::c_int);
907
908impl From<TTF_HorizontalAlignment> for ::core::ffi::c_int {
909 #[inline(always)]
910 fn from(value: TTF_HorizontalAlignment) -> Self {
911 value.0
912 }
913}
914
915#[cfg(feature = "debug-impls")]
916impl ::core::fmt::Debug for TTF_HorizontalAlignment {
917 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
918 #[allow(unreachable_patterns)]
919 f.write_str(match *self {
920 Self::INVALID => "TTF_HORIZONTAL_ALIGN_INVALID",
921 Self::LEFT => "TTF_HORIZONTAL_ALIGN_LEFT",
922 Self::CENTER => "TTF_HORIZONTAL_ALIGN_CENTER",
923 Self::RIGHT => "TTF_HORIZONTAL_ALIGN_RIGHT",
924
925 _ => return write!(f, "TTF_HorizontalAlignment({})", self.0),
926 })
927 }
928}
929
930impl TTF_HorizontalAlignment {
931 pub const INVALID: Self = Self(-1_i32);
932 pub const LEFT: Self = Self(0_i32);
933 pub const CENTER: Self = Self(1_i32);
934 pub const RIGHT: Self = Self(2_i32);
935}
936
937pub const TTF_HORIZONTAL_ALIGN_INVALID: TTF_HorizontalAlignment = TTF_HorizontalAlignment::INVALID;
938pub const TTF_HORIZONTAL_ALIGN_LEFT: TTF_HorizontalAlignment = TTF_HorizontalAlignment::LEFT;
939pub const TTF_HORIZONTAL_ALIGN_CENTER: TTF_HorizontalAlignment = TTF_HorizontalAlignment::CENTER;
940pub const TTF_HORIZONTAL_ALIGN_RIGHT: TTF_HorizontalAlignment = TTF_HorizontalAlignment::RIGHT;
941
942extern "C" {
943 /// Set a font's current wrap alignment option.
944 ///
945 /// This updates any [`TTF_Text`] objects using this font.
946 ///
947 /// ### Parameters
948 /// - `font`: the font to set a new wrap alignment option on.
949 /// - `align`: the new wrap alignment option.
950 ///
951 /// ### Thread safety
952 /// This function should be called on the thread that created the
953 /// font.
954 ///
955 /// ### Availability
956 /// This function is available since SDL_ttf 3.0.0.
957 ///
958 /// ### See also
959 /// - [`TTF_GetFontWrapAlignment`]
960 pub fn TTF_SetFontWrapAlignment(font: *mut TTF_Font, align: TTF_HorizontalAlignment);
961}
962
963extern "C" {
964 /// Query a font's current wrap alignment option.
965 ///
966 /// ### Parameters
967 /// - `font`: the font to query.
968 ///
969 /// ### Return value
970 /// Returns the font's current wrap alignment option.
971 ///
972 /// ### Thread safety
973 /// It is safe to call this function from any thread.
974 ///
975 /// ### Availability
976 /// This function is available since SDL_ttf 3.0.0.
977 ///
978 /// ### See also
979 /// - [`TTF_SetFontWrapAlignment`]
980 pub fn TTF_GetFontWrapAlignment(font: *const TTF_Font) -> TTF_HorizontalAlignment;
981}
982
983extern "C" {
984 /// Query the total height of a font.
985 ///
986 /// This is usually equal to point size.
987 ///
988 /// ### Parameters
989 /// - `font`: the font to query.
990 ///
991 /// ### Return value
992 /// Returns the font's height.
993 ///
994 /// ### Thread safety
995 /// It is safe to call this function from any thread.
996 ///
997 /// ### Availability
998 /// This function is available since SDL_ttf 3.0.0.
999 pub fn TTF_GetFontHeight(font: *const TTF_Font) -> ::core::ffi::c_int;
1000}
1001
1002extern "C" {
1003 /// Query the offset from the baseline to the top of a font.
1004 ///
1005 /// This is a positive value, relative to the baseline.
1006 ///
1007 /// ### Parameters
1008 /// - `font`: the font to query.
1009 ///
1010 /// ### Return value
1011 /// Returns the font's ascent.
1012 ///
1013 /// ### Thread safety
1014 /// It is safe to call this function from any thread.
1015 ///
1016 /// ### Availability
1017 /// This function is available since SDL_ttf 3.0.0.
1018 pub fn TTF_GetFontAscent(font: *const TTF_Font) -> ::core::ffi::c_int;
1019}
1020
1021extern "C" {
1022 /// Query the offset from the baseline to the bottom of a font.
1023 ///
1024 /// This is a negative value, relative to the baseline.
1025 ///
1026 /// ### Parameters
1027 /// - `font`: the font to query.
1028 ///
1029 /// ### Return value
1030 /// Returns the font's descent.
1031 ///
1032 /// ### Thread safety
1033 /// It is safe to call this function from any thread.
1034 ///
1035 /// ### Availability
1036 /// This function is available since SDL_ttf 3.0.0.
1037 pub fn TTF_GetFontDescent(font: *const TTF_Font) -> ::core::ffi::c_int;
1038}
1039
1040extern "C" {
1041 /// Set the spacing between lines of text for a font.
1042 ///
1043 /// This updates any [`TTF_Text`] objects using this font.
1044 ///
1045 /// ### Parameters
1046 /// - `font`: the font to modify.
1047 /// - `lineskip`: the new line spacing for the font.
1048 ///
1049 /// ### Thread safety
1050 /// This function should be called on the thread that created the
1051 /// font.
1052 ///
1053 /// ### Availability
1054 /// This function is available since SDL_ttf 3.0.0.
1055 ///
1056 /// ### See also
1057 /// - [`TTF_GetFontLineSkip`]
1058 pub fn TTF_SetFontLineSkip(font: *mut TTF_Font, lineskip: ::core::ffi::c_int);
1059}
1060
1061extern "C" {
1062 /// Query the spacing between lines of text for a font.
1063 ///
1064 /// ### Parameters
1065 /// - `font`: the font to query.
1066 ///
1067 /// ### Return value
1068 /// Returns the font's recommended spacing.
1069 ///
1070 /// ### Thread safety
1071 /// It is safe to call this function from any thread.
1072 ///
1073 /// ### Availability
1074 /// This function is available since SDL_ttf 3.0.0.
1075 ///
1076 /// ### See also
1077 /// - [`TTF_SetFontLineSkip`]
1078 pub fn TTF_GetFontLineSkip(font: *const TTF_Font) -> ::core::ffi::c_int;
1079}
1080
1081extern "C" {
1082 /// Set if kerning is enabled for a font.
1083 ///
1084 /// Newly-opened fonts default to allowing kerning. This is generally a good
1085 /// policy unless you have a strong reason to disable it, as it tends to
1086 /// produce better rendering (with kerning disabled, some fonts might render
1087 /// the word `kerning` as something that looks like `keming` for example).
1088 ///
1089 /// This updates any [`TTF_Text`] objects using this font.
1090 ///
1091 /// ### Parameters
1092 /// - `font`: the font to set kerning on.
1093 /// - `enabled`: true to enable kerning, false to disable.
1094 ///
1095 /// ### Thread safety
1096 /// This function should be called on the thread that created the
1097 /// font.
1098 ///
1099 /// ### Availability
1100 /// This function is available since SDL_ttf 3.0.0.
1101 ///
1102 /// ### See also
1103 /// - [`TTF_GetFontKerning`]
1104 pub fn TTF_SetFontKerning(font: *mut TTF_Font, enabled: ::core::primitive::bool);
1105}
1106
1107extern "C" {
1108 /// Query whether or not kerning is enabled for a font.
1109 ///
1110 /// ### Parameters
1111 /// - `font`: the font to query.
1112 ///
1113 /// ### Return value
1114 /// Returns true if kerning is enabled, false otherwise.
1115 ///
1116 /// ### Thread safety
1117 /// It is safe to call this function from any thread.
1118 ///
1119 /// ### Availability
1120 /// This function is available since SDL_ttf 3.0.0.
1121 ///
1122 /// ### See also
1123 /// - [`TTF_SetFontKerning`]
1124 pub fn TTF_GetFontKerning(font: *const TTF_Font) -> ::core::primitive::bool;
1125}
1126
1127extern "C" {
1128 /// Query whether a font is fixed-width.
1129 ///
1130 /// A "fixed-width" font means all glyphs are the same width across; a
1131 /// lowercase 'i' will be the same size across as a capital 'W', for example.
1132 /// This is common for terminals and text editors, and other apps that treat
1133 /// text as a grid. Most other things (WYSIWYG word processors, web pages, etc)
1134 /// are more likely to not be fixed-width in most cases.
1135 ///
1136 /// ### Parameters
1137 /// - `font`: the font to query.
1138 ///
1139 /// ### Return value
1140 /// Returns true if the font is fixed-width, false otherwise.
1141 ///
1142 /// ### Thread safety
1143 /// It is safe to call this function from any thread.
1144 ///
1145 /// ### Availability
1146 /// This function is available since SDL_ttf 3.0.0.
1147 pub fn TTF_FontIsFixedWidth(font: *const TTF_Font) -> ::core::primitive::bool;
1148}
1149
1150extern "C" {
1151 /// Query whether a font is scalable or not.
1152 ///
1153 /// Scalability lets us distinguish between outline and bitmap fonts.
1154 ///
1155 /// ### Parameters
1156 /// - `font`: the font to query.
1157 ///
1158 /// ### Return value
1159 /// Returns true if the font is scalable, false otherwise.
1160 ///
1161 /// ### Thread safety
1162 /// It is safe to call this function from any thread.
1163 ///
1164 /// ### Availability
1165 /// This function is available since SDL_ttf 3.0.0.
1166 ///
1167 /// ### See also
1168 /// - [`TTF_SetFontSDF`]
1169 pub fn TTF_FontIsScalable(font: *const TTF_Font) -> ::core::primitive::bool;
1170}
1171
1172extern "C" {
1173 /// Query a font's family name.
1174 ///
1175 /// This string is dictated by the contents of the font file.
1176 ///
1177 /// Note that the returned string is to internal storage, and should not be
1178 /// modified or free'd by the caller. The string becomes invalid, with the rest
1179 /// of the font, when `font` is handed to [`TTF_CloseFont()`].
1180 ///
1181 /// ### Parameters
1182 /// - `font`: the font to query.
1183 ///
1184 /// ### Return value
1185 /// Returns the font's family name.
1186 ///
1187 /// ### Thread safety
1188 /// It is safe to call this function from any thread.
1189 ///
1190 /// ### Availability
1191 /// This function is available since SDL_ttf 3.0.0.
1192 pub fn TTF_GetFontFamilyName(font: *const TTF_Font) -> *const ::core::ffi::c_char;
1193}
1194
1195extern "C" {
1196 /// Query a font's style name.
1197 ///
1198 /// This string is dictated by the contents of the font file.
1199 ///
1200 /// Note that the returned string is to internal storage, and should not be
1201 /// modified or free'd by the caller. The string becomes invalid, with the rest
1202 /// of the font, when `font` is handed to [`TTF_CloseFont()`].
1203 ///
1204 /// ### Parameters
1205 /// - `font`: the font to query.
1206 ///
1207 /// ### Return value
1208 /// Returns the font's style name.
1209 ///
1210 /// ### Thread safety
1211 /// It is safe to call this function from any thread.
1212 ///
1213 /// ### Availability
1214 /// This function is available since SDL_ttf 3.0.0.
1215 pub fn TTF_GetFontStyleName(font: *const TTF_Font) -> *const ::core::ffi::c_char;
1216}
1217
1218/// Direction flags
1219///
1220/// The values here are chosen to match
1221/// [hb_direction_t](https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-direction-t)
1222/// .
1223///
1224/// ### Availability
1225/// This enum is available since SDL_ttf 3.0.0.
1226///
1227/// ### See also
1228/// - [`TTF_SetFontDirection`]
1229///
1230/// ### Known values (`sdl3-sys`)
1231/// | Associated constant | Global constant | Description |
1232/// | ------------------- | --------------- | ----------- |
1233/// | [`INVALID`](TTF_Direction::INVALID) | [`TTF_DIRECTION_INVALID`] | |
1234/// | [`LTR`](TTF_Direction::LTR) | [`TTF_DIRECTION_LTR`] | Left to Right |
1235/// | [`RTL`](TTF_Direction::RTL) | [`TTF_DIRECTION_RTL`] | Right to Left |
1236/// | [`TTB`](TTF_Direction::TTB) | [`TTF_DIRECTION_TTB`] | Top to Bottom |
1237/// | [`BTT`](TTF_Direction::BTT) | [`TTF_DIRECTION_BTT`] | Bottom to Top |
1238#[repr(transparent)]
1239#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
1240pub struct TTF_Direction(pub ::core::primitive::u32);
1241
1242impl From<TTF_Direction> for ::core::primitive::u32 {
1243 #[inline(always)]
1244 fn from(value: TTF_Direction) -> Self {
1245 value.0
1246 }
1247}
1248
1249#[cfg(feature = "debug-impls")]
1250impl ::core::fmt::Debug for TTF_Direction {
1251 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1252 #[allow(unreachable_patterns)]
1253 f.write_str(match *self {
1254 Self::INVALID => "TTF_DIRECTION_INVALID",
1255 Self::LTR => "TTF_DIRECTION_LTR",
1256 Self::RTL => "TTF_DIRECTION_RTL",
1257 Self::TTB => "TTF_DIRECTION_TTB",
1258 Self::BTT => "TTF_DIRECTION_BTT",
1259
1260 _ => return write!(f, "TTF_Direction({})", self.0),
1261 })
1262 }
1263}
1264
1265impl TTF_Direction {
1266 pub const INVALID: Self = Self(0);
1267 /// Left to Right
1268 pub const LTR: Self = Self(4);
1269 /// Right to Left
1270 pub const RTL: Self = Self(5);
1271 /// Top to Bottom
1272 pub const TTB: Self = Self(6);
1273 /// Bottom to Top
1274 pub const BTT: Self = Self(7);
1275}
1276
1277pub const TTF_DIRECTION_INVALID: TTF_Direction = TTF_Direction::INVALID;
1278/// Left to Right
1279pub const TTF_DIRECTION_LTR: TTF_Direction = TTF_Direction::LTR;
1280/// Right to Left
1281pub const TTF_DIRECTION_RTL: TTF_Direction = TTF_Direction::RTL;
1282/// Top to Bottom
1283pub const TTF_DIRECTION_TTB: TTF_Direction = TTF_Direction::TTB;
1284/// Bottom to Top
1285pub const TTF_DIRECTION_BTT: TTF_Direction = TTF_Direction::BTT;
1286
1287extern "C" {
1288 /// Set the direction to be used for text shaping by a font.
1289 ///
1290 /// This function only supports left-to-right text shaping if SDL_ttf was not
1291 /// built with HarfBuzz support.
1292 ///
1293 /// This updates any [`TTF_Text`] objects using this font.
1294 ///
1295 /// ### Parameters
1296 /// - `font`: the font to modify.
1297 /// - `direction`: the new direction for text to flow.
1298 ///
1299 /// ### Return value
1300 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1301 /// information.
1302 ///
1303 /// ### Thread safety
1304 /// This function should be called on the thread that created the
1305 /// font.
1306 ///
1307 /// ### Availability
1308 /// This function is available since SDL_ttf 3.0.0.
1309 pub fn TTF_SetFontDirection(
1310 font: *mut TTF_Font,
1311 direction: TTF_Direction,
1312 ) -> ::core::primitive::bool;
1313}
1314
1315extern "C" {
1316 /// Get the direction to be used for text shaping by a font.
1317 ///
1318 /// This defaults to [`TTF_DIRECTION_INVALID`] if it hasn't been set.
1319 ///
1320 /// ### Parameters
1321 /// - `font`: the font to query.
1322 ///
1323 /// ### Return value
1324 /// Returns the direction to be used for text shaping.
1325 ///
1326 /// ### Thread safety
1327 /// This function should be called on the thread that created the
1328 /// font.
1329 ///
1330 /// ### Availability
1331 /// This function is available since SDL_ttf 3.0.0.
1332 pub fn TTF_GetFontDirection(font: *mut TTF_Font) -> TTF_Direction;
1333}
1334
1335extern "C" {
1336 /// Convert from a 4 character string to a 32-bit tag.
1337 ///
1338 /// ### Parameters
1339 /// - `string`: the 4 character string to convert.
1340 ///
1341 /// ### Return value
1342 /// Returns the 32-bit representation of the string.
1343 ///
1344 /// ### Thread safety
1345 /// It is safe to call this function from any thread.
1346 ///
1347 /// ### Availability
1348 /// This function is available since SDL_ttf 3.0.0.
1349 ///
1350 /// ### See also
1351 /// - [`TTF_TagToString`]
1352 pub fn TTF_StringToTag(string: *const ::core::ffi::c_char) -> Uint32;
1353}
1354
1355extern "C" {
1356 /// Convert from a 32-bit tag to a 4 character string.
1357 ///
1358 /// ### Parameters
1359 /// - `tag`: the 32-bit tag to convert.
1360 /// - `string`: a pointer filled in with the 4 character representation of
1361 /// the tag.
1362 /// - `size`: the size of the buffer pointed at by string, should be at least
1363 /// 4.
1364 ///
1365 /// ### Thread safety
1366 /// It is safe to call this function from any thread.
1367 ///
1368 /// ### Availability
1369 /// This function is available since SDL_ttf 3.0.0.
1370 ///
1371 /// ### See also
1372 /// - [`TTF_TagToString`]
1373 pub fn TTF_TagToString(
1374 tag: Uint32,
1375 string: *mut ::core::ffi::c_char,
1376 size: ::core::primitive::usize,
1377 );
1378}
1379
1380extern "C" {
1381 /// Set the script to be used for text shaping by a font.
1382 ///
1383 /// This returns false if SDL_ttf isn't built with HarfBuzz support.
1384 ///
1385 /// This updates any [`TTF_Text`] objects using this font.
1386 ///
1387 /// ### Parameters
1388 /// - `font`: the font to modify.
1389 /// - `script`: an
1390 /// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
1391 /// .
1392 ///
1393 /// ### Return value
1394 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1395 /// information.
1396 ///
1397 /// ### Thread safety
1398 /// This function should be called on the thread that created the
1399 /// font.
1400 ///
1401 /// ### Availability
1402 /// This function is available since SDL_ttf 3.0.0.
1403 ///
1404 /// ### See also
1405 /// - [`TTF_StringToTag`]
1406 pub fn TTF_SetFontScript(font: *mut TTF_Font, script: Uint32) -> ::core::primitive::bool;
1407}
1408
1409extern "C" {
1410 /// Get the script used for text shaping a font.
1411 ///
1412 /// ### Parameters
1413 /// - `font`: the font to query.
1414 ///
1415 /// ### Return value
1416 /// Returns an
1417 /// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
1418 /// or 0 if a script hasn't been set.
1419 ///
1420 /// ### Thread safety
1421 /// This function should be called on the thread that created the
1422 /// font.
1423 ///
1424 /// ### Availability
1425 /// This function is available since SDL_ttf 3.0.0.
1426 ///
1427 /// ### See also
1428 /// - [`TTF_TagToString`]
1429 pub fn TTF_GetFontScript(font: *mut TTF_Font) -> Uint32;
1430}
1431
1432extern "C" {
1433 /// Get the script used by a 32-bit codepoint.
1434 ///
1435 /// ### Parameters
1436 /// - `ch`: the character code to check.
1437 ///
1438 /// ### Return value
1439 /// Returns an
1440 /// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
1441 /// on success, or 0 on failure; call [`SDL_GetError()`] for more
1442 /// information.
1443 ///
1444 /// ### Thread safety
1445 /// This function is thread-safe.
1446 ///
1447 /// ### Availability
1448 /// This function is available since SDL_ttf 3.0.0.
1449 ///
1450 /// ### See also
1451 /// - [`TTF_TagToString`]
1452 pub fn TTF_GetGlyphScript(ch: Uint32) -> Uint32;
1453}
1454
1455extern "C" {
1456 /// Set language to be used for text shaping by a font.
1457 ///
1458 /// If SDL_ttf was not built with HarfBuzz support, this function returns
1459 /// false.
1460 ///
1461 /// This updates any [`TTF_Text`] objects using this font.
1462 ///
1463 /// ### Parameters
1464 /// - `font`: the font to specify a language for.
1465 /// - `language_bcp47`: a null-terminated string containing the desired
1466 /// language's BCP47 code. Or null to reset the value.
1467 ///
1468 /// ### Return value
1469 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1470 /// information.
1471 ///
1472 /// ### Thread safety
1473 /// This function should be called on the thread that created the
1474 /// font.
1475 ///
1476 /// ### Availability
1477 /// This function is available since SDL_ttf 3.0.0.
1478 pub fn TTF_SetFontLanguage(
1479 font: *mut TTF_Font,
1480 language_bcp47: *const ::core::ffi::c_char,
1481 ) -> ::core::primitive::bool;
1482}
1483
1484extern "C" {
1485 /// Check whether a glyph is provided by the font for a UNICODE codepoint.
1486 ///
1487 /// ### Parameters
1488 /// - `font`: the font to query.
1489 /// - `ch`: the codepoint to check.
1490 ///
1491 /// ### Return value
1492 /// Returns true if font provides a glyph for this character, false if not.
1493 ///
1494 /// ### Thread safety
1495 /// This function should be called on the thread that created the
1496 /// font.
1497 ///
1498 /// ### Availability
1499 /// This function is available since SDL_ttf 3.0.0.
1500 pub fn TTF_FontHasGlyph(font: *mut TTF_Font, ch: Uint32) -> ::core::primitive::bool;
1501}
1502
1503/// The type of data in a glyph image
1504///
1505/// ### Availability
1506/// This enum is available since SDL_ttf 3.0.0.
1507///
1508/// ### Known values (`sdl3-sys`)
1509/// | Associated constant | Global constant | Description |
1510/// | ------------------- | --------------- | ----------- |
1511/// | [`INVALID`](TTF_ImageType::INVALID) | [`TTF_IMAGE_INVALID`] | |
1512/// | [`ALPHA`](TTF_ImageType::ALPHA) | [`TTF_IMAGE_ALPHA`] | The color channels are white |
1513/// | [`COLOR`](TTF_ImageType::COLOR) | [`TTF_IMAGE_COLOR`] | The color channels have image data |
1514/// | [`SDF`](TTF_ImageType::SDF) | [`TTF_IMAGE_SDF`] | The alpha channel has signed distance field information |
1515#[repr(transparent)]
1516#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
1517pub struct TTF_ImageType(pub ::core::ffi::c_int);
1518
1519impl From<TTF_ImageType> for ::core::ffi::c_int {
1520 #[inline(always)]
1521 fn from(value: TTF_ImageType) -> Self {
1522 value.0
1523 }
1524}
1525
1526#[cfg(feature = "debug-impls")]
1527impl ::core::fmt::Debug for TTF_ImageType {
1528 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1529 #[allow(unreachable_patterns)]
1530 f.write_str(match *self {
1531 Self::INVALID => "TTF_IMAGE_INVALID",
1532 Self::ALPHA => "TTF_IMAGE_ALPHA",
1533 Self::COLOR => "TTF_IMAGE_COLOR",
1534 Self::SDF => "TTF_IMAGE_SDF",
1535
1536 _ => return write!(f, "TTF_ImageType({})", self.0),
1537 })
1538 }
1539}
1540
1541impl TTF_ImageType {
1542 pub const INVALID: Self = Self(0);
1543 /// The color channels are white
1544 pub const ALPHA: Self = Self(1);
1545 /// The color channels have image data
1546 pub const COLOR: Self = Self(2);
1547 /// The alpha channel has signed distance field information
1548 pub const SDF: Self = Self(3);
1549}
1550
1551pub const TTF_IMAGE_INVALID: TTF_ImageType = TTF_ImageType::INVALID;
1552/// The color channels are white
1553pub const TTF_IMAGE_ALPHA: TTF_ImageType = TTF_ImageType::ALPHA;
1554/// The color channels have image data
1555pub const TTF_IMAGE_COLOR: TTF_ImageType = TTF_ImageType::COLOR;
1556/// The alpha channel has signed distance field information
1557pub const TTF_IMAGE_SDF: TTF_ImageType = TTF_ImageType::SDF;
1558
1559extern "C" {
1560 /// Get the pixel image for a UNICODE codepoint.
1561 ///
1562 /// ### Parameters
1563 /// - `font`: the font to query.
1564 /// - `ch`: the codepoint to check.
1565 /// - `image_type`: a pointer filled in with the glyph image type, may be
1566 /// NULL.
1567 ///
1568 /// ### Return value
1569 /// Returns an [`SDL_Surface`] containing the glyph, or NULL on failure; call
1570 /// [`SDL_GetError()`] for more information.
1571 ///
1572 /// ### Thread safety
1573 /// This function should be called on the thread that created the
1574 /// font.
1575 ///
1576 /// ### Availability
1577 /// This function is available since SDL_ttf 3.0.0.
1578 pub fn TTF_GetGlyphImage(
1579 font: *mut TTF_Font,
1580 ch: Uint32,
1581 image_type: *mut TTF_ImageType,
1582 ) -> *mut SDL_Surface;
1583}
1584
1585extern "C" {
1586 /// Get the pixel image for a character index.
1587 ///
1588 /// This is useful for text engine implementations, which can call this with
1589 /// the `glyph_index` in a [`TTF_CopyOperation`]
1590 ///
1591 /// ### Parameters
1592 /// - `font`: the font to query.
1593 /// - `glyph_index`: the index of the glyph to return.
1594 /// - `image_type`: a pointer filled in with the glyph image type, may be
1595 /// NULL.
1596 ///
1597 /// ### Return value
1598 /// Returns an [`SDL_Surface`] containing the glyph, or NULL on failure; call
1599 /// [`SDL_GetError()`] for more information.
1600 ///
1601 /// ### Thread safety
1602 /// This function should be called on the thread that created the
1603 /// font.
1604 ///
1605 /// ### Availability
1606 /// This function is available since SDL_ttf 3.0.0.
1607 pub fn TTF_GetGlyphImageForIndex(
1608 font: *mut TTF_Font,
1609 glyph_index: Uint32,
1610 image_type: *mut TTF_ImageType,
1611 ) -> *mut SDL_Surface;
1612}
1613
1614extern "C" {
1615 /// Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint.
1616 ///
1617 /// To understand what these metrics mean, here is a useful link:
1618 ///
1619 /// <https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html>
1620 ///
1621 /// ### Parameters
1622 /// - `font`: the font to query.
1623 /// - `ch`: the codepoint to check.
1624 /// - `minx`: a pointer filled in with the minimum x coordinate of the glyph
1625 /// from the left edge of its bounding box. This value may be
1626 /// negative.
1627 /// - `maxx`: a pointer filled in with the maximum x coordinate of the glyph
1628 /// from the left edge of its bounding box.
1629 /// - `miny`: a pointer filled in with the minimum y coordinate of the glyph
1630 /// from the bottom edge of its bounding box. This value may be
1631 /// negative.
1632 /// - `maxy`: a pointer filled in with the maximum y coordinate of the glyph
1633 /// from the bottom edge of its bounding box.
1634 /// - `advance`: a pointer filled in with the distance to the next glyph from
1635 /// the left edge of this glyph's bounding box.
1636 ///
1637 /// ### Return value
1638 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1639 /// information.
1640 ///
1641 /// ### Thread safety
1642 /// This function should be called on the thread that created the
1643 /// font.
1644 ///
1645 /// ### Availability
1646 /// This function is available since SDL_ttf 3.0.0.
1647 pub fn TTF_GetGlyphMetrics(
1648 font: *mut TTF_Font,
1649 ch: Uint32,
1650 minx: *mut ::core::ffi::c_int,
1651 maxx: *mut ::core::ffi::c_int,
1652 miny: *mut ::core::ffi::c_int,
1653 maxy: *mut ::core::ffi::c_int,
1654 advance: *mut ::core::ffi::c_int,
1655 ) -> ::core::primitive::bool;
1656}
1657
1658extern "C" {
1659 /// Query the kerning size between the glyphs of two UNICODE codepoints.
1660 ///
1661 /// ### Parameters
1662 /// - `font`: the font to query.
1663 /// - `previous_ch`: the previous codepoint.
1664 /// - `ch`: the current codepoint.
1665 /// - `kerning`: a pointer filled in with the kerning size between the two
1666 /// glyphs, in pixels, may be NULL.
1667 ///
1668 /// ### Return value
1669 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1670 /// information.
1671 ///
1672 /// ### Thread safety
1673 /// This function should be called on the thread that created the
1674 /// font.
1675 ///
1676 /// ### Availability
1677 /// This function is available since SDL_ttf 3.0.0.
1678 pub fn TTF_GetGlyphKerning(
1679 font: *mut TTF_Font,
1680 previous_ch: Uint32,
1681 ch: Uint32,
1682 kerning: *mut ::core::ffi::c_int,
1683 ) -> ::core::primitive::bool;
1684}
1685
1686extern "C" {
1687 /// Calculate the dimensions of a rendered string of UTF-8 text.
1688 ///
1689 /// This will report the width and height, in pixels, of the space that the
1690 /// specified string will take to fully render.
1691 ///
1692 /// ### Parameters
1693 /// - `font`: the font to query.
1694 /// - `text`: text to calculate, in UTF-8 encoding.
1695 /// - `length`: the length of the text, in bytes, or 0 for null terminated
1696 /// text.
1697 /// - `w`: will be filled with width, in pixels, on return.
1698 /// - `h`: will be filled with height, in pixels, on return.
1699 ///
1700 /// ### Return value
1701 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1702 /// information.
1703 ///
1704 /// ### Thread safety
1705 /// This function should be called on the thread that created the
1706 /// font.
1707 ///
1708 /// ### Availability
1709 /// This function is available since SDL_ttf 3.0.0.
1710 pub fn TTF_GetStringSize(
1711 font: *mut TTF_Font,
1712 text: *const ::core::ffi::c_char,
1713 length: ::core::primitive::usize,
1714 w: *mut ::core::ffi::c_int,
1715 h: *mut ::core::ffi::c_int,
1716 ) -> ::core::primitive::bool;
1717}
1718
1719extern "C" {
1720 /// Calculate the dimensions of a rendered string of UTF-8 text.
1721 ///
1722 /// This will report the width and height, in pixels, of the space that the
1723 /// specified string will take to fully render.
1724 ///
1725 /// Text is wrapped to multiple lines on line endings and on word boundaries if
1726 /// it extends beyond `wrap_width` in pixels.
1727 ///
1728 /// If wrap_width is 0, this function will only wrap on newline characters.
1729 ///
1730 /// ### Parameters
1731 /// - `font`: the font to query.
1732 /// - `text`: text to calculate, in UTF-8 encoding.
1733 /// - `length`: the length of the text, in bytes, or 0 for null terminated
1734 /// text.
1735 /// - `wrap_width`: the maximum width or 0 to wrap on newline characters.
1736 /// - `w`: will be filled with width, in pixels, on return.
1737 /// - `h`: will be filled with height, in pixels, on return.
1738 ///
1739 /// ### Return value
1740 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1741 /// information.
1742 ///
1743 /// ### Thread safety
1744 /// This function should be called on the thread that created the
1745 /// font.
1746 ///
1747 /// ### Availability
1748 /// This function is available since SDL_ttf 3.0.0.
1749 pub fn TTF_GetStringSizeWrapped(
1750 font: *mut TTF_Font,
1751 text: *const ::core::ffi::c_char,
1752 length: ::core::primitive::usize,
1753 wrap_width: ::core::ffi::c_int,
1754 w: *mut ::core::ffi::c_int,
1755 h: *mut ::core::ffi::c_int,
1756 ) -> ::core::primitive::bool;
1757}
1758
1759extern "C" {
1760 /// Calculate how much of a UTF-8 string will fit in a given width.
1761 ///
1762 /// This reports the number of characters that can be rendered before reaching
1763 /// `max_width`.
1764 ///
1765 /// This does not need to render the string to do this calculation.
1766 ///
1767 /// ### Parameters
1768 /// - `font`: the font to query.
1769 /// - `text`: text to calculate, in UTF-8 encoding.
1770 /// - `length`: the length of the text, in bytes, or 0 for null terminated
1771 /// text.
1772 /// - `max_width`: maximum width, in pixels, available for the string, or 0
1773 /// for unbounded width.
1774 /// - `measured_width`: a pointer filled in with the width, in pixels, of the
1775 /// string that will fit, may be NULL.
1776 /// - `measured_length`: a pointer filled in with the length, in bytes, of
1777 /// the string that will fit, may be NULL.
1778 ///
1779 /// ### Return value
1780 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1781 /// information.
1782 ///
1783 /// ### Thread safety
1784 /// This function should be called on the thread that created the
1785 /// font.
1786 ///
1787 /// ### Availability
1788 /// This function is available since SDL_ttf 3.0.0.
1789 pub fn TTF_MeasureString(
1790 font: *mut TTF_Font,
1791 text: *const ::core::ffi::c_char,
1792 length: ::core::primitive::usize,
1793 max_width: ::core::ffi::c_int,
1794 measured_width: *mut ::core::ffi::c_int,
1795 measured_length: *mut ::core::primitive::usize,
1796 ) -> ::core::primitive::bool;
1797}
1798
1799extern "C" {
1800 /// Render UTF-8 text at fast quality to a new 8-bit surface.
1801 ///
1802 /// This function will allocate a new 8-bit, palettized surface. The surface's
1803 /// 0 pixel will be the colorkey, giving a transparent background. The 1 pixel
1804 /// will be set to the text color.
1805 ///
1806 /// This will not word-wrap the string; you'll get a surface with a single line
1807 /// of text, as long as the string requires. You can use
1808 /// [`TTF_RenderText_Solid_Wrapped()`] instead if you need to wrap the output to
1809 /// multiple lines.
1810 ///
1811 /// This will not wrap on newline characters.
1812 ///
1813 /// You can render at other quality levels with [`TTF_RenderText_Shaded`],
1814 /// [`TTF_RenderText_Blended`], and [`TTF_RenderText_LCD`].
1815 ///
1816 /// ### Parameters
1817 /// - `font`: the font to render with.
1818 /// - `text`: text to render, in UTF-8 encoding.
1819 /// - `length`: the length of the text, in bytes, or 0 for null terminated
1820 /// text.
1821 /// - `fg`: the foreground color for the text.
1822 ///
1823 /// ### Return value
1824 /// Returns a new 8-bit, palettized surface, or NULL if there was an error.
1825 ///
1826 /// ### Thread safety
1827 /// This function should be called on the thread that created the
1828 /// font.
1829 ///
1830 /// ### Availability
1831 /// This function is available since SDL_ttf 3.0.0.
1832 ///
1833 /// ### See also
1834 /// - [`TTF_RenderText_Blended`]
1835 /// - [`TTF_RenderText_LCD`]
1836 /// - [`TTF_RenderText_Shaded`]
1837 /// - [`TTF_RenderText_Solid`]
1838 /// - [`TTF_RenderText_Solid_Wrapped`]
1839 pub fn TTF_RenderText_Solid(
1840 font: *mut TTF_Font,
1841 text: *const ::core::ffi::c_char,
1842 length: ::core::primitive::usize,
1843 fg: SDL_Color,
1844 ) -> *mut SDL_Surface;
1845}
1846
1847extern "C" {
1848 /// Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface.
1849 ///
1850 /// This function will allocate a new 8-bit, palettized surface. The surface's
1851 /// 0 pixel will be the colorkey, giving a transparent background. The 1 pixel
1852 /// will be set to the text color.
1853 ///
1854 /// Text is wrapped to multiple lines on line endings and on word boundaries if
1855 /// it extends beyond `wrapLength` in pixels.
1856 ///
1857 /// If wrapLength is 0, this function will only wrap on newline characters.
1858 ///
1859 /// You can render at other quality levels with [`TTF_RenderText_Shaded_Wrapped`],
1860 /// [`TTF_RenderText_Blended_Wrapped`], and [`TTF_RenderText_LCD_Wrapped`].
1861 ///
1862 /// ### Parameters
1863 /// - `font`: the font to render with.
1864 /// - `text`: text to render, in UTF-8 encoding.
1865 /// - `length`: the length of the text, in bytes, or 0 for null terminated
1866 /// text.
1867 /// - `fg`: the foreground color for the text.
1868 /// - `wrapLength`: the maximum width of the text surface or 0 to wrap on
1869 /// newline characters.
1870 ///
1871 /// ### Return value
1872 /// Returns a new 8-bit, palettized surface, or NULL if there was an error.
1873 ///
1874 /// ### Thread safety
1875 /// This function should be called on the thread that created the
1876 /// font.
1877 ///
1878 /// ### Availability
1879 /// This function is available since SDL_ttf 3.0.0.
1880 ///
1881 /// ### See also
1882 /// - [`TTF_RenderText_Blended_Wrapped`]
1883 /// - [`TTF_RenderText_LCD_Wrapped`]
1884 /// - [`TTF_RenderText_Shaded_Wrapped`]
1885 /// - [`TTF_RenderText_Solid`]
1886 pub fn TTF_RenderText_Solid_Wrapped(
1887 font: *mut TTF_Font,
1888 text: *const ::core::ffi::c_char,
1889 length: ::core::primitive::usize,
1890 fg: SDL_Color,
1891 wrapLength: ::core::ffi::c_int,
1892 ) -> *mut SDL_Surface;
1893}
1894
1895extern "C" {
1896 /// Render a single 32-bit glyph at fast quality to a new 8-bit surface.
1897 ///
1898 /// This function will allocate a new 8-bit, palettized surface. The surface's
1899 /// 0 pixel will be the colorkey, giving a transparent background. The 1 pixel
1900 /// will be set to the text color.
1901 ///
1902 /// The glyph is rendered without any padding or centering in the X direction,
1903 /// and aligned normally in the Y direction.
1904 ///
1905 /// You can render at other quality levels with [`TTF_RenderGlyph_Shaded`],
1906 /// [`TTF_RenderGlyph_Blended`], and [`TTF_RenderGlyph_LCD`].
1907 ///
1908 /// ### Parameters
1909 /// - `font`: the font to render with.
1910 /// - `ch`: the character to render.
1911 /// - `fg`: the foreground color for the text.
1912 ///
1913 /// ### Return value
1914 /// Returns a new 8-bit, palettized surface, or NULL if there was an error.
1915 ///
1916 /// ### Thread safety
1917 /// This function should be called on the thread that created the
1918 /// font.
1919 ///
1920 /// ### Availability
1921 /// This function is available since SDL_ttf 3.0.0.
1922 ///
1923 /// ### See also
1924 /// - [`TTF_RenderGlyph_Blended`]
1925 /// - [`TTF_RenderGlyph_LCD`]
1926 /// - [`TTF_RenderGlyph_Shaded`]
1927 pub fn TTF_RenderGlyph_Solid(
1928 font: *mut TTF_Font,
1929 ch: Uint32,
1930 fg: SDL_Color,
1931 ) -> *mut SDL_Surface;
1932}
1933
1934extern "C" {
1935 /// Render UTF-8 text at high quality to a new 8-bit surface.
1936 ///
1937 /// This function will allocate a new 8-bit, palettized surface. The surface's
1938 /// 0 pixel will be the specified background color, while other pixels have
1939 /// varying degrees of the foreground color. This function returns the new
1940 /// surface, or NULL if there was an error.
1941 ///
1942 /// This will not word-wrap the string; you'll get a surface with a single line
1943 /// of text, as long as the string requires. You can use
1944 /// [`TTF_RenderText_Shaded_Wrapped()`] instead if you need to wrap the output to
1945 /// multiple lines.
1946 ///
1947 /// This will not wrap on newline characters.
1948 ///
1949 /// You can render at other quality levels with [`TTF_RenderText_Solid`],
1950 /// [`TTF_RenderText_Blended`], and [`TTF_RenderText_LCD`].
1951 ///
1952 /// ### Parameters
1953 /// - `font`: the font to render with.
1954 /// - `text`: text to render, in UTF-8 encoding.
1955 /// - `length`: the length of the text, in bytes, or 0 for null terminated
1956 /// text.
1957 /// - `fg`: the foreground color for the text.
1958 /// - `bg`: the background color for the text.
1959 ///
1960 /// ### Return value
1961 /// Returns a new 8-bit, palettized surface, or NULL if there was an error.
1962 ///
1963 /// ### Thread safety
1964 /// This function should be called on the thread that created the
1965 /// font.
1966 ///
1967 /// ### Availability
1968 /// This function is available since SDL_ttf 3.0.0.
1969 ///
1970 /// ### See also
1971 /// - [`TTF_RenderText_Blended`]
1972 /// - [`TTF_RenderText_LCD`]
1973 /// - [`TTF_RenderText_Shaded_Wrapped`]
1974 /// - [`TTF_RenderText_Solid`]
1975 pub fn TTF_RenderText_Shaded(
1976 font: *mut TTF_Font,
1977 text: *const ::core::ffi::c_char,
1978 length: ::core::primitive::usize,
1979 fg: SDL_Color,
1980 bg: SDL_Color,
1981 ) -> *mut SDL_Surface;
1982}
1983
1984extern "C" {
1985 /// Render word-wrapped UTF-8 text at high quality to a new 8-bit surface.
1986 ///
1987 /// This function will allocate a new 8-bit, palettized surface. The surface's
1988 /// 0 pixel will be the specified background color, while other pixels have
1989 /// varying degrees of the foreground color. This function returns the new
1990 /// surface, or NULL if there was an error.
1991 ///
1992 /// Text is wrapped to multiple lines on line endings and on word boundaries if
1993 /// it extends beyond `wrap_width` in pixels.
1994 ///
1995 /// If wrap_width is 0, this function will only wrap on newline characters.
1996 ///
1997 /// You can render at other quality levels with [`TTF_RenderText_Solid_Wrapped`],
1998 /// [`TTF_RenderText_Blended_Wrapped`], and [`TTF_RenderText_LCD_Wrapped`].
1999 ///
2000 /// ### Parameters
2001 /// - `font`: the font to render with.
2002 /// - `text`: text to render, in UTF-8 encoding.
2003 /// - `length`: the length of the text, in bytes, or 0 for null terminated
2004 /// text.
2005 /// - `fg`: the foreground color for the text.
2006 /// - `bg`: the background color for the text.
2007 /// - `wrap_width`: the maximum width of the text surface or 0 to wrap on
2008 /// newline characters.
2009 ///
2010 /// ### Return value
2011 /// Returns a new 8-bit, palettized surface, or NULL if there was an error.
2012 ///
2013 /// ### Thread safety
2014 /// This function should be called on the thread that created the
2015 /// font.
2016 ///
2017 /// ### Availability
2018 /// This function is available since SDL_ttf 3.0.0.
2019 ///
2020 /// ### See also
2021 /// - [`TTF_RenderText_Blended_Wrapped`]
2022 /// - [`TTF_RenderText_LCD_Wrapped`]
2023 /// - [`TTF_RenderText_Shaded`]
2024 /// - [`TTF_RenderText_Solid_Wrapped`]
2025 pub fn TTF_RenderText_Shaded_Wrapped(
2026 font: *mut TTF_Font,
2027 text: *const ::core::ffi::c_char,
2028 length: ::core::primitive::usize,
2029 fg: SDL_Color,
2030 bg: SDL_Color,
2031 wrap_width: ::core::ffi::c_int,
2032 ) -> *mut SDL_Surface;
2033}
2034
2035extern "C" {
2036 /// Render a single UNICODE codepoint at high quality to a new 8-bit surface.
2037 ///
2038 /// This function will allocate a new 8-bit, palettized surface. The surface's
2039 /// 0 pixel will be the specified background color, while other pixels have
2040 /// varying degrees of the foreground color. This function returns the new
2041 /// surface, or NULL if there was an error.
2042 ///
2043 /// The glyph is rendered without any padding or centering in the X direction,
2044 /// and aligned normally in the Y direction.
2045 ///
2046 /// You can render at other quality levels with [`TTF_RenderGlyph_Solid`],
2047 /// [`TTF_RenderGlyph_Blended`], and [`TTF_RenderGlyph_LCD`].
2048 ///
2049 /// ### Parameters
2050 /// - `font`: the font to render with.
2051 /// - `ch`: the codepoint to render.
2052 /// - `fg`: the foreground color for the text.
2053 /// - `bg`: the background color for the text.
2054 ///
2055 /// ### Return value
2056 /// Returns a new 8-bit, palettized surface, or NULL if there was an error.
2057 ///
2058 /// ### Thread safety
2059 /// This function should be called on the thread that created the
2060 /// font.
2061 ///
2062 /// ### Availability
2063 /// This function is available since SDL_ttf 3.0.0.
2064 ///
2065 /// ### See also
2066 /// - [`TTF_RenderGlyph_Blended`]
2067 /// - [`TTF_RenderGlyph_LCD`]
2068 /// - [`TTF_RenderGlyph_Solid`]
2069 pub fn TTF_RenderGlyph_Shaded(
2070 font: *mut TTF_Font,
2071 ch: Uint32,
2072 fg: SDL_Color,
2073 bg: SDL_Color,
2074 ) -> *mut SDL_Surface;
2075}
2076
2077extern "C" {
2078 /// Render UTF-8 text at high quality to a new ARGB surface.
2079 ///
2080 /// This function will allocate a new 32-bit, ARGB surface, using alpha
2081 /// blending to dither the font with the given color. This function returns the
2082 /// new surface, or NULL if there was an error.
2083 ///
2084 /// This will not word-wrap the string; you'll get a surface with a single line
2085 /// of text, as long as the string requires. You can use
2086 /// [`TTF_RenderText_Blended_Wrapped()`] instead if you need to wrap the output to
2087 /// multiple lines.
2088 ///
2089 /// This will not wrap on newline characters.
2090 ///
2091 /// You can render at other quality levels with [`TTF_RenderText_Solid`],
2092 /// [`TTF_RenderText_Shaded`], and [`TTF_RenderText_LCD`].
2093 ///
2094 /// ### Parameters
2095 /// - `font`: the font to render with.
2096 /// - `text`: text to render, in UTF-8 encoding.
2097 /// - `length`: the length of the text, in bytes, or 0 for null terminated
2098 /// text.
2099 /// - `fg`: the foreground color for the text.
2100 ///
2101 /// ### Return value
2102 /// Returns a new 32-bit, ARGB surface, or NULL if there was an error.
2103 ///
2104 /// ### Thread safety
2105 /// This function should be called on the thread that created the
2106 /// font.
2107 ///
2108 /// ### Availability
2109 /// This function is available since SDL_ttf 3.0.0.
2110 ///
2111 /// ### See also
2112 /// - [`TTF_RenderText_Blended_Wrapped`]
2113 /// - [`TTF_RenderText_LCD`]
2114 /// - [`TTF_RenderText_Shaded`]
2115 /// - [`TTF_RenderText_Solid`]
2116 pub fn TTF_RenderText_Blended(
2117 font: *mut TTF_Font,
2118 text: *const ::core::ffi::c_char,
2119 length: ::core::primitive::usize,
2120 fg: SDL_Color,
2121 ) -> *mut SDL_Surface;
2122}
2123
2124extern "C" {
2125 /// Render word-wrapped UTF-8 text at high quality to a new ARGB surface.
2126 ///
2127 /// This function will allocate a new 32-bit, ARGB surface, using alpha
2128 /// blending to dither the font with the given color. This function returns the
2129 /// new surface, or NULL if there was an error.
2130 ///
2131 /// Text is wrapped to multiple lines on line endings and on word boundaries if
2132 /// it extends beyond `wrap_width` in pixels.
2133 ///
2134 /// If wrap_width is 0, this function will only wrap on newline characters.
2135 ///
2136 /// You can render at other quality levels with [`TTF_RenderText_Solid_Wrapped`],
2137 /// [`TTF_RenderText_Shaded_Wrapped`], and [`TTF_RenderText_LCD_Wrapped`].
2138 ///
2139 /// ### Parameters
2140 /// - `font`: the font to render with.
2141 /// - `text`: text to render, in UTF-8 encoding.
2142 /// - `length`: the length of the text, in bytes, or 0 for null terminated
2143 /// text.
2144 /// - `fg`: the foreground color for the text.
2145 /// - `wrap_width`: the maximum width of the text surface or 0 to wrap on
2146 /// newline characters.
2147 ///
2148 /// ### Return value
2149 /// Returns a new 32-bit, ARGB surface, or NULL if there was an error.
2150 ///
2151 /// ### Thread safety
2152 /// This function should be called on the thread that created the
2153 /// font.
2154 ///
2155 /// ### Availability
2156 /// This function is available since SDL_ttf 3.0.0.
2157 ///
2158 /// ### See also
2159 /// - [`TTF_RenderText_Blended`]
2160 /// - [`TTF_RenderText_LCD_Wrapped`]
2161 /// - [`TTF_RenderText_Shaded_Wrapped`]
2162 /// - [`TTF_RenderText_Solid_Wrapped`]
2163 pub fn TTF_RenderText_Blended_Wrapped(
2164 font: *mut TTF_Font,
2165 text: *const ::core::ffi::c_char,
2166 length: ::core::primitive::usize,
2167 fg: SDL_Color,
2168 wrap_width: ::core::ffi::c_int,
2169 ) -> *mut SDL_Surface;
2170}
2171
2172extern "C" {
2173 /// Render a single UNICODE codepoint at high quality to a new ARGB surface.
2174 ///
2175 /// This function will allocate a new 32-bit, ARGB surface, using alpha
2176 /// blending to dither the font with the given color. This function returns the
2177 /// new surface, or NULL if there was an error.
2178 ///
2179 /// The glyph is rendered without any padding or centering in the X direction,
2180 /// and aligned normally in the Y direction.
2181 ///
2182 /// You can render at other quality levels with [`TTF_RenderGlyph_Solid`],
2183 /// [`TTF_RenderGlyph_Shaded`], and [`TTF_RenderGlyph_LCD`].
2184 ///
2185 /// ### Parameters
2186 /// - `font`: the font to render with.
2187 /// - `ch`: the codepoint to render.
2188 /// - `fg`: the foreground color for the text.
2189 ///
2190 /// ### Return value
2191 /// Returns a new 32-bit, ARGB surface, or NULL if there was an error.
2192 ///
2193 /// ### Thread safety
2194 /// This function should be called on the thread that created the
2195 /// font.
2196 ///
2197 /// ### Availability
2198 /// This function is available since SDL_ttf 3.0.0.
2199 ///
2200 /// ### See also
2201 /// - [`TTF_RenderGlyph_LCD`]
2202 /// - [`TTF_RenderGlyph_Shaded`]
2203 /// - [`TTF_RenderGlyph_Solid`]
2204 pub fn TTF_RenderGlyph_Blended(
2205 font: *mut TTF_Font,
2206 ch: Uint32,
2207 fg: SDL_Color,
2208 ) -> *mut SDL_Surface;
2209}
2210
2211extern "C" {
2212 /// Render UTF-8 text at LCD subpixel quality to a new ARGB surface.
2213 ///
2214 /// This function will allocate a new 32-bit, ARGB surface, and render
2215 /// alpha-blended text using FreeType's LCD subpixel rendering. This function
2216 /// returns the new surface, or NULL if there was an error.
2217 ///
2218 /// This will not word-wrap the string; you'll get a surface with a single line
2219 /// of text, as long as the string requires. You can use
2220 /// [`TTF_RenderText_LCD_Wrapped()`] instead if you need to wrap the output to
2221 /// multiple lines.
2222 ///
2223 /// This will not wrap on newline characters.
2224 ///
2225 /// You can render at other quality levels with [`TTF_RenderText_Solid`],
2226 /// [`TTF_RenderText_Shaded`], and [`TTF_RenderText_Blended`].
2227 ///
2228 /// ### Parameters
2229 /// - `font`: the font to render with.
2230 /// - `text`: text to render, in UTF-8 encoding.
2231 /// - `length`: the length of the text, in bytes, or 0 for null terminated
2232 /// text.
2233 /// - `fg`: the foreground color for the text.
2234 /// - `bg`: the background color for the text.
2235 ///
2236 /// ### Return value
2237 /// Returns a new 32-bit, ARGB surface, or NULL if there was an error.
2238 ///
2239 /// ### Thread safety
2240 /// This function should be called on the thread that created the
2241 /// font.
2242 ///
2243 /// ### Availability
2244 /// This function is available since SDL_ttf 3.0.0.
2245 ///
2246 /// ### See also
2247 /// - [`TTF_RenderText_Blended`]
2248 /// - [`TTF_RenderText_LCD_Wrapped`]
2249 /// - [`TTF_RenderText_Shaded`]
2250 /// - [`TTF_RenderText_Solid`]
2251 pub fn TTF_RenderText_LCD(
2252 font: *mut TTF_Font,
2253 text: *const ::core::ffi::c_char,
2254 length: ::core::primitive::usize,
2255 fg: SDL_Color,
2256 bg: SDL_Color,
2257 ) -> *mut SDL_Surface;
2258}
2259
2260extern "C" {
2261 /// Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB
2262 /// surface.
2263 ///
2264 /// This function will allocate a new 32-bit, ARGB surface, and render
2265 /// alpha-blended text using FreeType's LCD subpixel rendering. This function
2266 /// returns the new surface, or NULL if there was an error.
2267 ///
2268 /// Text is wrapped to multiple lines on line endings and on word boundaries if
2269 /// it extends beyond `wrap_width` in pixels.
2270 ///
2271 /// If wrap_width is 0, this function will only wrap on newline characters.
2272 ///
2273 /// You can render at other quality levels with [`TTF_RenderText_Solid_Wrapped`],
2274 /// [`TTF_RenderText_Shaded_Wrapped`], and [`TTF_RenderText_Blended_Wrapped`].
2275 ///
2276 /// ### Parameters
2277 /// - `font`: the font to render with.
2278 /// - `text`: text to render, in UTF-8 encoding.
2279 /// - `length`: the length of the text, in bytes, or 0 for null terminated
2280 /// text.
2281 /// - `fg`: the foreground color for the text.
2282 /// - `bg`: the background color for the text.
2283 /// - `wrap_width`: the maximum width of the text surface or 0 to wrap on
2284 /// newline characters.
2285 ///
2286 /// ### Return value
2287 /// Returns a new 32-bit, ARGB surface, or NULL if there was an error.
2288 ///
2289 /// ### Thread safety
2290 /// This function should be called on the thread that created the
2291 /// font.
2292 ///
2293 /// ### Availability
2294 /// This function is available since SDL_ttf 3.0.0.
2295 ///
2296 /// ### See also
2297 /// - [`TTF_RenderText_Blended_Wrapped`]
2298 /// - [`TTF_RenderText_LCD`]
2299 /// - [`TTF_RenderText_Shaded_Wrapped`]
2300 /// - [`TTF_RenderText_Solid_Wrapped`]
2301 pub fn TTF_RenderText_LCD_Wrapped(
2302 font: *mut TTF_Font,
2303 text: *const ::core::ffi::c_char,
2304 length: ::core::primitive::usize,
2305 fg: SDL_Color,
2306 bg: SDL_Color,
2307 wrap_width: ::core::ffi::c_int,
2308 ) -> *mut SDL_Surface;
2309}
2310
2311extern "C" {
2312 /// Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB
2313 /// surface.
2314 ///
2315 /// This function will allocate a new 32-bit, ARGB surface, and render
2316 /// alpha-blended text using FreeType's LCD subpixel rendering. This function
2317 /// returns the new surface, or NULL if there was an error.
2318 ///
2319 /// The glyph is rendered without any padding or centering in the X direction,
2320 /// and aligned normally in the Y direction.
2321 ///
2322 /// You can render at other quality levels with [`TTF_RenderGlyph_Solid`],
2323 /// [`TTF_RenderGlyph_Shaded`], and [`TTF_RenderGlyph_Blended`].
2324 ///
2325 /// ### Parameters
2326 /// - `font`: the font to render with.
2327 /// - `ch`: the codepoint to render.
2328 /// - `fg`: the foreground color for the text.
2329 /// - `bg`: the background color for the text.
2330 ///
2331 /// ### Return value
2332 /// Returns a new 32-bit, ARGB surface, or NULL if there was an error.
2333 ///
2334 /// ### Thread safety
2335 /// This function should be called on the thread that created the
2336 /// font.
2337 ///
2338 /// ### Availability
2339 /// This function is available since SDL_ttf 3.0.0.
2340 ///
2341 /// ### See also
2342 /// - [`TTF_RenderGlyph_Blended`]
2343 /// - [`TTF_RenderGlyph_Shaded`]
2344 /// - [`TTF_RenderGlyph_Solid`]
2345 pub fn TTF_RenderGlyph_LCD(
2346 font: *mut TTF_Font,
2347 ch: Uint32,
2348 fg: SDL_Color,
2349 bg: SDL_Color,
2350 ) -> *mut SDL_Surface;
2351}
2352
2353pub use super::textengine::TTF_TextEngine;
2354
2355/// Text created with [`TTF_CreateText()`]
2356///
2357/// ### Availability
2358/// This struct is available since SDL_ttf 3.0.0.
2359///
2360/// ### See also
2361/// - [`TTF_CreateText`]
2362/// - [`TTF_GetTextProperties`]
2363/// - [`TTF_DestroyText`]
2364#[repr(C)]
2365// #[non_exhaustive] // temporarily disabled bc of https://github.com/rust-lang/rust/issues/132699
2366#[cfg_attr(feature = "debug-impls", derive(Debug))]
2367pub struct TTF_Text {
2368 /// A copy of the UTF-8 string that this text object represents, useful for layout, debugging and retrieving substring text. This is updated when the text object is modified and will be freed automatically when the object is destroyed.
2369 pub text: *mut ::core::ffi::c_char,
2370 /// The number of lines in the text, 0 if it's empty
2371 pub num_lines: ::core::ffi::c_int,
2372 /// Application reference count, used when freeing surface
2373 pub refcount: ::core::ffi::c_int,
2374 /// Private
2375 pub internal: *mut TTF_TextData,
2376}
2377
2378extern "C" {
2379 /// Create a text engine for drawing text on SDL surfaces.
2380 ///
2381 /// ### Return value
2382 /// Returns a [`TTF_TextEngine`] object or NULL on failure; call [`SDL_GetError()`]
2383 /// for more information.
2384 ///
2385 /// ### Thread safety
2386 /// It is safe to call this function from any thread.
2387 ///
2388 /// ### Availability
2389 /// This function is available since SDL_ttf 3.0.0.
2390 ///
2391 /// ### See also
2392 /// - [`TTF_DestroySurfaceTextEngine`]
2393 /// - [`TTF_DrawSurfaceText`]
2394 pub fn TTF_CreateSurfaceTextEngine() -> *mut TTF_TextEngine;
2395}
2396
2397extern "C" {
2398 /// Draw text to an SDL surface.
2399 ///
2400 /// `text` must have been created using a [`TTF_TextEngine`] from
2401 /// [`TTF_CreateSurfaceTextEngine()`].
2402 ///
2403 /// ### Parameters
2404 /// - `text`: the text to draw.
2405 /// - `x`: the x coordinate in pixels, positive from the left edge towards
2406 /// the right.
2407 /// - `y`: the y coordinate in pixels, positive from the top edge towards the
2408 /// bottom.
2409 /// - `surface`: the surface to draw on.
2410 ///
2411 /// ### Return value
2412 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2413 /// information.
2414 ///
2415 /// ### Thread safety
2416 /// This function should be called on the thread that created the
2417 /// text.
2418 ///
2419 /// ### Availability
2420 /// This function is available since SDL_ttf 3.0.0.
2421 ///
2422 /// ### See also
2423 /// - [`TTF_CreateSurfaceTextEngine`]
2424 /// - [`TTF_CreateText`]
2425 pub fn TTF_DrawSurfaceText(
2426 text: *mut TTF_Text,
2427 x: ::core::ffi::c_int,
2428 y: ::core::ffi::c_int,
2429 surface: *mut SDL_Surface,
2430 ) -> ::core::primitive::bool;
2431}
2432
2433extern "C" {
2434 /// Destroy a text engine created for drawing text on SDL surfaces.
2435 ///
2436 /// All text created by this engine should be destroyed before calling this
2437 /// function.
2438 ///
2439 /// ### Parameters
2440 /// - `engine`: a [`TTF_TextEngine`] object created with
2441 /// [`TTF_CreateSurfaceTextEngine()`].
2442 ///
2443 /// ### Thread safety
2444 /// This function should be called on the thread that created the
2445 /// engine.
2446 ///
2447 /// ### Availability
2448 /// This function is available since SDL_ttf 3.0.0.
2449 ///
2450 /// ### See also
2451 /// - [`TTF_CreateSurfaceTextEngine`]
2452 pub fn TTF_DestroySurfaceTextEngine(engine: *mut TTF_TextEngine);
2453}
2454
2455extern "C" {
2456 /// Create a text engine for drawing text on an SDL renderer.
2457 ///
2458 /// ### Parameters
2459 /// - `renderer`: the renderer to use for creating textures and drawing text.
2460 ///
2461 /// ### Return value
2462 /// Returns a [`TTF_TextEngine`] object or NULL on failure; call [`SDL_GetError()`]
2463 /// for more information.
2464 ///
2465 /// ### Thread safety
2466 /// This function should be called on the thread that created the
2467 /// renderer.
2468 ///
2469 /// ### Availability
2470 /// This function is available since SDL_ttf 3.0.0.
2471 ///
2472 /// ### See also
2473 /// - [`TTF_DestroyRendererTextEngine`]
2474 /// - [`TTF_DrawRendererText`]
2475 /// - [`TTF_CreateRendererTextEngineWithProperties`]
2476 pub fn TTF_CreateRendererTextEngine(renderer: *mut SDL_Renderer) -> *mut TTF_TextEngine;
2477}
2478
2479extern "C" {
2480 /// Create a text engine for drawing text on an SDL renderer, with the
2481 /// specified properties.
2482 ///
2483 /// These are the supported properties:
2484 ///
2485 /// - [`TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER`]\: the renderer to use for
2486 /// creating textures and drawing text
2487 /// - [`TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`]\: the size of the
2488 /// texture atlas
2489 ///
2490 /// ### Parameters
2491 /// - `props`: the properties to use.
2492 ///
2493 /// ### Return value
2494 /// Returns a [`TTF_TextEngine`] object or NULL on failure; call [`SDL_GetError()`]
2495 /// for more information.
2496 ///
2497 /// ### Thread safety
2498 /// This function should be called on the thread that created the
2499 /// renderer.
2500 ///
2501 /// ### Availability
2502 /// This function is available since SDL_ttf 3.0.0.
2503 ///
2504 /// ### See also
2505 /// - [`TTF_CreateRendererTextEngine`]
2506 /// - [`TTF_DestroyRendererTextEngine`]
2507 /// - [`TTF_DrawRendererText`]
2508 pub fn TTF_CreateRendererTextEngineWithProperties(
2509 props: SDL_PropertiesID,
2510 ) -> *mut TTF_TextEngine;
2511}
2512
2513pub const TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER: *const ::core::ffi::c_char =
2514 c"SDL_ttf.renderer_text_engine.create.renderer".as_ptr();
2515
2516pub const TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE: *const ::core::ffi::c_char =
2517 c"SDL_ttf.renderer_text_engine.create.atlas_texture_size".as_ptr();
2518
2519extern "C" {
2520 /// Draw text to an SDL renderer.
2521 ///
2522 /// `text` must have been created using a [`TTF_TextEngine`] from
2523 /// [`TTF_CreateRendererTextEngine()`], and will draw using the renderer passed to
2524 /// that function.
2525 ///
2526 /// ### Parameters
2527 /// - `text`: the text to draw.
2528 /// - `x`: the x coordinate in pixels, positive from the left edge towards
2529 /// the right.
2530 /// - `y`: the y coordinate in pixels, positive from the top edge towards the
2531 /// bottom.
2532 ///
2533 /// ### Return value
2534 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2535 /// information.
2536 ///
2537 /// ### Thread safety
2538 /// This function should be called on the thread that created the
2539 /// text.
2540 ///
2541 /// ### Availability
2542 /// This function is available since SDL_ttf 3.0.0.
2543 ///
2544 /// ### See also
2545 /// - [`TTF_CreateRendererTextEngine`]
2546 /// - [`TTF_CreateText`]
2547 pub fn TTF_DrawRendererText(
2548 text: *mut TTF_Text,
2549 x: ::core::ffi::c_float,
2550 y: ::core::ffi::c_float,
2551 ) -> ::core::primitive::bool;
2552}
2553
2554extern "C" {
2555 /// Destroy a text engine created for drawing text on an SDL renderer.
2556 ///
2557 /// All text created by this engine should be destroyed before calling this
2558 /// function.
2559 ///
2560 /// ### Parameters
2561 /// - `engine`: a [`TTF_TextEngine`] object created with
2562 /// [`TTF_CreateRendererTextEngine()`].
2563 ///
2564 /// ### Thread safety
2565 /// This function should be called on the thread that created the
2566 /// engine.
2567 ///
2568 /// ### Availability
2569 /// This function is available since SDL_ttf 3.0.0.
2570 ///
2571 /// ### See also
2572 /// - [`TTF_CreateRendererTextEngine`]
2573 pub fn TTF_DestroyRendererTextEngine(engine: *mut TTF_TextEngine);
2574}
2575
2576extern "C" {
2577 /// Create a text engine for drawing text with the SDL GPU API.
2578 ///
2579 /// ### Parameters
2580 /// - `device`: the [`SDL_GPUDevice`] to use for creating textures and drawing
2581 /// text.
2582 ///
2583 /// ### Return value
2584 /// Returns a [`TTF_TextEngine`] object or NULL on failure; call [`SDL_GetError()`]
2585 /// for more information.
2586 ///
2587 /// ### Thread safety
2588 /// This function should be called on the thread that created the
2589 /// device.
2590 ///
2591 /// ### Availability
2592 /// This function is available since SDL_ttf 3.0.0.
2593 ///
2594 /// ### See also
2595 /// - [`TTF_CreateGPUTextEngineWithProperties`]
2596 /// - [`TTF_DestroyGPUTextEngine`]
2597 /// - [`TTF_GetGPUTextDrawData`]
2598 pub fn TTF_CreateGPUTextEngine(device: *mut SDL_GPUDevice) -> *mut TTF_TextEngine;
2599}
2600
2601extern "C" {
2602 /// Create a text engine for drawing text with the SDL GPU API, with the
2603 /// specified properties.
2604 ///
2605 /// These are the supported properties:
2606 ///
2607 /// - [`TTF_PROP_GPU_TEXT_ENGINE_DEVICE`]\: the [`SDL_GPUDevice`] to use for creating
2608 /// textures and drawing text.
2609 /// - [`TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`]\: the size of the texture
2610 /// atlas
2611 ///
2612 /// ### Parameters
2613 /// - `props`: the properties to use.
2614 ///
2615 /// ### Return value
2616 /// Returns a [`TTF_TextEngine`] object or NULL on failure; call [`SDL_GetError()`]
2617 /// for more information.
2618 ///
2619 /// ### Thread safety
2620 /// This function should be called on the thread that created the
2621 /// device.
2622 ///
2623 /// ### Availability
2624 /// This function is available since SDL_ttf 3.0.0.
2625 ///
2626 /// ### See also
2627 /// - [`TTF_CreateGPUTextEngine`]
2628 /// - [`TTF_DestroyGPUTextEngine`]
2629 /// - [`TTF_GetGPUTextDrawData`]
2630 pub fn TTF_CreateGPUTextEngineWithProperties(props: SDL_PropertiesID) -> *mut TTF_TextEngine;
2631}
2632
2633pub const TTF_PROP_GPU_TEXT_ENGINE_DEVICE: *const ::core::ffi::c_char =
2634 c"SDL_ttf.gpu_text_engine.create.device".as_ptr();
2635
2636pub const TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE: *const ::core::ffi::c_char =
2637 c"SDL_ttf.gpu_text_engine.create.atlas_texture_size".as_ptr();
2638
2639/// Draw sequence returned by [`TTF_GetGPUTextDrawData`]
2640///
2641/// ### Availability
2642/// This struct is available since SDL_ttf 3.0.0.
2643///
2644/// ### See also
2645/// - [`TTF_GetGPUTextDrawData`]
2646#[repr(C)]
2647#[cfg_attr(feature = "debug-impls", derive(Debug))]
2648pub struct TTF_GPUAtlasDrawSequence {
2649 /// Texture atlas that stores the glyphs
2650 pub atlas_texture: *mut SDL_GPUTexture,
2651 /// An array of vertex positions
2652 pub xy: *mut SDL_FPoint,
2653 /// An array of normalized texture coordinates for each vertex
2654 pub uv: *mut SDL_FPoint,
2655 /// Number of vertices
2656 pub num_vertices: ::core::ffi::c_int,
2657 /// An array of indices into the 'vertices' arrays
2658 pub indices: *mut ::core::ffi::c_int,
2659 /// Number of indices
2660 pub num_indices: ::core::ffi::c_int,
2661 /// The image type of this draw sequence
2662 pub image_type: TTF_ImageType,
2663 /// The next sequence (will be NULL in case of the last sequence)
2664 pub next: *mut TTF_GPUAtlasDrawSequence,
2665}
2666
2667impl ::core::default::Default for TTF_GPUAtlasDrawSequence {
2668 /// Initialize all fields to zero
2669 #[inline(always)]
2670 fn default() -> Self {
2671 unsafe { ::core::mem::MaybeUninit::<Self>::zeroed().assume_init() }
2672 }
2673}
2674
2675extern "C" {
2676 /// Get the geometry data needed for drawing the text.
2677 ///
2678 /// `text` must have been created using a [`TTF_TextEngine`] from
2679 /// [`TTF_CreateGPUTextEngine()`].
2680 ///
2681 /// The positive X-axis is taken towards the right and the positive Y-axis is
2682 /// taken upwards for both the vertex and the texture coordinates, i.e, it
2683 /// follows the same convention used by the SDL_GPU API. If you want to use a
2684 /// different coordinate system you will need to transform the vertices
2685 /// yourself.
2686 ///
2687 /// If the text looks blocky use linear filtering.
2688 ///
2689 /// ### Parameters
2690 /// - `text`: the text to draw.
2691 ///
2692 /// ### Return value
2693 /// Returns a NULL terminated linked list of [`TTF_GPUAtlasDrawSequence`] objects
2694 /// or NULL if the passed text is empty or in case of failure; call
2695 /// [`SDL_GetError()`] for more information.
2696 ///
2697 /// ### Thread safety
2698 /// This function should be called on the thread that created the
2699 /// text.
2700 ///
2701 /// ### Availability
2702 /// This function is available since SDL_ttf 3.0.0.
2703 ///
2704 /// ### See also
2705 /// - [`TTF_CreateGPUTextEngine`]
2706 /// - [`TTF_CreateText`]
2707 pub fn TTF_GetGPUTextDrawData(text: *mut TTF_Text) -> *mut TTF_GPUAtlasDrawSequence;
2708}
2709
2710extern "C" {
2711 /// Destroy a text engine created for drawing text with the SDL GPU API.
2712 ///
2713 /// All text created by this engine should be destroyed before calling this
2714 /// function.
2715 ///
2716 /// ### Parameters
2717 /// - `engine`: a [`TTF_TextEngine`] object created with
2718 /// [`TTF_CreateGPUTextEngine()`].
2719 ///
2720 /// ### Thread safety
2721 /// This function should be called on the thread that created the
2722 /// engine.
2723 ///
2724 /// ### Availability
2725 /// This function is available since SDL_ttf 3.0.0.
2726 ///
2727 /// ### See also
2728 /// - [`TTF_CreateGPUTextEngine`]
2729 pub fn TTF_DestroyGPUTextEngine(engine: *mut TTF_TextEngine);
2730}
2731
2732/// The winding order of the vertices returned by [`TTF_GetGPUTextDrawData`]
2733///
2734/// ### Availability
2735/// This enum is available since SDL_ttf 3.0.0.
2736///
2737/// ### Known values (`sdl3-sys`)
2738/// | Associated constant | Global constant | Description |
2739/// | ------------------- | --------------- | ----------- |
2740/// | [`INVALID`](TTF_GPUTextEngineWinding::INVALID) | [`TTF_GPU_TEXTENGINE_WINDING_INVALID`] | |
2741/// | [`CLOCKWISE`](TTF_GPUTextEngineWinding::CLOCKWISE) | [`TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE`] | |
2742/// | [`COUNTER_CLOCKWISE`](TTF_GPUTextEngineWinding::COUNTER_CLOCKWISE) | [`TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE`] | |
2743#[repr(transparent)]
2744#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
2745pub struct TTF_GPUTextEngineWinding(pub ::core::ffi::c_int);
2746
2747impl From<TTF_GPUTextEngineWinding> for ::core::ffi::c_int {
2748 #[inline(always)]
2749 fn from(value: TTF_GPUTextEngineWinding) -> Self {
2750 value.0
2751 }
2752}
2753
2754#[cfg(feature = "debug-impls")]
2755impl ::core::fmt::Debug for TTF_GPUTextEngineWinding {
2756 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
2757 #[allow(unreachable_patterns)]
2758 f.write_str(match *self {
2759 Self::INVALID => "TTF_GPU_TEXTENGINE_WINDING_INVALID",
2760 Self::CLOCKWISE => "TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE",
2761 Self::COUNTER_CLOCKWISE => "TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE",
2762
2763 _ => return write!(f, "TTF_GPUTextEngineWinding({})", self.0),
2764 })
2765 }
2766}
2767
2768impl TTF_GPUTextEngineWinding {
2769 pub const INVALID: Self = Self(-1_i32);
2770 pub const CLOCKWISE: Self = Self(0_i32);
2771 pub const COUNTER_CLOCKWISE: Self = Self(1_i32);
2772}
2773
2774pub const TTF_GPU_TEXTENGINE_WINDING_INVALID: TTF_GPUTextEngineWinding =
2775 TTF_GPUTextEngineWinding::INVALID;
2776pub const TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE: TTF_GPUTextEngineWinding =
2777 TTF_GPUTextEngineWinding::CLOCKWISE;
2778pub const TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE: TTF_GPUTextEngineWinding =
2779 TTF_GPUTextEngineWinding::COUNTER_CLOCKWISE;
2780
2781extern "C" {
2782 /// Sets the winding order of the vertices returned by [`TTF_GetGPUTextDrawData`]
2783 /// for a particular GPU text engine.
2784 ///
2785 /// ### Parameters
2786 /// - `engine`: a [`TTF_TextEngine`] object created with
2787 /// [`TTF_CreateGPUTextEngine()`].
2788 /// - `winding`: the new winding order option.
2789 ///
2790 /// ### Thread safety
2791 /// This function should be called on the thread that created the
2792 /// engine.
2793 ///
2794 /// ### Availability
2795 /// This function is available since SDL_ttf 3.0.0.
2796 ///
2797 /// ### See also
2798 /// - [`TTF_GetGPUTextEngineWinding`]
2799 pub fn TTF_SetGPUTextEngineWinding(
2800 engine: *mut TTF_TextEngine,
2801 winding: TTF_GPUTextEngineWinding,
2802 );
2803}
2804
2805extern "C" {
2806 /// Get the winding order of the vertices returned by [`TTF_GetGPUTextDrawData`]
2807 /// for a particular GPU text engine
2808 ///
2809 /// ### Parameters
2810 /// - `engine`: a [`TTF_TextEngine`] object created with
2811 /// [`TTF_CreateGPUTextEngine()`].
2812 ///
2813 /// ### Return value
2814 /// Returns the winding order used by the GPU text engine or
2815 /// [`TTF_GPU_TEXTENGINE_WINDING_INVALID`] in case of error.
2816 ///
2817 /// ### Thread safety
2818 /// This function should be called on the thread that created the
2819 /// engine.
2820 ///
2821 /// ### Availability
2822 /// This function is available since SDL_ttf 3.0.0.
2823 ///
2824 /// ### See also
2825 /// - [`TTF_SetGPUTextEngineWinding`]
2826 pub fn TTF_GetGPUTextEngineWinding(engine: *const TTF_TextEngine) -> TTF_GPUTextEngineWinding;
2827}
2828
2829extern "C" {
2830 /// Create a text object from UTF-8 text and a text engine.
2831 ///
2832 /// ### Parameters
2833 /// - `engine`: the text engine to use when creating the text object, may be
2834 /// NULL.
2835 /// - `font`: the font to render with.
2836 /// - `text`: the text to use, in UTF-8 encoding.
2837 /// - `length`: the length of the text, in bytes, or 0 for null terminated
2838 /// text.
2839 ///
2840 /// ### Return value
2841 /// Returns a [`TTF_Text`] object or NULL on failure; call [`SDL_GetError()`] for more
2842 /// information.
2843 ///
2844 /// ### Thread safety
2845 /// This function should be called on the thread that created the
2846 /// font and text engine.
2847 ///
2848 /// ### Availability
2849 /// This function is available since SDL_ttf 3.0.0.
2850 ///
2851 /// ### See also
2852 /// - [`TTF_DestroyText`]
2853 pub fn TTF_CreateText(
2854 engine: *mut TTF_TextEngine,
2855 font: *mut TTF_Font,
2856 text: *const ::core::ffi::c_char,
2857 length: ::core::primitive::usize,
2858 ) -> *mut TTF_Text;
2859}
2860
2861extern "C" {
2862 /// Get the properties associated with a text object.
2863 ///
2864 /// ### Parameters
2865 /// - `text`: the [`TTF_Text`] to query.
2866 ///
2867 /// ### Return value
2868 /// Returns a valid property ID on success or 0 on failure; call
2869 /// [`SDL_GetError()`] for more information.
2870 ///
2871 /// ### Thread safety
2872 /// This function should be called on the thread that created the
2873 /// text.
2874 ///
2875 /// ### Availability
2876 /// This function is available since SDL_ttf 3.0.0.
2877 pub fn TTF_GetTextProperties(text: *mut TTF_Text) -> SDL_PropertiesID;
2878}
2879
2880extern "C" {
2881 /// Set the text engine used by a text object.
2882 ///
2883 /// This function may cause the internal text representation to be rebuilt.
2884 ///
2885 /// ### Parameters
2886 /// - `text`: the [`TTF_Text`] to modify.
2887 /// - `engine`: the text engine to use for drawing.
2888 ///
2889 /// ### Return value
2890 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2891 /// information.
2892 ///
2893 /// ### Thread safety
2894 /// This function should be called on the thread that created the
2895 /// text.
2896 ///
2897 /// ### Availability
2898 /// This function is available since SDL_ttf 3.0.0.
2899 ///
2900 /// ### See also
2901 /// - [`TTF_GetTextEngine`]
2902 pub fn TTF_SetTextEngine(
2903 text: *mut TTF_Text,
2904 engine: *mut TTF_TextEngine,
2905 ) -> ::core::primitive::bool;
2906}
2907
2908extern "C" {
2909 /// Get the text engine used by a text object.
2910 ///
2911 /// ### Parameters
2912 /// - `text`: the [`TTF_Text`] to query.
2913 ///
2914 /// ### Return value
2915 /// Returns the [`TTF_TextEngine`] used by the text on success or NULL on failure;
2916 /// call [`SDL_GetError()`] for more information.
2917 ///
2918 /// ### Thread safety
2919 /// This function should be called on the thread that created the
2920 /// text.
2921 ///
2922 /// ### Availability
2923 /// This function is available since SDL_ttf 3.0.0.
2924 ///
2925 /// ### See also
2926 /// - [`TTF_SetTextEngine`]
2927 pub fn TTF_GetTextEngine(text: *mut TTF_Text) -> *mut TTF_TextEngine;
2928}
2929
2930extern "C" {
2931 /// Set the font used by a text object.
2932 ///
2933 /// When a text object has a font, any changes to the font will automatically
2934 /// regenerate the text. If you set the font to NULL, the text will continue to
2935 /// render but changes to the font will no longer affect the text.
2936 ///
2937 /// This function may cause the internal text representation to be rebuilt.
2938 ///
2939 /// ### Parameters
2940 /// - `text`: the [`TTF_Text`] to modify.
2941 /// - `font`: the font to use, may be NULL.
2942 ///
2943 /// ### Return value
2944 /// Returns false if the text pointer is null; otherwise, true. call
2945 /// [`SDL_GetError()`] for more information.
2946 ///
2947 /// ### Thread safety
2948 /// This function should be called on the thread that created the
2949 /// text.
2950 ///
2951 /// ### Availability
2952 /// This function is available since SDL_ttf 3.0.0.
2953 ///
2954 /// ### See also
2955 /// - [`TTF_GetTextFont`]
2956 pub fn TTF_SetTextFont(text: *mut TTF_Text, font: *mut TTF_Font) -> ::core::primitive::bool;
2957}
2958
2959extern "C" {
2960 /// Get the font used by a text object.
2961 ///
2962 /// ### Parameters
2963 /// - `text`: the [`TTF_Text`] to query.
2964 ///
2965 /// ### Return value
2966 /// Returns the [`TTF_Font`] used by the text on success or NULL on failure; call
2967 /// [`SDL_GetError()`] for more information.
2968 ///
2969 /// ### Thread safety
2970 /// This function should be called on the thread that created the
2971 /// text.
2972 ///
2973 /// ### Availability
2974 /// This function is available since SDL_ttf 3.0.0.
2975 ///
2976 /// ### See also
2977 /// - [`TTF_SetTextFont`]
2978 pub fn TTF_GetTextFont(text: *mut TTF_Text) -> *mut TTF_Font;
2979}
2980
2981extern "C" {
2982 /// Set the direction to be used for text shaping a text object.
2983 ///
2984 /// This function only supports left-to-right text shaping if SDL_ttf was not
2985 /// built with HarfBuzz support.
2986 ///
2987 /// ### Parameters
2988 /// - `text`: the text to modify.
2989 /// - `direction`: the new direction for text to flow.
2990 ///
2991 /// ### Return value
2992 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2993 /// information.
2994 ///
2995 /// ### Thread safety
2996 /// This function should be called on the thread that created the
2997 /// text.
2998 ///
2999 /// ### Availability
3000 /// This function is available since SDL_ttf 3.0.0.
3001 pub fn TTF_SetTextDirection(
3002 text: *mut TTF_Text,
3003 direction: TTF_Direction,
3004 ) -> ::core::primitive::bool;
3005}
3006
3007extern "C" {
3008 /// Get the direction to be used for text shaping a text object.
3009 ///
3010 /// This defaults to the direction of the font used by the text object.
3011 ///
3012 /// ### Parameters
3013 /// - `text`: the text to query.
3014 ///
3015 /// ### Return value
3016 /// Returns the direction to be used for text shaping.
3017 ///
3018 /// ### Thread safety
3019 /// This function should be called on the thread that created the
3020 /// text.
3021 ///
3022 /// ### Availability
3023 /// This function is available since SDL_ttf 3.0.0.
3024 pub fn TTF_GetTextDirection(text: *mut TTF_Text) -> TTF_Direction;
3025}
3026
3027extern "C" {
3028 /// Set the script to be used for text shaping a text object.
3029 ///
3030 /// This returns false if SDL_ttf isn't built with HarfBuzz support.
3031 ///
3032 /// ### Parameters
3033 /// - `text`: the text to modify.
3034 /// - `script`: an
3035 /// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
3036 /// .
3037 ///
3038 /// ### Return value
3039 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3040 /// information.
3041 ///
3042 /// ### Thread safety
3043 /// This function should be called on the thread that created the
3044 /// text.
3045 ///
3046 /// ### Availability
3047 /// This function is available since SDL_ttf 3.0.0.
3048 ///
3049 /// ### See also
3050 /// - [`TTF_StringToTag`]
3051 pub fn TTF_SetTextScript(text: *mut TTF_Text, script: Uint32) -> ::core::primitive::bool;
3052}
3053
3054extern "C" {
3055 /// Get the script used for text shaping a text object.
3056 ///
3057 /// This defaults to the script of the font used by the text object.
3058 ///
3059 /// ### Parameters
3060 /// - `text`: the text to query.
3061 ///
3062 /// ### Return value
3063 /// Returns an
3064 /// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
3065 /// or 0 if a script hasn't been set on either the text object or the
3066 /// font.
3067 ///
3068 /// ### Thread safety
3069 /// This function should be called on the thread that created the
3070 /// text.
3071 ///
3072 /// ### Availability
3073 /// This function is available since SDL_ttf 3.0.0.
3074 ///
3075 /// ### See also
3076 /// - [`TTF_TagToString`]
3077 pub fn TTF_GetTextScript(text: *mut TTF_Text) -> Uint32;
3078}
3079
3080extern "C" {
3081 /// Set the color of a text object.
3082 ///
3083 /// The default text color is white (255, 255, 255, 255).
3084 ///
3085 /// ### Parameters
3086 /// - `text`: the [`TTF_Text`] to modify.
3087 /// - `r`: the red color value in the range of 0-255.
3088 /// - `g`: the green color value in the range of 0-255.
3089 /// - `b`: the blue color value in the range of 0-255.
3090 /// - `a`: the alpha value in the range of 0-255.
3091 ///
3092 /// ### Return value
3093 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3094 /// information.
3095 ///
3096 /// ### Thread safety
3097 /// This function should be called on the thread that created the
3098 /// text.
3099 ///
3100 /// ### Availability
3101 /// This function is available since SDL_ttf 3.0.0.
3102 ///
3103 /// ### See also
3104 /// - [`TTF_GetTextColor`]
3105 /// - [`TTF_SetTextColorFloat`]
3106 pub fn TTF_SetTextColor(
3107 text: *mut TTF_Text,
3108 r: Uint8,
3109 g: Uint8,
3110 b: Uint8,
3111 a: Uint8,
3112 ) -> ::core::primitive::bool;
3113}
3114
3115extern "C" {
3116 /// Set the color of a text object.
3117 ///
3118 /// The default text color is white (1.0f, 1.0f, 1.0f, 1.0f).
3119 ///
3120 /// ### Parameters
3121 /// - `text`: the [`TTF_Text`] to modify.
3122 /// - `r`: the red color value, normally in the range of 0-1.
3123 /// - `g`: the green color value, normally in the range of 0-1.
3124 /// - `b`: the blue color value, normally in the range of 0-1.
3125 /// - `a`: the alpha value in the range of 0-1.
3126 ///
3127 /// ### Return value
3128 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3129 /// information.
3130 ///
3131 /// ### Thread safety
3132 /// This function should be called on the thread that created the
3133 /// text.
3134 ///
3135 /// ### Availability
3136 /// This function is available since SDL_ttf 3.0.0.
3137 ///
3138 /// ### See also
3139 /// - [`TTF_GetTextColorFloat`]
3140 /// - [`TTF_SetTextColor`]
3141 pub fn TTF_SetTextColorFloat(
3142 text: *mut TTF_Text,
3143 r: ::core::ffi::c_float,
3144 g: ::core::ffi::c_float,
3145 b: ::core::ffi::c_float,
3146 a: ::core::ffi::c_float,
3147 ) -> ::core::primitive::bool;
3148}
3149
3150extern "C" {
3151 /// Get the color of a text object.
3152 ///
3153 /// ### Parameters
3154 /// - `text`: the [`TTF_Text`] to query.
3155 /// - `r`: a pointer filled in with the red color value in the range of
3156 /// 0-255, may be NULL.
3157 /// - `g`: a pointer filled in with the green color value in the range of
3158 /// 0-255, may be NULL.
3159 /// - `b`: a pointer filled in with the blue color value in the range of
3160 /// 0-255, may be NULL.
3161 /// - `a`: a pointer filled in with the alpha value in the range of 0-255,
3162 /// may be NULL.
3163 ///
3164 /// ### Return value
3165 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3166 /// information.
3167 ///
3168 /// ### Thread safety
3169 /// This function should be called on the thread that created the
3170 /// text.
3171 ///
3172 /// ### Availability
3173 /// This function is available since SDL_ttf 3.0.0.
3174 ///
3175 /// ### See also
3176 /// - [`TTF_GetTextColorFloat`]
3177 /// - [`TTF_SetTextColor`]
3178 pub fn TTF_GetTextColor(
3179 text: *mut TTF_Text,
3180 r: *mut Uint8,
3181 g: *mut Uint8,
3182 b: *mut Uint8,
3183 a: *mut Uint8,
3184 ) -> ::core::primitive::bool;
3185}
3186
3187extern "C" {
3188 /// Get the color of a text object.
3189 ///
3190 /// ### Parameters
3191 /// - `text`: the [`TTF_Text`] to query.
3192 /// - `r`: a pointer filled in with the red color value, normally in the
3193 /// range of 0-1, may be NULL.
3194 /// - `g`: a pointer filled in with the green color value, normally in the
3195 /// range of 0-1, may be NULL.
3196 /// - `b`: a pointer filled in with the blue color value, normally in the
3197 /// range of 0-1, may be NULL.
3198 /// - `a`: a pointer filled in with the alpha value in the range of 0-1, may
3199 /// be NULL.
3200 ///
3201 /// ### Return value
3202 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3203 /// information.
3204 ///
3205 /// ### Thread safety
3206 /// This function should be called on the thread that created the
3207 /// text.
3208 ///
3209 /// ### Availability
3210 /// This function is available since SDL_ttf 3.0.0.
3211 ///
3212 /// ### See also
3213 /// - [`TTF_GetTextColor`]
3214 /// - [`TTF_SetTextColorFloat`]
3215 pub fn TTF_GetTextColorFloat(
3216 text: *mut TTF_Text,
3217 r: *mut ::core::ffi::c_float,
3218 g: *mut ::core::ffi::c_float,
3219 b: *mut ::core::ffi::c_float,
3220 a: *mut ::core::ffi::c_float,
3221 ) -> ::core::primitive::bool;
3222}
3223
3224extern "C" {
3225 /// Set the position of a text object.
3226 ///
3227 /// This can be used to position multiple text objects within a single wrapping
3228 /// text area.
3229 ///
3230 /// This function may cause the internal text representation to be rebuilt.
3231 ///
3232 /// ### Parameters
3233 /// - `text`: the [`TTF_Text`] to modify.
3234 /// - `x`: the x offset of the upper left corner of this text in pixels.
3235 /// - `y`: the y offset of the upper left corner of this text in pixels.
3236 ///
3237 /// ### Thread safety
3238 /// This function should be called on the thread that created the
3239 /// text.
3240 ///
3241 /// ### Availability
3242 /// This function is available since SDL_ttf 3.0.0.
3243 ///
3244 /// ### See also
3245 /// - [`TTF_GetTextPosition`]
3246 pub fn TTF_SetTextPosition(
3247 text: *mut TTF_Text,
3248 x: ::core::ffi::c_int,
3249 y: ::core::ffi::c_int,
3250 ) -> ::core::primitive::bool;
3251}
3252
3253extern "C" {
3254 /// Get the position of a text object.
3255 ///
3256 /// ### Parameters
3257 /// - `text`: the [`TTF_Text`] to query.
3258 /// - `x`: a pointer filled in with the x offset of the upper left corner of
3259 /// this text in pixels, may be NULL.
3260 /// - `y`: a pointer filled in with the y offset of the upper left corner of
3261 /// this text in pixels, may be NULL.
3262 ///
3263 /// ### Thread safety
3264 /// This function should be called on the thread that created the
3265 /// text.
3266 ///
3267 /// ### Availability
3268 /// This function is available since SDL_ttf 3.0.0.
3269 ///
3270 /// ### See also
3271 /// - [`TTF_SetTextPosition`]
3272 pub fn TTF_GetTextPosition(
3273 text: *mut TTF_Text,
3274 x: *mut ::core::ffi::c_int,
3275 y: *mut ::core::ffi::c_int,
3276 ) -> ::core::primitive::bool;
3277}
3278
3279extern "C" {
3280 /// Set whether wrapping is enabled on a text object.
3281 ///
3282 /// This function may cause the internal text representation to be rebuilt.
3283 ///
3284 /// ### Parameters
3285 /// - `text`: the [`TTF_Text`] to modify.
3286 /// - `wrap_width`: the maximum width in pixels, 0 to wrap on newline
3287 /// characters.
3288 ///
3289 /// ### Return value
3290 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3291 /// information.
3292 ///
3293 /// ### Thread safety
3294 /// This function should be called on the thread that created the
3295 /// text.
3296 ///
3297 /// ### Availability
3298 /// This function is available since SDL_ttf 3.0.0.
3299 ///
3300 /// ### See also
3301 /// - [`TTF_GetTextWrapWidth`]
3302 pub fn TTF_SetTextWrapWidth(
3303 text: *mut TTF_Text,
3304 wrap_width: ::core::ffi::c_int,
3305 ) -> ::core::primitive::bool;
3306}
3307
3308extern "C" {
3309 /// Get whether wrapping is enabled on a text object.
3310 ///
3311 /// ### Parameters
3312 /// - `text`: the [`TTF_Text`] to query.
3313 /// - `wrap_width`: a pointer filled in with the maximum width in pixels or 0
3314 /// if the text is being wrapped on newline characters.
3315 ///
3316 /// ### Return value
3317 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3318 /// information.
3319 ///
3320 /// ### Thread safety
3321 /// This function should be called on the thread that created the
3322 /// text.
3323 ///
3324 /// ### Availability
3325 /// This function is available since SDL_ttf 3.0.0.
3326 ///
3327 /// ### See also
3328 /// - [`TTF_SetTextWrapWidth`]
3329 pub fn TTF_GetTextWrapWidth(
3330 text: *mut TTF_Text,
3331 wrap_width: *mut ::core::ffi::c_int,
3332 ) -> ::core::primitive::bool;
3333}
3334
3335extern "C" {
3336 /// Set whether whitespace should be visible when wrapping a text object.
3337 ///
3338 /// If the whitespace is visible, it will take up space for purposes of
3339 /// alignment and wrapping. This is good for editing, but looks better when
3340 /// centered or aligned if whitespace around line wrapping is hidden. This
3341 /// defaults false.
3342 ///
3343 /// This function may cause the internal text representation to be rebuilt.
3344 ///
3345 /// ### Parameters
3346 /// - `text`: the [`TTF_Text`] to modify.
3347 /// - `visible`: true to show whitespace when wrapping text, false to hide
3348 /// it.
3349 ///
3350 /// ### Return value
3351 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3352 /// information.
3353 ///
3354 /// ### Thread safety
3355 /// This function should be called on the thread that created the
3356 /// text.
3357 ///
3358 /// ### Availability
3359 /// This function is available since SDL_ttf 3.0.0.
3360 ///
3361 /// ### See also
3362 /// - [`TTF_TextWrapWhitespaceVisible`]
3363 pub fn TTF_SetTextWrapWhitespaceVisible(
3364 text: *mut TTF_Text,
3365 visible: ::core::primitive::bool,
3366 ) -> ::core::primitive::bool;
3367}
3368
3369extern "C" {
3370 /// Return whether whitespace is shown when wrapping a text object.
3371 ///
3372 /// ### Parameters
3373 /// - `text`: the [`TTF_Text`] to query.
3374 ///
3375 /// ### Return value
3376 /// Returns true if whitespace is shown when wrapping text, or false
3377 /// otherwise.
3378 ///
3379 /// ### Thread safety
3380 /// This function should be called on the thread that created the
3381 /// text.
3382 ///
3383 /// ### Availability
3384 /// This function is available since SDL_ttf 3.0.0.
3385 ///
3386 /// ### See also
3387 /// - [`TTF_SetTextWrapWhitespaceVisible`]
3388 pub fn TTF_TextWrapWhitespaceVisible(text: *mut TTF_Text) -> ::core::primitive::bool;
3389}
3390
3391extern "C" {
3392 /// Set the UTF-8 text used by a text object.
3393 ///
3394 /// This function may cause the internal text representation to be rebuilt.
3395 ///
3396 /// ### Parameters
3397 /// - `text`: the [`TTF_Text`] to modify.
3398 /// - `string`: the UTF-8 text to use, may be NULL.
3399 /// - `length`: the length of the text, in bytes, or 0 for null terminated
3400 /// text.
3401 ///
3402 /// ### Return value
3403 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3404 /// information.
3405 ///
3406 /// ### Thread safety
3407 /// This function should be called on the thread that created the
3408 /// text.
3409 ///
3410 /// ### Availability
3411 /// This function is available since SDL_ttf 3.0.0.
3412 ///
3413 /// ### See also
3414 /// - [`TTF_AppendTextString`]
3415 /// - [`TTF_DeleteTextString`]
3416 /// - [`TTF_InsertTextString`]
3417 pub fn TTF_SetTextString(
3418 text: *mut TTF_Text,
3419 string: *const ::core::ffi::c_char,
3420 length: ::core::primitive::usize,
3421 ) -> ::core::primitive::bool;
3422}
3423
3424extern "C" {
3425 /// Insert UTF-8 text into a text object.
3426 ///
3427 /// This function may cause the internal text representation to be rebuilt.
3428 ///
3429 /// ### Parameters
3430 /// - `text`: the [`TTF_Text`] to modify.
3431 /// - `offset`: the offset, in bytes, from the beginning of the string if >=
3432 /// 0, the offset from the end of the string if < 0. Note that
3433 /// this does not do UTF-8 validation, so you should only insert
3434 /// at UTF-8 sequence boundaries.
3435 /// - `string`: the UTF-8 text to insert.
3436 /// - `length`: the length of the text, in bytes, or 0 for null terminated
3437 /// text.
3438 ///
3439 /// ### Return value
3440 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3441 /// information.
3442 ///
3443 /// ### Thread safety
3444 /// This function should be called on the thread that created the
3445 /// text.
3446 ///
3447 /// ### Availability
3448 /// This function is available since SDL_ttf 3.0.0.
3449 ///
3450 /// ### See also
3451 /// - [`TTF_AppendTextString`]
3452 /// - [`TTF_DeleteTextString`]
3453 /// - [`TTF_SetTextString`]
3454 pub fn TTF_InsertTextString(
3455 text: *mut TTF_Text,
3456 offset: ::core::ffi::c_int,
3457 string: *const ::core::ffi::c_char,
3458 length: ::core::primitive::usize,
3459 ) -> ::core::primitive::bool;
3460}
3461
3462extern "C" {
3463 /// Append UTF-8 text to a text object.
3464 ///
3465 /// This function may cause the internal text representation to be rebuilt.
3466 ///
3467 /// ### Parameters
3468 /// - `text`: the [`TTF_Text`] to modify.
3469 /// - `string`: the UTF-8 text to insert.
3470 /// - `length`: the length of the text, in bytes, or 0 for null terminated
3471 /// text.
3472 ///
3473 /// ### Return value
3474 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3475 /// information.
3476 ///
3477 /// ### Thread safety
3478 /// This function should be called on the thread that created the
3479 /// text.
3480 ///
3481 /// ### Availability
3482 /// This function is available since SDL_ttf 3.0.0.
3483 ///
3484 /// ### See also
3485 /// - [`TTF_DeleteTextString`]
3486 /// - [`TTF_InsertTextString`]
3487 /// - [`TTF_SetTextString`]
3488 pub fn TTF_AppendTextString(
3489 text: *mut TTF_Text,
3490 string: *const ::core::ffi::c_char,
3491 length: ::core::primitive::usize,
3492 ) -> ::core::primitive::bool;
3493}
3494
3495extern "C" {
3496 /// Delete UTF-8 text from a text object.
3497 ///
3498 /// This function may cause the internal text representation to be rebuilt.
3499 ///
3500 /// ### Parameters
3501 /// - `text`: the [`TTF_Text`] to modify.
3502 /// - `offset`: the offset, in bytes, from the beginning of the string if >=
3503 /// 0, the offset from the end of the string if < 0. Note that
3504 /// this does not do UTF-8 validation, so you should only delete
3505 /// at UTF-8 sequence boundaries.
3506 /// - `length`: the length of text to delete, in bytes, or -1 for the
3507 /// remainder of the string.
3508 ///
3509 /// ### Return value
3510 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3511 /// information.
3512 ///
3513 /// ### Thread safety
3514 /// This function should be called on the thread that created the
3515 /// text.
3516 ///
3517 /// ### Availability
3518 /// This function is available since SDL_ttf 3.0.0.
3519 ///
3520 /// ### See also
3521 /// - [`TTF_AppendTextString`]
3522 /// - [`TTF_InsertTextString`]
3523 /// - [`TTF_SetTextString`]
3524 pub fn TTF_DeleteTextString(
3525 text: *mut TTF_Text,
3526 offset: ::core::ffi::c_int,
3527 length: ::core::ffi::c_int,
3528 ) -> ::core::primitive::bool;
3529}
3530
3531extern "C" {
3532 /// Get the size of a text object.
3533 ///
3534 /// The size of the text may change when the font or font style and size
3535 /// change.
3536 ///
3537 /// ### Parameters
3538 /// - `text`: the [`TTF_Text`] to query.
3539 /// - `w`: a pointer filled in with the width of the text, in pixels, may be
3540 /// NULL.
3541 /// - `h`: a pointer filled in with the height of the text, in pixels, may be
3542 /// NULL.
3543 ///
3544 /// ### Return value
3545 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3546 /// information.
3547 ///
3548 /// ### Thread safety
3549 /// This function should be called on the thread that created the
3550 /// text.
3551 ///
3552 /// ### Availability
3553 /// This function is available since SDL_ttf 3.0.0.
3554 pub fn TTF_GetTextSize(
3555 text: *mut TTF_Text,
3556 w: *mut ::core::ffi::c_int,
3557 h: *mut ::core::ffi::c_int,
3558 ) -> ::core::primitive::bool;
3559}
3560
3561/// Flags for [`TTF_SubString`]
3562///
3563/// ### Availability
3564/// This datatype is available since SDL_ttf 3.0.0.
3565///
3566/// ### See also
3567/// - [`TTF_SubString`]
3568///
3569/// ### Known values (`sdl3-sys`)
3570/// | Constant | Description |
3571/// | -------- | ----------- |
3572/// | [`TTF_SUBSTRING_DIRECTION_MASK`] | The mask for the flow direction for this substring |
3573/// | [`TTF_SUBSTRING_TEXT_START`] | This substring contains the beginning of the text |
3574/// | [`TTF_SUBSTRING_LINE_START`] | This substring contains the beginning of line `line_index` |
3575/// | [`TTF_SUBSTRING_LINE_END`] | This substring contains the end of line `line_index` |
3576/// | [`TTF_SUBSTRING_TEXT_END`] | This substring contains the end of the text |
3577pub type TTF_SubStringFlags = Uint32;
3578
3579/// The mask for the flow direction for this substring
3580pub const TTF_SUBSTRING_DIRECTION_MASK: TTF_SubStringFlags = (0x000000ff as TTF_SubStringFlags);
3581
3582/// This substring contains the beginning of the text
3583pub const TTF_SUBSTRING_TEXT_START: TTF_SubStringFlags = (0x00000100 as TTF_SubStringFlags);
3584
3585/// This substring contains the beginning of line `line_index`
3586pub const TTF_SUBSTRING_LINE_START: TTF_SubStringFlags = (0x00000200 as TTF_SubStringFlags);
3587
3588/// This substring contains the end of line `line_index`
3589pub const TTF_SUBSTRING_LINE_END: TTF_SubStringFlags = (0x00000400 as TTF_SubStringFlags);
3590
3591/// This substring contains the end of the text
3592pub const TTF_SUBSTRING_TEXT_END: TTF_SubStringFlags = (0x00000800 as TTF_SubStringFlags);
3593
3594/// The representation of a substring within text.
3595///
3596/// ### Availability
3597/// This struct is available since SDL_ttf 3.0.0.
3598///
3599/// ### See also
3600/// - [`TTF_GetNextTextSubString`]
3601/// - [`TTF_GetPreviousTextSubString`]
3602/// - [`TTF_GetTextSubString`]
3603/// - [`TTF_GetTextSubStringForLine`]
3604/// - [`TTF_GetTextSubStringForPoint`]
3605/// - [`TTF_GetTextSubStringsForRange`]
3606#[repr(C)]
3607#[derive(Clone, Copy)]
3608#[cfg_attr(feature = "debug-impls", derive(Debug))]
3609#[derive(Default)]
3610pub struct TTF_SubString {
3611 /// The flags for this substring
3612 pub flags: TTF_SubStringFlags,
3613 /// The byte offset from the beginning of the text
3614 pub offset: ::core::ffi::c_int,
3615 /// The byte length starting at the offset
3616 pub length: ::core::ffi::c_int,
3617 /// The index of the line that contains this substring
3618 pub line_index: ::core::ffi::c_int,
3619 /// The internal cluster index, used for quickly iterating
3620 pub cluster_index: ::core::ffi::c_int,
3621 /// The rectangle, relative to the top left of the text, containing the substring
3622 pub rect: SDL_Rect,
3623}
3624
3625extern "C" {
3626 /// Get the substring of a text object that surrounds a text offset.
3627 ///
3628 /// If `offset` is less than 0, this will return a zero length substring at the
3629 /// beginning of the text with the [`TTF_SUBSTRING_TEXT_START`] flag set. If
3630 /// `offset` is greater than or equal to the length of the text string, this
3631 /// will return a zero length substring at the end of the text with the
3632 /// [`TTF_SUBSTRING_TEXT_END`] flag set.
3633 ///
3634 /// ### Parameters
3635 /// - `text`: the [`TTF_Text`] to query.
3636 /// - `offset`: a byte offset into the text string.
3637 /// - `substring`: a pointer filled in with the substring containing the
3638 /// offset.
3639 ///
3640 /// ### Return value
3641 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3642 /// information.
3643 ///
3644 /// ### Thread safety
3645 /// This function should be called on the thread that created the
3646 /// text.
3647 ///
3648 /// ### Availability
3649 /// This function is available since SDL_ttf 3.0.0.
3650 pub fn TTF_GetTextSubString(
3651 text: *mut TTF_Text,
3652 offset: ::core::ffi::c_int,
3653 substring: *mut TTF_SubString,
3654 ) -> ::core::primitive::bool;
3655}
3656
3657extern "C" {
3658 /// Get the substring of a text object that contains the given line.
3659 ///
3660 /// If `line` is less than 0, this will return a zero length substring at the
3661 /// beginning of the text with the [`TTF_SUBSTRING_TEXT_START`] flag set. If `line`
3662 /// is greater than or equal to `text->num_lines` this will return a zero
3663 /// length substring at the end of the text with the [`TTF_SUBSTRING_TEXT_END`]
3664 /// flag set.
3665 ///
3666 /// ### Parameters
3667 /// - `text`: the [`TTF_Text`] to query.
3668 /// - `line`: a zero-based line index, in the range \[0 .. text->num_lines-1\].
3669 /// - `substring`: a pointer filled in with the substring containing the
3670 /// offset.
3671 ///
3672 /// ### Return value
3673 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3674 /// information.
3675 ///
3676 /// ### Thread safety
3677 /// This function should be called on the thread that created the
3678 /// text.
3679 ///
3680 /// ### Availability
3681 /// This function is available since SDL_ttf 3.0.0.
3682 pub fn TTF_GetTextSubStringForLine(
3683 text: *mut TTF_Text,
3684 line: ::core::ffi::c_int,
3685 substring: *mut TTF_SubString,
3686 ) -> ::core::primitive::bool;
3687}
3688
3689extern "C" {
3690 /// Get the substrings of a text object that contain a range of text.
3691 ///
3692 /// ### Parameters
3693 /// - `text`: the [`TTF_Text`] to query.
3694 /// - `offset`: a byte offset into the text string.
3695 /// - `length`: the length of the range being queried, in bytes, or -1 for
3696 /// the remainder of the string.
3697 /// - `count`: a pointer filled in with the number of substrings returned,
3698 /// may be NULL.
3699 ///
3700 /// ### Return value
3701 /// Returns a NULL terminated array of substring pointers or NULL on failure;
3702 /// call [`SDL_GetError()`] for more information. This is a single
3703 /// allocation that should be freed with [`SDL_free()`] when it is no
3704 /// longer needed.
3705 ///
3706 /// ### Thread safety
3707 /// This function should be called on the thread that created the
3708 /// text.
3709 ///
3710 /// ### Availability
3711 /// This function is available since SDL_ttf 3.0.0.
3712 pub fn TTF_GetTextSubStringsForRange(
3713 text: *mut TTF_Text,
3714 offset: ::core::ffi::c_int,
3715 length: ::core::ffi::c_int,
3716 count: *mut ::core::ffi::c_int,
3717 ) -> *mut *mut TTF_SubString;
3718}
3719
3720extern "C" {
3721 /// Get the portion of a text string that is closest to a point.
3722 ///
3723 /// This will return the closest substring of text to the given point.
3724 ///
3725 /// ### Parameters
3726 /// - `text`: the [`TTF_Text`] to query.
3727 /// - `x`: the x coordinate relative to the left side of the text, may be
3728 /// outside the bounds of the text area.
3729 /// - `y`: the y coordinate relative to the top side of the text, may be
3730 /// outside the bounds of the text area.
3731 /// - `substring`: a pointer filled in with the closest substring of text to
3732 /// the given point.
3733 ///
3734 /// ### Return value
3735 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3736 /// information.
3737 ///
3738 /// ### Thread safety
3739 /// This function should be called on the thread that created the
3740 /// text.
3741 ///
3742 /// ### Availability
3743 /// This function is available since SDL_ttf 3.0.0.
3744 pub fn TTF_GetTextSubStringForPoint(
3745 text: *mut TTF_Text,
3746 x: ::core::ffi::c_int,
3747 y: ::core::ffi::c_int,
3748 substring: *mut TTF_SubString,
3749 ) -> ::core::primitive::bool;
3750}
3751
3752extern "C" {
3753 /// Get the previous substring in a text object
3754 ///
3755 /// If called at the start of the text, this will return a zero length
3756 /// substring with the [`TTF_SUBSTRING_TEXT_START`] flag set.
3757 ///
3758 /// ### Parameters
3759 /// - `text`: the [`TTF_Text`] to query.
3760 /// - `substring`: the [`TTF_SubString`] to query.
3761 ///
3762 /// ### Return value
3763 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3764 /// information.
3765 ///
3766 /// ### Thread safety
3767 /// This function should be called on the thread that created the
3768 /// text.
3769 ///
3770 /// ### Availability
3771 /// This function is available since SDL_ttf 3.0.0.
3772 pub fn TTF_GetPreviousTextSubString(
3773 text: *mut TTF_Text,
3774 substring: *const TTF_SubString,
3775 previous: *mut TTF_SubString,
3776 ) -> ::core::primitive::bool;
3777}
3778
3779extern "C" {
3780 /// Get the next substring in a text object
3781 ///
3782 /// If called at the end of the text, this will return a zero length substring
3783 /// with the [`TTF_SUBSTRING_TEXT_END`] flag set.
3784 ///
3785 /// ### Parameters
3786 /// - `text`: the [`TTF_Text`] to query.
3787 /// - `substring`: the [`TTF_SubString`] to query.
3788 /// - `next`: a pointer filled in with the next substring.
3789 ///
3790 /// ### Return value
3791 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3792 /// information.
3793 ///
3794 /// ### Thread safety
3795 /// This function should be called on the thread that created the
3796 /// text.
3797 ///
3798 /// ### Availability
3799 /// This function is available since SDL_ttf 3.0.0.
3800 pub fn TTF_GetNextTextSubString(
3801 text: *mut TTF_Text,
3802 substring: *const TTF_SubString,
3803 next: *mut TTF_SubString,
3804 ) -> ::core::primitive::bool;
3805}
3806
3807extern "C" {
3808 /// Update the layout of a text object.
3809 ///
3810 /// This is automatically done when the layout is requested or the text is
3811 /// rendered, but you can call this if you need more control over the timing of
3812 /// when the layout and text engine representation are updated.
3813 ///
3814 /// ### Parameters
3815 /// - `text`: the [`TTF_Text`] to update.
3816 ///
3817 /// ### Return value
3818 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
3819 /// information.
3820 ///
3821 /// ### Thread safety
3822 /// This function should be called on the thread that created the
3823 /// text.
3824 ///
3825 /// ### Availability
3826 /// This function is available since SDL_ttf 3.0.0.
3827 pub fn TTF_UpdateText(text: *mut TTF_Text) -> ::core::primitive::bool;
3828}
3829
3830extern "C" {
3831 /// Destroy a text object created by a text engine.
3832 ///
3833 /// ### Parameters
3834 /// - `text`: the text to destroy.
3835 ///
3836 /// ### Thread safety
3837 /// This function should be called on the thread that created the
3838 /// text.
3839 ///
3840 /// ### Availability
3841 /// This function is available since SDL_ttf 3.0.0.
3842 ///
3843 /// ### See also
3844 /// - [`TTF_CreateText`]
3845 pub fn TTF_DestroyText(text: *mut TTF_Text);
3846}
3847
3848extern "C" {
3849 /// Dispose of a previously-created font.
3850 ///
3851 /// Call this when done with a font. This function will free any resources
3852 /// associated with it. It is safe to call this function on NULL, for example
3853 /// on the result of a failed call to [`TTF_OpenFont()`].
3854 ///
3855 /// The font is not valid after being passed to this function. String pointers
3856 /// from functions that return information on this font, such as
3857 /// [`TTF_GetFontFamilyName()`] and [`TTF_GetFontStyleName()`], are no longer valid
3858 /// after this call, as well.
3859 ///
3860 /// ### Parameters
3861 /// - `font`: the font to dispose of.
3862 ///
3863 /// ### Thread safety
3864 /// This function should not be called while any other thread is
3865 /// using the font.
3866 ///
3867 /// ### Availability
3868 /// This function is available since SDL_ttf 3.0.0.
3869 ///
3870 /// ### See also
3871 /// - [`TTF_OpenFont`]
3872 /// - [`TTF_OpenFontIO`]
3873 pub fn TTF_CloseFont(font: *mut TTF_Font);
3874}
3875
3876extern "C" {
3877 /// Deinitialize SDL_ttf.
3878 ///
3879 /// You must call this when done with the library, to free internal resources.
3880 /// It is safe to call this when the library isn't initialized, as it will just
3881 /// return immediately.
3882 ///
3883 /// Once you have as many quit calls as you have had successful calls to
3884 /// [`TTF_Init`], the library will actually deinitialize.
3885 ///
3886 /// Please note that this does not automatically close any fonts that are still
3887 /// open at the time of deinitialization, and it is possibly not safe to close
3888 /// them afterwards, as parts of the library will no longer be initialized to
3889 /// deal with it. A well-written program should call [`TTF_CloseFont()`] on any
3890 /// open fonts before calling this function!
3891 ///
3892 /// ### Thread safety
3893 /// It is safe to call this function from any thread.
3894 ///
3895 /// ### Availability
3896 /// This function is available since SDL_ttf 3.0.0.
3897 pub fn TTF_Quit();
3898}
3899
3900extern "C" {
3901 /// Check if SDL_ttf is initialized.
3902 ///
3903 /// This reports the number of times the library has been initialized by a call
3904 /// to [`TTF_Init()`], without a paired deinitialization request from [`TTF_Quit()`].
3905 ///
3906 /// In short: if it's greater than zero, the library is currently initialized
3907 /// and ready to work. If zero, it is not initialized.
3908 ///
3909 /// Despite the return value being a signed integer, this function should not
3910 /// return a negative number.
3911 ///
3912 /// ### Return value
3913 /// Returns the current number of initialization calls, that need to
3914 /// eventually be paired with this many calls to [`TTF_Quit()`].
3915 ///
3916 /// ### Thread safety
3917 /// It is safe to call this function from any thread.
3918 ///
3919 /// ### Availability
3920 /// This function is available since SDL_ttf 3.0.0.
3921 ///
3922 /// ### See also
3923 /// - [`TTF_Init`]
3924 /// - [`TTF_Quit`]
3925 pub fn TTF_WasInit() -> ::core::ffi::c_int;
3926}
3927
3928/// The internal structure containing font information.
3929///
3930/// Opaque data!
3931#[repr(C)]
3932pub struct TTF_Font {
3933 _opaque: [::core::primitive::u8; 0],
3934}
3935
3936/// Internal data for [`TTF_Text`]
3937///
3938/// ### Availability
3939/// This struct is available since SDL_ttf 3.0.0.
3940#[repr(C)]
3941pub struct TTF_TextData {
3942 _opaque: [::core::primitive::u8; 0],
3943}
3944
3945#[cfg(doc)]
3946use crate::everything::*;