Expand description
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 choose another 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();
assert_eq!(positions.len(), infos.len());
// 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
Re-exports§
pub use crate::font_funcs::FontFuncs;
Modules§
- Contains the
FontFuncs
trait.
Structs§
- A
Blob
manages raw data like e.g. file contents. It refers to a slice of bytes that can be either owned by theBlob
or not. - A type that can be used to serialize a
GlyphBuffer
. - An iterator over the codepoints stored in a
UnicodeBuffer
. - A wrapper around
hb_face_t
. - A feature tag with an accompanying range specifying on which subslice of
shape
s input it should be applied. - A type representing a single font (i.e. a specific combination of typeface, font-size and font-variation settings)
- A
GlyphBuffer
contains the resulting output information of the shaping process. - A set of flags that may be set during shaping on each glyph.
GlyphPosition
is the structure that holds the positions of the glyph in both horizontal and vertical directions. All positions inGlyphPosition
are relative to the current point.- A smart pointer that wraps a singly owned harfbuzz object.
- Flags used for serialization with a
BufferSerializer
. - A smart pointer that wraps an atomically reference counted HarfBuzz object.
- A type to represent 4-byte SFNT tags.
- A
UnicodeBuffer
can be filled with unicode text and corresponding cluster indices. - A variation selector which can be applied to a specific font.
Enums§
- Defines the direction in which text is to be read.
- The serialization format used in
BufferSerializer
. - An Error generated when a
Tag
fails to parse from a&str
with thefrom_str
function. - This type provides an interface to create one of the buffer types from a raw harfbuzz pointer.
Traits§
- A trait which is implemented for all harffbuzz wrapper structs. It exposes common functionality for converting from and to the underlying raw harfbuzz pointers that are useful for ffi.
Functions§
- Shape the contents of the buffer using the provided font and activating all OpenType features given in
features
.