51 releases (31 breaking)

Uses old Rust 2015

0.31.0 Aug 4, 2022
0.30.1 Apr 28, 2022
0.29.1 Mar 19, 2022
0.29.0 Nov 28, 2021
0.0.0 Dec 11, 2014

#16 in Graphics APIs

Download history 2270/week @ 2022-04-25 2294/week @ 2022-05-02 2118/week @ 2022-05-09 3094/week @ 2022-05-16 2441/week @ 2022-05-23 2785/week @ 2022-05-30 3037/week @ 2022-06-06 2704/week @ 2022-06-13 2577/week @ 2022-06-20 2668/week @ 2022-06-27 2687/week @ 2022-07-04 2653/week @ 2022-07-11 2892/week @ 2022-07-18 3606/week @ 2022-07-25 4426/week @ 2022-08-01 4877/week @ 2022-08-08

16,130 downloads per month
Used in 50 crates (16 directly)

MIT license

105KB
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;
    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

~6.5MB
~126K SLoC