HarfBuzz
Open source text shaping library
From Wikipedia, the free encyclopedia
HarfBuzz (loose transliteration of Persian calque حرفباز harf-bāz, literally "open type")[3][4] is an open-source text shaping engine written in C++. Text shaping is the process of converting a sequence of Unicode code points into the correct glyph identifiers and precise positions needed to render text on screen or in print. For scripts where characters change shape depending on their neighbours (such as Arabic, Devanagari, or Tamil), text shaping ensures that the right glyph forms are selected and joined correctly. Without it, text renderers would display raw disconnected code points rather than readable words.
| HarfBuzz | |
|---|---|
| Original author | The FreeType Project |
| Developers | Behdad Esfahbod, Khaled Hosny[1] |
| Stable release | 13.0.1[2] |
| Written in | C++ |
| Operating system | Unix-like, Windows, OpenHarmony |
| Type | Software development library |
| License | MIT |
| Website | harfbuzz |
| Repository | github |
HarfBuzz takes a string of Unicode text, a font file, and information about the writing script and language as input. It returns a list of glyph IDs and their x/y positions, which a rendering engine such as Cairo or Skia then uses to draw the text. The library supports multiple font technologies, including OpenType, Apple Advanced Typography (AAT), and SIL Graphite.
The project originated in the FreeType codebase and went through several development phases before Behdad Esfahbod rewrote it from scratch around 2012. It is now used by major operating systems, browsers, and desktop toolkits worldwide.[3]
History
HarfBuzz evolved from shaping code that was originally part of the FreeType project. That code was forked separately into both Qt and Pango, leaving two diverging implementations. The two forks were eventually merged back into a shared repository under an MIT license, forming what is now called Old HarfBuzz. Old HarfBuzz supported only OpenType fonts and is no longer maintained.[3]
Around 2010–2012, Behdad Esfahbod rewrote the library from scratch in C++, producing New HarfBuzz. The rewrite discarded the old architecture and was designed from the outset to support multiple font technologies and complex script shaping rules. In 2013, Esfahbod received the O'Reilly Open Source Award for his work on HarfBuzz.[5] The same year, Android adopted HarfBuzz as its text shaping engine, bringing the library to hundreds of millions of devices.[3]
Over the following years, the library's script and font format coverage grew. Early releases added SIL Graphite support, and the 1.0 release in 2015 incorporated the Universal Shaping Engine, a generalised shaping model developed by Microsoft that covers dozens of scripts not individually defined in the OpenType specification.[6] Subsequent work broadened the range of supported font technologies to include OpenType font variations,[7] Apple Advanced Typography shaping,[8] and colour fonts. A font subsetter API, stabilised in 2021, allows tools to produce optimised font subsets for web and embedded use.[9] In 2023, an experimental shaper was added that allows fonts to embed WebAssembly programs to handle their own shaping logic.[10]
Architecture
HarfBuzz is a C++ library with a C API. A caller provides three inputs: a buffer containing Unicode text, a font object loaded from a font file, and optional metadata about the writing script and language. HarfBuzz returns the same buffer populated with glyph IDs and x/y advance and offset values. The caller then passes those values to a drawing library to paint the glyphs.
Internally, HarfBuzz selects a shaping engine based on the font format and script:
- The OpenType shaper handles the majority of scripts. It reads the GSUB (glyph substitution) and GPOS (glyph positioning) tables from the font and applies their rules in the order specified by the OpenType specification for each script.
- The Universal Shaping Engine (USE) shaper covers scripts in the OpenType specification that do not have dedicated shaping logic, using a generalised finite-state model.
- The Apple Advanced Typography (AAT) shaper reads AAT morx and kerx tables, enabling HarfBuzz to shape fonts distributed in Apple's format.
- The SIL Graphite shaper hands off processing to the embedded Graphite engine, which evaluates rules stored inside Graphite-enabled fonts.
- An experimental WebAssembly shaper allows a font to include a Wasm binary that takes full control of shaping for that font.
The library also includes a subsetter API that produces optimised font subsets containing only the glyphs needed for a particular document, reducing file sizes in web and embedded contexts.
Users
Most applications use HarfBuzz indirectly through a UI toolkit or text layout library that integrates it, rather than calling HarfBuzz directly. The library is used across a range of platforms, from mobile operating systems to professional desktop publishing software.
HarfBuzz is used by the UI libraries of:
- GNOME (GTK)
- KDE (Qt)
- ChromeOS (Skia)
- PlayStation 4[11]
- Android[3]
- Java[12]
- Flutter[13]
- Godot (since version 4.0)[14][15]
- Unity (since version 6.0)[16]
- OpenHarmony (HarmonyOS)[17]
HarfBuzz is used directly by many applications, including:
- Chromium
- Firefox
- LibreOffice (from version 4.1 on Linux,[18] from 5.3 on all platforms[19])
- Scribus (since version 1.5.3)[20]
- Inkscape
- Adobe Photoshop (since version 23.0)[21]
- Adobe InDesign (when using World Ready Composer since InDesign 19.0)[22]
- Figma[23]
- XeTeX (since version 0.9999)[24][25]
- LuaTeX (since version 1.11.1)[26][27]
- QuarkXPress[28]
See also
- Cairo (graphics)
- Graphite (smart font technology), a programmable Unicode-compliant smart-font technology and rendering system developed by SIL International
- Uniscribe and DirectWrite, APIs providing similar functionality on Microsoft Windows
- Core Text, the macOS equivalent (HarfBuzz can be used as an alternative on macOS)