36 releases (19 breaking)

0.19.0 Jul 17, 2018
0.18.0 Feb 20, 2018
0.17.0 Feb 9, 2018
0.16.0 Oct 15, 2017
0.0.0 Dec 11, 2014

#6 in Rendering

Download history 495/week @ 2018-09-14 1111/week @ 2018-09-21 632/week @ 2018-09-28 1239/week @ 2018-10-05 901/week @ 2018-10-12 1837/week @ 2018-10-19 809/week @ 2018-10-26 1110/week @ 2018-11-02 1002/week @ 2018-11-09 1642/week @ 2018-11-16 710/week @ 2018-11-23 724/week @ 2018-11-30 755/week @ 2018-12-07

2,623 downloads per month
Used in 22 crates (3 directly)

MIT license

106KB
1.5K 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;

    // 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, freetype::face::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

~1.5MB
~33K SLoC