Skip to content

Commit f2a7b7f

Browse files
committed
Convert SDL_ttf bindings into autogenerated bindings
Had to change some mutability of some raw pointers used, but the ttf demo seem to work. Progresses on Rust-SDL2#647
1 parent d096769 commit f2a7b7f

File tree

5 files changed

+339
-106
lines changed

5 files changed

+339
-106
lines changed

sdl2-sys/build.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ fn copy_pregenerated_bindings() {
284284

285285
fs::copy(crate_path.join("sdl_image_bindings.rs"), out_path.join("image_bindings.rs"))
286286
.expect("Couldn't find pregenerated SDL_image bindings!");
287+
288+
fs::copy(crate_path.join("sdl_ttf_bindings.rs"), out_path.join("ttf_bindings.rs"))
289+
.expect("Couldn't find pregenerated SDL_ttf bindings!");
287290
}
288291

289292
#[cfg(feature = "bindgen")]
@@ -293,6 +296,7 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
293296
let target_os = get_os_from_triple(target).unwrap();
294297
let mut bindings = bindgen::Builder::default();
295298
let mut image_bindings = bindgen::Builder::default();
299+
let mut ttf_bindings = bindgen::Builder::default();
296300

297301
// Set correct target triple for bindgen when cross-compiling
298302
if target != host {
@@ -301,6 +305,9 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
301305

302306
image_bindings = image_bindings.clang_arg("-target");
303307
image_bindings = image_bindings.clang_arg(target.clone());
308+
309+
ttf_bindings = ttf_bindings.clang_arg("-target");
310+
ttf_bindings = ttf_bindings.clang_arg(target.clone());
304311
}
305312

306313
if headers_paths.len() == 0 {
@@ -310,11 +317,13 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
310317
include_path.push("include");
311318
bindings = bindings.clang_arg(format!("-I{}", include_path.display()));
312319
image_bindings = image_bindings.clang_arg(format!("-I{}", include_path.display()));
320+
ttf_bindings = ttf_bindings.clang_arg(format!("-I{}", include_path.display()));
313321
} else {
314322
// if paths are included, use them for bindgen. Bindgen should use the first one.
315323
for headers_path in headers_paths {
316324
bindings = bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
317325
image_bindings = image_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
326+
ttf_bindings = ttf_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
318327
}
319328
}
320329

@@ -330,6 +339,12 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
330339
image_bindings = image_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"));
331340
image_bindings = image_bindings.clang_arg(format!("-IC:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"));
332341
image_bindings = image_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/um"));
342+
343+
ttf_bindings = ttf_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/shared"));
344+
ttf_bindings = ttf_bindings.clang_arg(format!("-IC:/Program Files/LLVM/lib/clang/5.0.0/include"));
345+
ttf_bindings = ttf_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"));
346+
ttf_bindings = ttf_bindings.clang_arg(format!("-IC:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"));
347+
ttf_bindings = ttf_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/um"));
333348
};
334349

335350
// SDL2 hasn't a default configuration for Linux
@@ -338,6 +353,8 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
338353
bindings = bindings.clang_arg("-DSDL_VIDEO_DRIVER_WAYLAND");
339354
image_bindings = image_bindings.clang_arg("-DSDL_VIDEO_DRIVER_X11");
340355
image_bindings = image_bindings.clang_arg("-DSDL_VIDEO_DRIVER_WAYLAND");
356+
ttf_bindings = ttf_bindings.clang_arg("-DSDL_VIDEO_DRIVER_X11");
357+
ttf_bindings = ttf_bindings.clang_arg("-DSDL_VIDEO_DRIVER_WAYLAND");
341358
}
342359

343360
let bindings = bindings
@@ -370,6 +387,22 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
370387
.write_to_file(out_path.join("image_bindings.rs"))
371388
.expect("Couldn't write image_bindings!");
372389

390+
let ttf_bindings = ttf_bindings
391+
.header("wrapper_ttf.h")
392+
.whitelist_type("TTF.*")
393+
.whitelist_function("TTF.*")
394+
.whitelist_var("TTF.*")
395+
.blacklist_type("SDL_.*")
396+
.blacklist_type("_IO.*|FILE")
397+
.generate()
398+
.expect("Unable to generate ttf_bindings!");
399+
400+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
401+
402+
ttf_bindings
403+
.write_to_file(out_path.join("ttf_bindings.rs"))
404+
.expect("Couldn't write ttf_bindings!");
405+
373406
}
374407

375408
fn get_os_from_triple(triple: &str) -> Option<&str>

sdl2-sys/sdl_ttf_bindings.rs

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
pub const TTF_MAJOR_VERSION: u32 = 2;
4+
pub const TTF_MINOR_VERSION: u32 = 0;
5+
pub const TTF_PATCHLEVEL: u32 = 14;
6+
pub const TTF_STYLE_NORMAL: u32 = 0;
7+
pub const TTF_STYLE_BOLD: u32 = 1;
8+
pub const TTF_STYLE_ITALIC: u32 = 2;
9+
pub const TTF_STYLE_UNDERLINE: u32 = 4;
10+
pub const TTF_STYLE_STRIKETHROUGH: u32 = 8;
11+
pub const TTF_HINTING_NORMAL: u32 = 0;
12+
pub const TTF_HINTING_LIGHT: u32 = 1;
13+
pub const TTF_HINTING_MONO: u32 = 2;
14+
pub const TTF_HINTING_NONE: u32 = 3;
15+
pub type __uint8_t = ::std::os::raw::c_uchar;
16+
pub type __uint16_t = ::std::os::raw::c_ushort;
17+
pub type __uint32_t = ::std::os::raw::c_uint;
18+
pub type __int64_t = ::std::os::raw::c_long;
19+
pub type __off_t = ::std::os::raw::c_long;
20+
pub type __off64_t = ::std::os::raw::c_long;
21+
pub type Uint8 = u8;
22+
pub type Uint16 = u16;
23+
pub type Uint32 = u32;
24+
pub type Sint64 = i64;
25+
extern "C" {
26+
pub fn TTF_Linked_Version() -> *const SDL_version;
27+
}
28+
extern "C" {
29+
pub fn TTF_ByteSwappedUNICODE(swapped: ::std::os::raw::c_int);
30+
}
31+
#[repr(C)]
32+
#[derive(Debug, Copy, Clone)]
33+
pub struct _TTF_Font {
34+
_unused: [u8; 0],
35+
}
36+
pub type TTF_Font = _TTF_Font;
37+
extern "C" {
38+
pub fn TTF_Init() -> ::std::os::raw::c_int;
39+
}
40+
extern "C" {
41+
pub fn TTF_OpenFont(
42+
file: *const ::std::os::raw::c_char,
43+
ptsize: ::std::os::raw::c_int,
44+
) -> *mut TTF_Font;
45+
}
46+
extern "C" {
47+
pub fn TTF_OpenFontIndex(
48+
file: *const ::std::os::raw::c_char,
49+
ptsize: ::std::os::raw::c_int,
50+
index: ::std::os::raw::c_long,
51+
) -> *mut TTF_Font;
52+
}
53+
extern "C" {
54+
pub fn TTF_OpenFontRW(
55+
src: *mut SDL_RWops,
56+
freesrc: ::std::os::raw::c_int,
57+
ptsize: ::std::os::raw::c_int,
58+
) -> *mut TTF_Font;
59+
}
60+
extern "C" {
61+
pub fn TTF_OpenFontIndexRW(
62+
src: *mut SDL_RWops,
63+
freesrc: ::std::os::raw::c_int,
64+
ptsize: ::std::os::raw::c_int,
65+
index: ::std::os::raw::c_long,
66+
) -> *mut TTF_Font;
67+
}
68+
extern "C" {
69+
pub fn TTF_GetFontStyle(font: *const TTF_Font) -> ::std::os::raw::c_int;
70+
}
71+
extern "C" {
72+
pub fn TTF_SetFontStyle(font: *mut TTF_Font, style: ::std::os::raw::c_int);
73+
}
74+
extern "C" {
75+
pub fn TTF_GetFontOutline(font: *const TTF_Font) -> ::std::os::raw::c_int;
76+
}
77+
extern "C" {
78+
pub fn TTF_SetFontOutline(font: *mut TTF_Font, outline: ::std::os::raw::c_int);
79+
}
80+
extern "C" {
81+
pub fn TTF_GetFontHinting(font: *const TTF_Font) -> ::std::os::raw::c_int;
82+
}
83+
extern "C" {
84+
pub fn TTF_SetFontHinting(font: *mut TTF_Font, hinting: ::std::os::raw::c_int);
85+
}
86+
extern "C" {
87+
pub fn TTF_FontHeight(font: *const TTF_Font) -> ::std::os::raw::c_int;
88+
}
89+
extern "C" {
90+
pub fn TTF_FontAscent(font: *const TTF_Font) -> ::std::os::raw::c_int;
91+
}
92+
extern "C" {
93+
pub fn TTF_FontDescent(font: *const TTF_Font) -> ::std::os::raw::c_int;
94+
}
95+
extern "C" {
96+
pub fn TTF_FontLineSkip(font: *const TTF_Font) -> ::std::os::raw::c_int;
97+
}
98+
extern "C" {
99+
pub fn TTF_GetFontKerning(font: *const TTF_Font) -> ::std::os::raw::c_int;
100+
}
101+
extern "C" {
102+
pub fn TTF_SetFontKerning(font: *mut TTF_Font, allowed: ::std::os::raw::c_int);
103+
}
104+
extern "C" {
105+
pub fn TTF_FontFaces(font: *const TTF_Font) -> ::std::os::raw::c_long;
106+
}
107+
extern "C" {
108+
pub fn TTF_FontFaceIsFixedWidth(font: *const TTF_Font) -> ::std::os::raw::c_int;
109+
}
110+
extern "C" {
111+
pub fn TTF_FontFaceFamilyName(font: *const TTF_Font) -> *mut ::std::os::raw::c_char;
112+
}
113+
extern "C" {
114+
pub fn TTF_FontFaceStyleName(font: *const TTF_Font) -> *mut ::std::os::raw::c_char;
115+
}
116+
extern "C" {
117+
pub fn TTF_GlyphIsProvided(font: *const TTF_Font, ch: Uint16) -> ::std::os::raw::c_int;
118+
}
119+
extern "C" {
120+
pub fn TTF_GlyphMetrics(
121+
font: *mut TTF_Font,
122+
ch: Uint16,
123+
minx: *mut ::std::os::raw::c_int,
124+
maxx: *mut ::std::os::raw::c_int,
125+
miny: *mut ::std::os::raw::c_int,
126+
maxy: *mut ::std::os::raw::c_int,
127+
advance: *mut ::std::os::raw::c_int,
128+
) -> ::std::os::raw::c_int;
129+
}
130+
extern "C" {
131+
pub fn TTF_SizeText(
132+
font: *mut TTF_Font,
133+
text: *const ::std::os::raw::c_char,
134+
w: *mut ::std::os::raw::c_int,
135+
h: *mut ::std::os::raw::c_int,
136+
) -> ::std::os::raw::c_int;
137+
}
138+
extern "C" {
139+
pub fn TTF_SizeUTF8(
140+
font: *mut TTF_Font,
141+
text: *const ::std::os::raw::c_char,
142+
w: *mut ::std::os::raw::c_int,
143+
h: *mut ::std::os::raw::c_int,
144+
) -> ::std::os::raw::c_int;
145+
}
146+
extern "C" {
147+
pub fn TTF_SizeUNICODE(
148+
font: *mut TTF_Font,
149+
text: *const Uint16,
150+
w: *mut ::std::os::raw::c_int,
151+
h: *mut ::std::os::raw::c_int,
152+
) -> ::std::os::raw::c_int;
153+
}
154+
extern "C" {
155+
pub fn TTF_RenderText_Solid(
156+
font: *mut TTF_Font,
157+
text: *const ::std::os::raw::c_char,
158+
fg: SDL_Color,
159+
) -> *mut SDL_Surface;
160+
}
161+
extern "C" {
162+
pub fn TTF_RenderUTF8_Solid(
163+
font: *mut TTF_Font,
164+
text: *const ::std::os::raw::c_char,
165+
fg: SDL_Color,
166+
) -> *mut SDL_Surface;
167+
}
168+
extern "C" {
169+
pub fn TTF_RenderUNICODE_Solid(
170+
font: *mut TTF_Font,
171+
text: *const Uint16,
172+
fg: SDL_Color,
173+
) -> *mut SDL_Surface;
174+
}
175+
extern "C" {
176+
pub fn TTF_RenderGlyph_Solid(
177+
font: *mut TTF_Font,
178+
ch: Uint16,
179+
fg: SDL_Color,
180+
) -> *mut SDL_Surface;
181+
}
182+
extern "C" {
183+
pub fn TTF_RenderText_Shaded(
184+
font: *mut TTF_Font,
185+
text: *const ::std::os::raw::c_char,
186+
fg: SDL_Color,
187+
bg: SDL_Color,
188+
) -> *mut SDL_Surface;
189+
}
190+
extern "C" {
191+
pub fn TTF_RenderUTF8_Shaded(
192+
font: *mut TTF_Font,
193+
text: *const ::std::os::raw::c_char,
194+
fg: SDL_Color,
195+
bg: SDL_Color,
196+
) -> *mut SDL_Surface;
197+
}
198+
extern "C" {
199+
pub fn TTF_RenderUNICODE_Shaded(
200+
font: *mut TTF_Font,
201+
text: *const Uint16,
202+
fg: SDL_Color,
203+
bg: SDL_Color,
204+
) -> *mut SDL_Surface;
205+
}
206+
extern "C" {
207+
pub fn TTF_RenderGlyph_Shaded(
208+
font: *mut TTF_Font,
209+
ch: Uint16,
210+
fg: SDL_Color,
211+
bg: SDL_Color,
212+
) -> *mut SDL_Surface;
213+
}
214+
extern "C" {
215+
pub fn TTF_RenderText_Blended(
216+
font: *mut TTF_Font,
217+
text: *const ::std::os::raw::c_char,
218+
fg: SDL_Color,
219+
) -> *mut SDL_Surface;
220+
}
221+
extern "C" {
222+
pub fn TTF_RenderUTF8_Blended(
223+
font: *mut TTF_Font,
224+
text: *const ::std::os::raw::c_char,
225+
fg: SDL_Color,
226+
) -> *mut SDL_Surface;
227+
}
228+
extern "C" {
229+
pub fn TTF_RenderUNICODE_Blended(
230+
font: *mut TTF_Font,
231+
text: *const Uint16,
232+
fg: SDL_Color,
233+
) -> *mut SDL_Surface;
234+
}
235+
extern "C" {
236+
pub fn TTF_RenderText_Blended_Wrapped(
237+
font: *mut TTF_Font,
238+
text: *const ::std::os::raw::c_char,
239+
fg: SDL_Color,
240+
wrapLength: Uint32,
241+
) -> *mut SDL_Surface;
242+
}
243+
extern "C" {
244+
pub fn TTF_RenderUTF8_Blended_Wrapped(
245+
font: *mut TTF_Font,
246+
text: *const ::std::os::raw::c_char,
247+
fg: SDL_Color,
248+
wrapLength: Uint32,
249+
) -> *mut SDL_Surface;
250+
}
251+
extern "C" {
252+
pub fn TTF_RenderUNICODE_Blended_Wrapped(
253+
font: *mut TTF_Font,
254+
text: *const Uint16,
255+
fg: SDL_Color,
256+
wrapLength: Uint32,
257+
) -> *mut SDL_Surface;
258+
}
259+
extern "C" {
260+
pub fn TTF_RenderGlyph_Blended(
261+
font: *mut TTF_Font,
262+
ch: Uint16,
263+
fg: SDL_Color,
264+
) -> *mut SDL_Surface;
265+
}
266+
extern "C" {
267+
pub fn TTF_CloseFont(font: *mut TTF_Font);
268+
}
269+
extern "C" {
270+
pub fn TTF_Quit();
271+
}
272+
extern "C" {
273+
pub fn TTF_WasInit() -> ::std::os::raw::c_int;
274+
}
275+
extern "C" {
276+
pub fn TTF_GetFontKerningSize(
277+
font: *mut TTF_Font,
278+
prev_index: ::std::os::raw::c_int,
279+
index: ::std::os::raw::c_int,
280+
) -> ::std::os::raw::c_int;
281+
}
282+
extern "C" {
283+
pub fn TTF_GetFontKerningSizeGlyphs(
284+
font: *mut TTF_Font,
285+
previous_ch: Uint16,
286+
ch: Uint16,
287+
) -> ::std::os::raw::c_int;
288+
}

0 commit comments

Comments
 (0)