#text #ffi #shaping #textlayout #harfbuzz


A high-level interface to HarfBuzz, exposing its most important functionality in a safe manner using Rust

7 releases (3 stable)

✓ Uses Rust 2018 edition

1.1.1 Apr 29, 2020
1.0.1 Jan 18, 2020
1.0.0 Jan 31, 2019
0.4.0 Jan 8, 2019
0.1.0 Jan 11, 2018

#3 in Internationalization (i18n)

Download history 1093/week @ 2020-03-16 3785/week @ 2020-03-23 1739/week @ 2020-03-30 1376/week @ 2020-04-06 1616/week @ 2020-04-13 1370/week @ 2020-04-20 2022/week @ 2020-04-27 1790/week @ 2020-05-04 2282/week @ 2020-05-11 2001/week @ 2020-05-18 2674/week @ 2020-05-25 2279/week @ 2020-06-01 1981/week @ 2020-06-08 2247/week @ 2020-06-15 1777/week @ 2020-06-22 1530/week @ 2020-06-29

5,692 downloads per month

MIT license



Crates.io Documentation Build Status Build status

harfbuzz_rs is a high-level interface to HarfBuzz, exposing its most important functionality in a safe manner using Rust.

What is HarfBuzz?

HarfBuzz is a library for performing complex text layout. It does not perform any drawing. This is quite a low-level operation. If you want to simply draw some text on the screen you should maybe choose another more high-level library. However if you want to build a library for drawing text on some canvas or need a lot of control on advanced text layout then this is the right library to use.

Getting Started

To shape a simple string of text you just create a Font from a font file, fill a Buffer with some text and call the shape function.

use harfbuzz_rs::*;

let path = "path/to/some/font_file.otf";
let index = 0; //< face index in the font file
let face = Face::from_file(path, index)?;
let mut font = Font::new(face);

let buffer = UnicodeBuffer::new().add_str("Hello World!");
let output = shape(&font, buffer, &[]);

// The results of the shaping operation are stored in the `output` buffer.

let positions = output.get_glyph_positions();
let infos = output.get_glyph_infos();

// iterate over the shaped glyphs
for (position, info) in positions.iter().zip(infos) {
    let gid = info.codepoint;
    let cluster = info.cluster;
    let x_advance = position.x_advance;
    let x_offset = position.x_offset;
    let y_offset = position.y_offset;

    // Here you would usually draw the glyphs.
    println!("gid{:?}={:?}@{:?},{:?}+{:?}", gid, cluster, x_advance, x_offset, y_offset);

This should print out something similar to the following:


Supported HarfBuzz versions

This crate is tested to work with harfbuzz versions 2.0 and higher. Older versions may work as well but not sure. I recommend statically linking the harfbuzz library provided by the harfbuzz-sys crate.

Optional Features

If you want to use rusttype as font functions enable the rusttype feature.


~51K SLoC