All Projects → manuel-rhdt → harfbuzz_rs

manuel-rhdt / harfbuzz_rs

Licence: MIT license
A fully safe Rust wrapper for the harfbuzz text shaping library.

Programming Languages

C++
36643 projects - #6 most used programming language
HTML
75241 projects
Makefile
30231 projects
c
50402 projects - #5 most used programming language
hack
652 projects
shell
77523 projects

Projects that are alternatives of or similar to harfbuzz rs

Tehreer-Android
Standalone text engine for Android aimed to be free from platform limitations
Stars: ✭ 61 (+134.62%)
Mutual labels:  harfbuzz, text-layout, text-shaping
Tehreer-Cocoa
Standalone text engine for iOS
Stars: ✭ 31 (+19.23%)
Mutual labels:  harfbuzz, text-layout, text-shaping
harfbuzz-example
Harfbuzz text-shaping example with OpenGL using Freetype
Stars: ✭ 104 (+300%)
Mutual labels:  harfbuzz, text-shaping
typesetting
High quality text shaping in pure Go.
Stars: ✭ 28 (+7.69%)
Mutual labels:  harfbuzz, text-shaping
sdlpp
C++ wrapper for SDL2
Stars: ✭ 37 (+42.31%)
Mutual labels:  wrapper
readexpro
Readex Pro is the world-script expansion of Lexend. Lexend is a variable font empirically shown to significantly improve reading-proficiency.
Stars: ✭ 396 (+1423.08%)
Mutual labels:  font
net-Socket
A minimalist wrapper around System.Net.Sockets.Socket.
Stars: ✭ 21 (-19.23%)
Mutual labels:  wrapper
sandboxed-fs
Sandboxed Wrapper for Node.js File System API
Stars: ✭ 41 (+57.69%)
Mutual labels:  wrapper
PSEventViewer
PSEventViewer (Get-Events) is really useful PowerShell wrapper around Get-WinEvent. One of the features you may be interested in is a simple way of getting “hidden” events data
Stars: ✭ 74 (+184.62%)
Mutual labels:  wrapper
image-generator
Package for PHP 8.x to generate placeholder images with a specific size, color, text on it. You can also customize the font. (Legacy version available for PHP 7.x.)
Stars: ✭ 16 (-38.46%)
Mutual labels:  font
routeros-client
Abstraction layer over the node-routeros API
Stars: ✭ 63 (+142.31%)
Mutual labels:  wrapper
advcash
node.js wrapper for advcash cryptocurrency exchange
Stars: ✭ 14 (-46.15%)
Mutual labels:  wrapper
igdb
Laravel PHP Facade/Wrapper for the IGDB API
Stars: ✭ 30 (+15.38%)
Mutual labels:  wrapper
YaraSharp
C# wrapper around the Yara pattern matching library
Stars: ✭ 29 (+11.54%)
Mutual labels:  wrapper
tyffle
Try Google Fonts Blazing Fast. https://tyffle.ml
Stars: ✭ 17 (-34.62%)
Mutual labels:  font
limo
A wrapper around selenium webdriver
Stars: ✭ 25 (-3.85%)
Mutual labels:  wrapper
noto-color-emoji-font
Color emoji SVGinOT font using Noto emoji, with multiple releases, such as Lollipop and Nougat. Linux/MacOS/Windows
Stars: ✭ 32 (+23.08%)
Mutual labels:  font
FinMesh
A python package that brings together financial and economic data.
Stars: ✭ 20 (-23.08%)
Mutual labels:  wrapper
nimCEF
Nim wrapper for the Chromium Embedded Framework
Stars: ✭ 27 (+3.85%)
Mutual labels:  wrapper
CallofDuty.py
Asynchronous, object-oriented Python wrapper for the Call of Duty API.
Stars: ✭ 86 (+230.77%)
Mutual labels:  wrapper

harfbuzz_rs

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:

gid41=0@741,0+0
gid70=1@421,0+0
gid77=2@258,0+0
gid77=3@253,0+0
gid80=4@510,0+0
gid1=5@227,0+0
gid56=6@874,0+0
gid80=7@498,0+0
gid83=8@367,0+0
gid77=9@253,0+0
gid69=10@528,0+0
gid2=11@276,0+0

The values of x_advance, x_offset, y_advance and y_offset are all given in so-called font units by default. By calling face.upem() you get the number of font units per EM for a specific face. This upem value can be used to scale the advances and offsets to a given font-size. For example, if you want to display a font at 16 point (pt) size, that means that 1 EM = 16 pt. In this example, to convert a value, say x_advance, from font-units to points, we compute ((x_advance * font_size) as f64) / (upem as f64), where font_size = 16 is a variable specifying the font size in points.

Note that harfbuzz internally supports scaling fonts itself as well (using font.set_scale(...), etc.) but in my opinion it is easier to scale the results oneself as described in the paragraph above.

Supported HarfBuzz versions

This crate is tested to work with harfbuzz versions 2.0 and higher. Older versions may work as well. I recommend statically linking the harfbuzz library provided by the harfbuzz-sys crate which is always up-to-date.

Optional Features

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].