Streamlined Cython bindings for the harfbuzz shaping engine
Actively maintained. Last release 5 weeks ago, commits in 9 of the last 26 weeks. A safe choice.
pip install uharfbuzzuharfbuzz
Streamlined Cython bindings for the HarfBuzz shaping engine.
Example
import sys
import uharfbuzz as hb
fontfile = sys.argv[1]
text = sys.argv[2]
blob = hb.Blob.from_file_path(fontfile)
face = hb.Face(blob)
font = hb.Font(face)
buf = hb.Buffer()
buf.add_str(text)
buf.guess_segment_properties()
features = {"kern": True, "liga": True}
hb.shape(font, buf, features)
infos = buf.glyph_infos
positions = buf.glyph_positions
for info, pos in zip(infos, positions):
gid = info.codepoint
glyph_name = font.glyph_to_string(gid)
cluster = info.cluster
x_advance = pos.x_advance
y_advance = pos.y_advance
x_offset = pos.x_offset
y_offset = pos.y_offset
print(
f"{glyph_name=} {gid=} {cluster=} "
f"{x_advance=} {y_advance=} "
f"{x_offset=} {y_offset=}"
)
Installation
When building the uharfbuzz package, it automatically incorporates minimal HarfBuzz sources so you don't have to install the native HarfBuzz library.
However, if you want to use uharfbuzz with your system-provided HarfBuzz (e.g., if you built it from sources with custom configuration), you can set USE_SYSTEM_LIBS=1 environment variable (see example below).
USE_SYSTEM_LIBS=1 pip install uharfbuzz --no-binary :uharfbuzz:
harfbuzz installation is found using pkg-config, so you must have harfbuzz's .pc files in your system.
If you've built it from sources, meson installs them automatically. Otherwise, you may want to install harfbuzz development package, like harfbuzz-devel on Fedora-derived distros.
How to make a release
Use git tag -a to make a new annotated tag, or git tag -s for a GPG-signed annotated tag, if you prefer.
