fcft-sys 0.1.0

Raw bindings to fcft: font loading and glyph rasterisation library
Documentation
//! Basic sanity tests.

use std::ffi::CString;

#[test]
fn init_load_rasterize() {
    unsafe {
        assert!(fcft_sys::fcft_init(
            fcft_sys::fcft_log_colorize_FCFT_LOG_COLORIZE_NEVER,
            false,
            fcft_sys::fcft_log_class_FCFT_LOG_CLASS_ERROR,
        ));

        // Capabilities is a plain bitmask; just make sure it's callable.
        let _caps = fcft_sys::fcft_capabilities();

        let name = CString::new("monospace:pixelsize=16").unwrap();
        let mut names = [name.as_ptr()];
        let font = fcft_sys::fcft_from_name(1, names.as_mut_ptr(), std::ptr::null());
        assert!(!font.is_null(), "fontconfig should always match something");

        let metrics = &*font;
        assert!(metrics.height > 0);
        assert!(metrics.ascent > 0);

        let glyph = fcft_sys::fcft_rasterize_char_utf32(
            font,
            u32::from('A'),
            fcft_sys::fcft_subpixel_FCFT_SUBPIXEL_NONE,
        );
        assert!(!glyph.is_null());
        let glyph = &*glyph;
        assert!(glyph.width > 0);
        assert!(glyph.advance.x > 0);
        assert!(!glyph.pix.is_null());

        fcft_sys::fcft_destroy(font);
    }
}