5 releases

Uses old Rust 2015

0.2.1 Jul 10, 2021
0.2.0 Dec 1, 2018
0.1.2 Dec 1, 2018
0.1.1 Aug 30, 2018
0.1.0 Jan 10, 2018

#528 in Graphics APIs

29 downloads per month

MIT license

105KB
1K SLoC

freetype-rs Build Status

Rust bindings for FreeType library

Requirements

  • Cargo: We use Cargo to compile the project.
  • FreeType2 development libraries: For installation instructions see freetype-sys.

Build

Clone this repo then run

cd freetype-rs
cargo build

Examples

To build examples, use cargo test. They are all built in ./target/debug/examples/*.

To run examples, use cargo run --example name, for example:

cargo run --example single_glyph examples/assets/FiraSans-Regular.ttf A

How to contribute


lib.rs:

Rust wrapper around freetype 2 library

Initialization

To create a new freetype context, instantiate the Library struct as below. The Library (along with other objects) obeys RAII and is dropped when the struct goes out of scope.

Example

extern crate freetype;

fn main() {
    use freetype::Library;
    use freetype::face::LoadFlag;

    // Init the library
    let lib = Library::init().unwrap();
    // Load a font face
    let face = lib.new_face("/path/to/a/font/file.ttf", 0).unwrap();
    // Set the font size
    face.set_char_size(40 * 64, 0, 50, 0).unwrap();
    // Load a character
    face.load_char('A' as usize, LoadFlag::RENDER).unwrap();
    // Get the glyph instance
    let glyph = face.glyph();
    do_something_with_bitmap(glyph.bitmap());
}

See in the examples/ folder for more examples.

External links

Dependencies

~12MB
~259K SLoC