57 releases (36 breaking)

Uses old Rust 2015

0.36.0 Feb 15, 2024
0.34.1 Dec 7, 2023
0.34.0 Oct 19, 2023
0.32.0 Nov 16, 2022
0.0.0 Dec 11, 2014

#22 in Graphics APIs

Download history 5949/week @ 2023-12-06 6360/week @ 2023-12-13 5932/week @ 2023-12-20 5255/week @ 2023-12-27 6123/week @ 2024-01-03 6886/week @ 2024-01-10 6527/week @ 2024-01-17 6512/week @ 2024-01-24 6192/week @ 2024-01-31 7257/week @ 2024-02-07 5916/week @ 2024-02-14 7324/week @ 2024-02-21 6852/week @ 2024-02-28 5903/week @ 2024-03-06 6799/week @ 2024-03-13 5128/week @ 2024-03-20

25,911 downloads per month
Used in 61 crates (21 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

~7.5MB
~148K SLoC