rustfontshandlefreetype

How do I use freetype bindings in Rust?


I've been working on a fairly basic project which needs to interact with fonts. The plan was to use the bindings for FreeType by the Servo team. However, I'm having a hard time figuring out how exactly one is to use it. I've new to FreeType, so I'm following their tutorial. What's tripping me up at this point is creating the handles. I did try the (admittedly laughable) to create the library handle for instance:

use freetype::freetype;
let library: freetype::FT_Library;

That predictably did not work. I have resolved to use font_kit for the project because I'm fairly certain this is a bit over my head. But I'd still love to find out how I can actually do this.


Solution

  • It looks like you can use std::ptr::null_mut to initialize freetype::freetype::FT_Library:

    fn main() {
        let mut lib: freetype::freetype::FT_Library = std::ptr::null_mut();
        let result = unsafe {
            freetype::freetype::FT_Init_FreeType(&mut lib)
        };
        println!("Initialization succeed:{}",  freetype::succeeded(result));
    }
    

    Based on example.