1#region License
2/* SDL2# - C# Wrapper for SDL2
3 *
4 * Copyright (c) 2013-2021 Ethan Lee.
5 *
6 * This software is provided 'as-is', without any express or implied warranty.
7 * In no event will the authors be held liable for any damages arising from
8 * the use of this software.
9 *
10 * Permission is granted to anyone to use this software for any purpose,
11 * including commercial applications, and to alter it and redistribute it
12 * freely, subject to the following restrictions:
13 *
14 * 1. The origin of this software must not be misrepresented; you must not
15 * claim that you wrote the original software. If you use this software in a
16 * product, an acknowledgment in the product documentation would be
17 * appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be
20 * misrepresented as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 *
24 * Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
25 *
26 */
27#endregion
28
29#region Using Statements
30using System;
31using System.Runtime.InteropServices;
32#endregion
33
34namespace SDL2
35{
36 public static class SDL_ttf
37 {
38 #region SDL2# Variables
39
40 /* Used by DllImport to load the native library. */
41 private const string nativeLibName = "SDL2_ttf";
42
43 #endregion
44
45 #region SDL_ttf.h
46
47 /* Similar to the headers, this is the version we're expecting to be
48 * running with. You will likely want to check this somewhere in your
49 * program!
50 */
51 public const int SDL_TTF_MAJOR_VERSION = 2;
52 public const int SDL_TTF_MINOR_VERSION = 0;
53 public const int SDL_TTF_PATCHLEVEL = 16;
54
55 public const int UNICODE_BOM_NATIVE = 0xFEFF;
56 public const int UNICODE_BOM_SWAPPED = 0xFFFE;
57
58 public const int TTF_STYLE_NORMAL = 0x00;
59 public const int TTF_STYLE_BOLD = 0x01;
60 public const int TTF_STYLE_ITALIC = 0x02;
61 public const int TTF_STYLE_UNDERLINE = 0x04;
62 public const int TTF_STYLE_STRIKETHROUGH = 0x08;
63
64 public const int TTF_HINTING_NORMAL = 0;
65 public const int TTF_HINTING_LIGHT = 1;
66 public const int TTF_HINTING_MONO = 2;
67 public const int TTF_HINTING_NONE = 3;
68 public const int TTF_HINTING_LIGHT_SUBPIXEL = 4; /* >= 2.0.16 */
69
70 public static void SDL_TTF_VERSION(out SDL.SDL_version X)
71 {
72 X.major = SDL_TTF_MAJOR_VERSION;
73 X.minor = SDL_TTF_MINOR_VERSION;
74 X.patch = SDL_TTF_PATCHLEVEL;
75 }
76
77 [DllImport(nativeLibName, EntryPoint = "TTF_LinkedVersion", CallingConvention = CallingConvention.Cdecl)]
78 private static extern IntPtr INTERNAL_TTF_LinkedVersion();
79 public static SDL.SDL_version TTF_LinkedVersion()
80 {
81 SDL.SDL_version result;
82 IntPtr result_ptr = INTERNAL_TTF_LinkedVersion();
83 result = SDL.PtrToStructure<SDL.SDL_version>(
84 result_ptr
85 );
86 return result;
87 }
88
89 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
90 public static extern void TTF_ByteSwappedUNICODE(int swapped);
91
92 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
93 public static extern int TTF_Init();
94
95 /* IntPtr refers to a TTF_Font* */
96 [DllImport(nativeLibName, EntryPoint = "TTF_OpenFont", CallingConvention = CallingConvention.Cdecl)]
97 private static extern unsafe IntPtr INTERNAL_TTF_OpenFont(
98 byte* file,
99 int ptsize
100 );
101 public static unsafe IntPtr TTF_OpenFont(string file, int ptsize)
102 {
103 byte* utf8File = SDL.Utf8EncodeHeap(file);
104 IntPtr handle = INTERNAL_TTF_OpenFont(
105 utf8File,
106 ptsize
107 );
108 Marshal.FreeHGlobal((IntPtr) utf8File);
109 return handle;
110 }
111
112 /* src refers to an SDL_RWops*, IntPtr to a TTF_Font* */
113 /* THIS IS A PUBLIC RWops FUNCTION! */
114 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
115 public static extern IntPtr TTF_OpenFontRW(
116 IntPtr src,
117 int freesrc,
118 int ptsize
119 );
120
121 /* IntPtr refers to a TTF_Font* */
122 [DllImport(nativeLibName, EntryPoint = "TTF_OpenFontIndex", CallingConvention = CallingConvention.Cdecl)]
123 private static extern unsafe IntPtr INTERNAL_TTF_OpenFontIndex(
124 byte* file,
125 int ptsize,
126 long index
127 );
128 public static unsafe IntPtr TTF_OpenFontIndex(
129 string file,
130 int ptsize,
131 long index
132 ) {
133 byte* utf8File = SDL.Utf8EncodeHeap(file);
134 IntPtr handle = INTERNAL_TTF_OpenFontIndex(
135 utf8File,
136 ptsize,
137 index
138 );
139 Marshal.FreeHGlobal((IntPtr) utf8File);
140 return handle;
141 }
142
143 /* src refers to an SDL_RWops*, IntPtr to a TTF_Font* */
144 /* THIS IS A PUBLIC RWops FUNCTION! */
145 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
146 public static extern IntPtr TTF_OpenFontIndexRW(
147 IntPtr src,
148 int freesrc,
149 int ptsize,
150 long index
151 );
152
153 /* font refers to a TTF_Font*
154 * Only available in 2.0.16 or higher.
155 */
156 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
157 public static extern int TTF_SetFontSize(
158 IntPtr font,
159 int ptsize
160 );
161
162 /* font refers to a TTF_Font* */
163 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
164 public static extern int TTF_GetFontStyle(IntPtr font);
165
166 /* font refers to a TTF_Font* */
167 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
168 public static extern void TTF_SetFontStyle(IntPtr font, int style);
169
170 /* font refers to a TTF_Font* */
171 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
172 public static extern int TTF_GetFontOutline(IntPtr font);
173
174 /* font refers to a TTF_Font* */
175 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
176 public static extern void TTF_SetFontOutline(IntPtr font, int outline);
177
178 /* font refers to a TTF_Font* */
179 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
180 public static extern int TTF_GetFontHinting(IntPtr font);
181
182 /* font refers to a TTF_Font* */
183 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
184 public static extern void TTF_SetFontHinting(IntPtr font, int hinting);
185
186 /* font refers to a TTF_Font* */
187 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
188 public static extern int TTF_FontHeight(IntPtr font);
189
190 /* font refers to a TTF_Font* */
191 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
192 public static extern int TTF_FontAscent(IntPtr font);
193
194 /* font refers to a TTF_Font* */
195 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
196 public static extern int TTF_FontDescent(IntPtr font);
197
198 /* font refers to a TTF_Font* */
199 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
200 public static extern int TTF_FontLineSkip(IntPtr font);
201
202 /* font refers to a TTF_Font* */
203 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
204 public static extern int TTF_GetFontKerning(IntPtr font);
205
206 /* font refers to a TTF_Font* */
207 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
208 public static extern void TTF_SetFontKerning(IntPtr font, int allowed);
209
210 /* font refers to a TTF_Font*.
211 * IntPtr is actually a C long! This ignores Win64!
212 */
213 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
214 public static extern IntPtr TTF_FontFaces(IntPtr font);
215
216 /* font refers to a TTF_Font* */
217 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
218 public static extern int TTF_FontFaceIsFixedWidth(IntPtr font);
219
220 /* font refers to a TTF_Font* */
221 [DllImport(nativeLibName, EntryPoint = "TTF_FontFaceFamilyName", CallingConvention = CallingConvention.Cdecl)]
222 private static extern IntPtr INTERNAL_TTF_FontFaceFamilyName(
223 IntPtr font
224 );
225 public static string TTF_FontFaceFamilyName(IntPtr font)
226 {
227 return SDL.UTF8_ToManaged(
228 INTERNAL_TTF_FontFaceFamilyName(font)
229 );
230 }
231
232 /* font refers to a TTF_Font* */
233 [DllImport(nativeLibName, EntryPoint = "TTF_FontFaceStyleName", CallingConvention = CallingConvention.Cdecl)]
234 private static extern IntPtr INTERNAL_TTF_FontFaceStyleName(
235 IntPtr font
236 );
237 public static string TTF_FontFaceStyleName(IntPtr font)
238 {
239 return SDL.UTF8_ToManaged(
240 INTERNAL_TTF_FontFaceStyleName(font)
241 );
242 }
243
244 /* font refers to a TTF_Font* */
245 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
246 public static extern int TTF_GlyphIsProvided(IntPtr font, ushort ch);
247
248 /* font refers to a TTF_Font*
249 * Only available in 2.0.16 or higher.
250 */
251 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
252 public static extern int TTF_GlyphIsProvided32(IntPtr font, uint ch);
253
254 /* font refers to a TTF_Font* */
255 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
256 public static extern int TTF_GlyphMetrics(
257 IntPtr font,
258 ushort ch,
259 out int minx,
260 out int maxx,
261 out int miny,
262 out int maxy,
263 out int advance
264 );
265
266 /* font refers to a TTF_Font*
267 * Only available in 2.0.16 or higher.
268 */
269 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
270 public static extern int TTF_GlyphMetrics32(
271 IntPtr font,
272 uint ch,
273 out int minx,
274 out int maxx,
275 out int miny,
276 out int maxy,
277 out int advance
278 );
279
280 /* font refers to a TTF_Font* */
281 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
282 public static extern int TTF_SizeText(
283 IntPtr font,
284 [In()] [MarshalAs(UnmanagedType.LPStr)]
285 string text,
286 out int w,
287 out int h
288 );
289
290 /* font refers to a TTF_Font* */
291 [DllImport(nativeLibName, EntryPoint = "TTF_SizeUTF8", CallingConvention = CallingConvention.Cdecl)]
292 public static extern unsafe int INTERNAL_TTF_SizeUTF8(
293 IntPtr font,
294 byte* text,
295 out int w,
296 out int h
297 );
298 public static unsafe int TTF_SizeUTF8(
299 IntPtr font,
300 string text,
301 out int w,
302 out int h
303 ) {
304 byte* utf8Text = SDL.Utf8EncodeHeap(text);
305 int result = INTERNAL_TTF_SizeUTF8(
306 font,
307 utf8Text,
308 out w,
309 out h
310 );
311 Marshal.FreeHGlobal((IntPtr) utf8Text);
312 return result;
313 }
314
315 /* font refers to a TTF_Font* */
316 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
317 public static extern int TTF_SizeUNICODE(
318 IntPtr font,
319 [In()] [MarshalAs(UnmanagedType.LPWStr)]
320 string text,
321 out int w,
322 out int h
323 );
324
325 /* font refers to a TTF_Font*
326 * Only available in 2.0.16 or higher.
327 */
328 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
329 public static extern int TTF_MeasureText(
330 IntPtr font,
331 [In()] [MarshalAs(UnmanagedType.LPStr)]
332 string text,
333 int measure_width,
334 out int extent,
335 out int count
336 );
337
338 /* font refers to a TTF_Font*
339 * Only available in 2.0.16 or higher.
340 */
341 [DllImport(nativeLibName, EntryPoint = "TTF_MeasureUTF8", CallingConvention = CallingConvention.Cdecl)]
342 public static extern unsafe int INTERNAL_TTF_MeasureUTF8(
343 IntPtr font,
344 byte* text,
345 int measure_width,
346 out int extent,
347 out int count
348 );
349 public static unsafe int TTF_MeasureUTF8(
350 IntPtr font,
351 string text,
352 int measure_width,
353 out int extent,
354 out int count
355 ) {
356 byte* utf8Text = SDL.Utf8EncodeHeap(text);
357 int result = INTERNAL_TTF_MeasureUTF8(
358 font,
359 utf8Text,
360 measure_width,
361 out extent,
362 out count
363 );
364 Marshal.FreeHGlobal((IntPtr) utf8Text);
365 return result;
366 }
367
368 /* font refers to a TTF_Font*
369 * Only available in 2.0.16 or higher.
370 */
371 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
372 public static extern int TTF_MeasureUNICODE(
373 IntPtr font,
374 [In()] [MarshalAs(UnmanagedType.LPWStr)]
375 string text,
376 int measure_width,
377 out int extent,
378 out int count
379 );
380
381 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
382 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
383 public static extern IntPtr TTF_RenderText_Solid(
384 IntPtr font,
385 [In()] [MarshalAs(UnmanagedType.LPStr)]
386 string text,
387 SDL.SDL_Color fg
388 );
389
390 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
391 [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Solid", CallingConvention = CallingConvention.Cdecl)]
392 private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Solid(
393 IntPtr font,
394 byte* text,
395 SDL.SDL_Color fg
396 );
397 public static unsafe IntPtr TTF_RenderUTF8_Solid(
398 IntPtr font,
399 string text,
400 SDL.SDL_Color fg
401 ) {
402 byte* utf8Text = SDL.Utf8EncodeHeap(text);
403 IntPtr result = INTERNAL_TTF_RenderUTF8_Solid(
404 font,
405 utf8Text,
406 fg
407 );
408 Marshal.FreeHGlobal((IntPtr) utf8Text);
409 return result;
410 }
411
412 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
413 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
414 public static extern IntPtr TTF_RenderUNICODE_Solid(
415 IntPtr font,
416 [In()] [MarshalAs(UnmanagedType.LPWStr)]
417 string text,
418 SDL.SDL_Color fg
419 );
420
421 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
422 * Only available in 2.0.16 or higher.
423 */
424 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
425 public static extern IntPtr TTF_RenderText_Solid_Wrapped(
426 IntPtr font,
427 [In()] [MarshalAs(UnmanagedType.LPStr)]
428 string text,
429 SDL.SDL_Color fg,
430 uint wrapLength
431 );
432
433 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
434 * Only available in 2.0.16 or higher.
435 */
436 [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Solid_Wrapped", CallingConvention = CallingConvention.Cdecl)]
437 public static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Solid_Wrapped(
438 IntPtr font,
439 byte* text,
440 SDL.SDL_Color fg,
441 uint wrapLength
442 );
443 public static unsafe IntPtr TTF_RenderUTF8_Solid_Wrapped(
444 IntPtr font,
445 string text,
446 SDL.SDL_Color fg,
447 uint wrapLength
448 ) {
449 byte* utf8Text = SDL.Utf8EncodeHeap(text);
450 IntPtr result = INTERNAL_TTF_RenderUTF8_Solid_Wrapped(
451 font,
452 utf8Text,
453 fg,
454 wrapLength
455 );
456 Marshal.FreeHGlobal((IntPtr) utf8Text);
457 return result;
458 }
459
460 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
461 * Only available in 2.0.16 or higher.
462 */
463 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
464 public static extern IntPtr TTF_RenderUNICODE_Solid_Wrapped(
465 IntPtr font,
466 [In()] [MarshalAs(UnmanagedType.LPWStr)]
467 string text,
468 SDL.SDL_Color fg,
469 uint wrapLength
470 );
471
472 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
473 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
474 public static extern IntPtr TTF_RenderGlyph_Solid(
475 IntPtr font,
476 ushort ch,
477 SDL.SDL_Color fg
478 );
479
480 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
481 * Only available in 2.0.16 or higher.
482 */
483 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
484 public static extern IntPtr TTF_RenderGlyph32_Solid(
485 IntPtr font,
486 uint ch,
487 SDL.SDL_Color fg
488 );
489
490 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
491 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
492 public static extern IntPtr TTF_RenderText_Shaded(
493 IntPtr font,
494 [In()] [MarshalAs(UnmanagedType.LPStr)]
495 string text,
496 SDL.SDL_Color fg,
497 SDL.SDL_Color bg
498 );
499
500 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
501 [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Shaded", CallingConvention = CallingConvention.Cdecl)]
502 private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Shaded(
503 IntPtr font,
504 byte* text,
505 SDL.SDL_Color fg,
506 SDL.SDL_Color bg
507 );
508 public static unsafe IntPtr TTF_RenderUTF8_Shaded(
509 IntPtr font,
510 string text,
511 SDL.SDL_Color fg,
512 SDL.SDL_Color bg
513 ) {
514 byte* utf8Text = SDL.Utf8EncodeHeap(text);
515 IntPtr result = INTERNAL_TTF_RenderUTF8_Shaded(
516 font,
517 utf8Text,
518 fg,
519 bg
520 );
521 Marshal.FreeHGlobal((IntPtr) utf8Text);
522 return result;
523 }
524
525 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
526 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
527 public static extern IntPtr TTF_RenderUNICODE_Shaded(
528 IntPtr font,
529 [In()] [MarshalAs(UnmanagedType.LPWStr)]
530 string text,
531 SDL.SDL_Color fg,
532 SDL.SDL_Color bg
533 );
534
535 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
536 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
537 public static extern IntPtr TTF_RenderText_Shaded_Wrapped(
538 IntPtr font,
539 [In()] [MarshalAs(UnmanagedType.LPStr)]
540 string text,
541 SDL.SDL_Color fg,
542 SDL.SDL_Color bg,
543 uint wrapLength
544 );
545
546 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
547 * Only available in 2.0.16 or higher.
548 */
549 [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Shaded_Wrapped", CallingConvention = CallingConvention.Cdecl)]
550 public static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Shaded_Wrapped(
551 IntPtr font,
552 byte* text,
553 SDL.SDL_Color fg,
554 SDL.SDL_Color bg,
555 uint wrapLength
556 );
557 public static unsafe IntPtr TTF_RenderUTF8_Shaded_Wrapped(
558 IntPtr font,
559 string text,
560 SDL.SDL_Color fg,
561 SDL.SDL_Color bg,
562 uint wrapLength
563 ) {
564 byte* utf8Text = SDL.Utf8EncodeHeap(text);
565 IntPtr result = INTERNAL_TTF_RenderUTF8_Shaded_Wrapped(
566 font,
567 utf8Text,
568 fg,
569 bg,
570 wrapLength
571 );
572 Marshal.FreeHGlobal((IntPtr) utf8Text);
573 return result;
574 }
575
576 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
577 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
578 public static extern IntPtr TTF_RenderUNICODE_Shaded_Wrapped(
579 IntPtr font,
580 [In()] [MarshalAs(UnmanagedType.LPWStr)]
581 string text,
582 SDL.SDL_Color fg,
583 SDL.SDL_Color bg,
584 uint wrapLength
585 );
586
587 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
588 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
589 public static extern IntPtr TTF_RenderGlyph_Shaded(
590 IntPtr font,
591 ushort ch,
592 SDL.SDL_Color fg,
593 SDL.SDL_Color bg
594 );
595
596 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
597 * Only available in 2.0.16 or higher.
598 */
599 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
600 public static extern IntPtr TTF_RenderGlyph32_Shaded(
601 IntPtr font,
602 uint ch,
603 SDL.SDL_Color fg,
604 SDL.SDL_Color bg
605 );
606
607 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
608 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
609 public static extern IntPtr TTF_RenderText_Blended(
610 IntPtr font,
611 [In()] [MarshalAs(UnmanagedType.LPStr)]
612 string text,
613 SDL.SDL_Color fg
614 );
615
616 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
617 [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Blended", CallingConvention = CallingConvention.Cdecl)]
618 private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Blended(
619 IntPtr font,
620 byte* text,
621 SDL.SDL_Color fg
622 );
623 public static unsafe IntPtr TTF_RenderUTF8_Blended(
624 IntPtr font,
625 string text,
626 SDL.SDL_Color fg
627 ) {
628 byte* utf8Text = SDL.Utf8EncodeHeap(text);
629 IntPtr result = INTERNAL_TTF_RenderUTF8_Blended(
630 font,
631 utf8Text,
632 fg
633 );
634 Marshal.FreeHGlobal((IntPtr) utf8Text);
635 return result;
636 }
637
638 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
639 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
640 public static extern IntPtr TTF_RenderUNICODE_Blended(
641 IntPtr font,
642 [In()] [MarshalAs(UnmanagedType.LPWStr)]
643 string text,
644 SDL.SDL_Color fg
645 );
646
647 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
648 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
649 public static extern IntPtr TTF_RenderText_Blended_Wrapped(
650 IntPtr font,
651 [In()] [MarshalAs(UnmanagedType.LPStr)]
652 string text,
653 SDL.SDL_Color fg,
654 uint wrapped
655 );
656
657 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
658 [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Blended_Wrapped", CallingConvention = CallingConvention.Cdecl)]
659 private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Blended_Wrapped(
660 IntPtr font,
661 byte* text,
662 SDL.SDL_Color fg,
663 uint wrapped
664 );
665 public static unsafe IntPtr TTF_RenderUTF8_Blended_Wrapped(
666 IntPtr font,
667 string text,
668 SDL.SDL_Color fg,
669 uint wrapped
670 ) {
671 byte* utf8Text = SDL.Utf8EncodeHeap(text);
672 IntPtr result = INTERNAL_TTF_RenderUTF8_Blended_Wrapped(
673 font,
674 utf8Text,
675 fg,
676 wrapped
677 );
678 Marshal.FreeHGlobal((IntPtr) utf8Text);
679 return result;
680 }
681
682 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
683 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
684 public static extern IntPtr TTF_RenderUNICODE_Blended_Wrapped(
685 IntPtr font,
686 [In()] [MarshalAs(UnmanagedType.LPWStr)]
687 string text,
688 SDL.SDL_Color fg,
689 uint wrapped
690 );
691
692 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
693 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
694 public static extern IntPtr TTF_RenderGlyph_Blended(
695 IntPtr font,
696 ushort ch,
697 SDL.SDL_Color fg
698 );
699
700 /* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
701 * Only available in 2.0.16 or higher.
702 */
703 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
704 public static extern IntPtr TTF_RenderGlyph32_Blended(
705 IntPtr font,
706 uint ch,
707 SDL.SDL_Color fg
708 );
709
710 /* Only available in 2.0.16 or higher. */
711 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
712 public static extern int TTF_SetDirection(int direction);
713
714 /* Only available in 2.0.16 or higher. */
715 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
716 public static extern int TTF_SetScript(int script);
717
718 /* font refers to a TTF_Font* */
719 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
720 public static extern void TTF_CloseFont(IntPtr font);
721
722 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
723 public static extern void TTF_Quit();
724
725 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
726 public static extern int TTF_WasInit();
727
728 /* font refers to a TTF_Font* */
729 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
730 public static extern int SDL_GetFontKerningSize(
731 IntPtr font,
732 int prev_index,
733 int index
734 );
735
736 /* font refers to a TTF_Font*
737 * Only available in 2.0.15 or higher.
738 */
739 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
740 public static extern int TTF_GetFontKerningSizeGlyphs(
741 IntPtr font,
742 ushort previous_ch,
743 ushort ch
744 );
745
746 /* font refers to a TTF_Font*
747 * Only available in 2.0.16 or higher.
748 */
749 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
750 public static extern int TTF_GetFontKerningSizeGlyphs32(
751 IntPtr font,
752 ushort previous_ch,
753 ushort ch
754 );
755
756 public static string TTF_GetError()
757 {
758 return SDL.SDL_GetError();
759 }
760
761 public static void TTF_SetError(string fmtAndArglist)
762 {
763 SDL.SDL_SetError(fmtAndArglist);
764 }
765
766 #endregion
767 }
768}