[gpu] Accept a single quadratic by how far the cubic leaves it (#6882) hb_gpu_cubic_approx_quadratic() tried the quadratic of the cubic's two end tangents and tested it at equal parameters: how far apart the two are at the same t. A cubic runs along that quadratic at another pace, so most of that distance is along the curve and costs nothing: of the cubics of three fonts, 2.4% passed at the tolerance of 0.5, while a third are within 0.5 of their quadratic as sets of points. With q where the tangents meet, a = q - c0, z = c3 - q, and the cubic's control points at c1 = c0 + l1 a and c2 = c3 - l2 z, the cubic B is the quadratic Q at another parameter plus an offset along the parabola's axis: B(t) = Q(tau(t)) + rho(t) (a - z) tau(t) = 3 t (1-t)^2 l1/2 + 3 t^2 (1-t) (1 - l2/2) + t^3 rho(t) = 3 t^2 (1-t)^2 (l1 + l2 - 4/3 + 3 e(t)^2) e(t) = (1-t) (l1/2 - 1/3) + t (1/3 - l2/2) an identity of polynomials. For l1 and l2 from 0 to 2, tau is a Bezier function with control values from 0 to 1, so it takes [0,1] onto [0,1], and each curve is within max |rho| |a - z| of the other: at most 3/16 max |l1 + l2 - 4/3 + 3 e^2| |a - z|. A single quadratic fits when the two handles add up to 4/3 of the way to where the tangents meet, however that is split; at equal parameters it took 2/3 each. Test that bound instead, in closed form. The recursive test and its depth cap go, and so does the check that skipped it for a long third difference, which bounded the distance at equal parameters. A cubic with a control point on its end point, whose tangent there is taken toward the other control point, now comes out as one quadratic with that tangent when it is small enough: 281 of the 862 such cubics in the three fonts. Of the 77,533 cubics, 24.1% become one quadratic, and quadratics per cubic go from 2.84 to 2.59. 15 cubics that passed the old test take two now. Testing: the identity checked exactly, in rational arithmetic on a grid that covers its degree; the bound against a measured two-sided distance on 18,000 cubics, from fonts and made to cover the range of handles, zero-length handles, far tangent intersections and extreme scales: never below it. Blobs of faces without cubics are byte-identical (745 fonts, 889,000 glyphs); of 235,312 glyphs in CFF/CFF2 faces 87,461 change, for 1.6% fewer bytes in all. util/hb-gpu-encode-all, instructions, five interleaved rounds against main: NotoSansSC-Regular.otf -5.61% SourceCodePro-Regular.otf -1.62% STIXTwoMath-Regular.otf -1.30% NotoSansCJK-VF.ttc -2.29% NotoSans[wght].ttf 0.00% (TrueType: no cubics) meson test: 301/301. test-gpu (34 subtests) and the fuzzer seeds under ASan and UBSan: pass. Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
HarfBuzz started as a text shaping engine but has grown into a full font platform — the ffmpeg of text shaping. It primarily supports OpenType, but also Apple Advanced Typography.
HarfBuzz shapes the majority of text on modern screens.
HarfBuzz is optimized for robustness, correctness, and performance — in that order. Achieve all.
Try it live at harfbuzz-world.cc — an interactive playground for shaping, subsetting, rasterization, vector output, and GPU rendering, all running in your browser.
Here is a quick map of its components:
| Library | Description |
|---|---|
| libharfbuzz | Text shaping, draw API, paint API. Highly configurable (see CONFIG.md). Optional integration backends compiled in: hb-ft (FreeType), hb-coretext (macOS), hb-uniscribe (Windows), hb-directwrite (Windows), hb-gdi (Windows), hb-glib, hb-graphite2. |
| libharfbuzz-subset | Font subsetting and variable-font instancing. |
| Library | Description |
|---|---|
| libharfbuzz-icu | ICU Unicode integration. |
| libharfbuzz-cairo | Cairo rendering integration. |
| libharfbuzz-gobject | GObject/GI bindings. |
| Library | Description |
|---|---|
| libharfbuzz-raster | Glyph rasterization to bitmaps, including color fonts. Uses hb-draw and hb-paint. |
| libharfbuzz-vector | Glyph output to vector formats (SVG and PDF), including color fonts. Uses hb-draw and hb-paint. |
| libharfbuzz-gpu | Encodes glyph outlines for GPU rasterization (Slug algorithm). Provides shader sources in GLSL, WGSL, MSL, and HLSL. Live demo. |
Notable missing feature: font hinting (including autohinting) is not implemented. For hinted rasterization, use FreeType or Skrifa.
For simplified builds, amalgamated sources are available: harfbuzz.cc (just libharfbuzz), harfbuzz-subset.cc (just libharfbuzz-subset), or harfbuzz-world.cc (everything, driven by a custom hb-features.h). For a live in-browser playground plus a worked example of the world.cc single-file build, see harfbuzz-world.cc.
| Tool | Description |
|---|---|
| hb-shape | Shape text and display glyph output. |
| hb-view | Render shaped text to an image. |
| hb-subset | Subset and optimize fonts. |
| hb-info | Display font metadata. |
| hb-raster | Render glyphs to bitmap images. |
| hb-vector | Render glyphs to vector formats (SVG). |
| hb-gpu | Interactive GPU text rendering. |
The canonical source tree and bug trackers are available on github. Both development and user support discussion around HarfBuzz happen on github as well.
For license information, see COPYING.
The API that comes with hb.h will not change incompatibly. Other, peripheral, headers are more likely to go through minor modifications, but again, we do our best to never change API in an incompatible way. We will never break the ABI.
The API and ABI are stable even across major version number jumps. In fact, current HarfBuzz is API/ABI compatible all the way back to the 0.9.x series. If one day we need to break the API/ABI, that would be called a new library.
As such, we bump the major version number only when we add major new features, the minor version when there is new API, and the micro version when there are bug fixes.
For user manual as well as API documentation, check: https://harfbuzz.github.io
Tarball releases and Win32/Win64 binary bundles are available on the github releases page.
For build information, see BUILD.md.
For custom configurations, see CONFIG.md.
For testing and profiling, see TESTING.md.
For using with Python, see README.python.md. There is also uharfbuzz.
For cross-compiling to Windows from Linux or macOS, see README.mingw.md.
To report bugs or submit patches please use github issues and pull-requests.
To get a better idea of where HarfBuzz stands in the text rendering stack you may want to read State of Text Rendering 2024. Here are a few presentation slides about HarfBuzz over the years:
More presentations and papers are available on behdad's website. In particular, the following studies are relevant to HarfBuzz development:
hb-decyclerhb-iterhb-ft >h_advance functionHarfBuzz /hærfˈbɒːz/
From Persian حرف (Harf: letter) and باز (Buzz: open). Transliteration of the Persian calque for OpenType.
As a noun: The Open Source text shaping engine.
As an adjective: Insincerely talkative; glib. A nod to the GNOME project where HarfBuzz originates from.
The logo shows حرفباز in the IranNastaliq font, on a Damascus steel background.
Background: Originally there was this font format called TrueType. People and companies started calling their type engines all things ending in Type: FreeType, CoolType, ClearType, etc. And then came OpenType, which is the successor of TrueType. So, for my OpenType implementation, I decided to stick with the concept but use the Persian translation. Which is fitting given that Persian is written in the Arabic script, and OpenType is an extension of TrueType that adds support for complex script rendering, and HarfBuzz is an implementation of OpenType text shaping.
HarfBuzz is used in Android, Chrome, ChromeOS, Firefox, Flutter, GNOME, GTK+, KDE, Qt, LibreOffice, OpenJDK, XeTeX, Adobe Photoshop, Illustrator, InDesign, Microsoft Edge, Amazon Kindle, PlayStation, Godot Engine, Unreal Engine, Figma, Canva, QuarkXPress, Scribus, smart TVs, car displays, and many other places.