[vector] Paint linear and radial gradients that repeat in PDF PDF shadings do not repeat. A linear or radial gradient whose color line repeats or reflects was written as a shading over the color line alone, with nothing painted on either side of it. Paint it a period of the color line at a time, for the periods that reach what is painted, with the color line backwards in every other one if it reflects. What is painted is known from the bounds of the open clips, which are kept for sizing sweep gradients: the periods are those whose lines, or circles, touch the bounds. No more than 256 are written, those nearest the color line itself. One shading over a function that repeats the color line would be less to write, and is what cairo writes. Viewers do badly with it. pdfium and MuPDF resolve the function of a shading in 256 steps whatever it holds, so every period makes all of them coarser. And poppler splits a shading for as long as the colors at the two ends of a piece differ, which they do not when a whole number of periods lie between them, as when the periods fit the clip: it paints that piece in one color. It does so with cairo's own output. How the periods are written is what it took for the viewers tried to agree with hb-raster: - The periods of a linear gradient are one shading, painted at one place after another. Each written with rounded numbers of its own, they are not quite parallel, and MuPDF left holes between them. - Each period goes a little into the next, which is painted over it: viewers decide pixel by pixel which side of the line between two shadings a pixel is on. - Under a transform that rotates, the periods of a linear gradient are painted in the space of the root. Ghostscript gets the length of an axial shading wrong under such a transform, depending on how much of it the clip lets through, and a period is seldom seen whole. - Circles inside one another make rings, painted from the outside in and each with its hole filled: MuPDF leaves holes between rings that merely meet. They are written growing, the color line backwards if need be: poppler drops a radial shading that shrinks and is extended at one end only. - The periods of a radial gradient are painted on top of each other, so they are painted in a group, and the group once: under a clip each would add to its antialiased edge. So are periods that are not opaque, their alphas in a soft mask. The documentation no longer says that these are not supported. Testing: of the mapped glyphs of the COLR test fonts, 106 have a different PDF, in five fonts. 19 of them had the pixels of hb-raster before, in each of pdfium, MuPDF, poppler's cairo backend and Ghostscript. All 106 do now, but for six in pdfium: the two glyphs of a cone that repeats, in three fonts, where hb-raster paints the cone's mirror image as well until #6845. Replaying the same paint calls on hb-raster and hb-vector for 300 random scenes of clipped and transformed linear gradients and rings that repeat or reflect, the pixels are the same in 300 with MuPDF and with poppler's cairo backend, 299 with its Splash backend, and 298 with pdfium and with Ghostscript. With one shading over a repeating function they were in 291 with pdfium, and poppler painted flat what a whole number of periods filled. With cones as well, and #6845 for hb-raster, they are the same in 300 with Ghostscript, 299 with MuPDF and 292 with pdfium and with Splash. poppler's cairo backend is at 165: it paints cones that shrink in one color, repeating or not. The search for the circles that touch the bounds agrees with brute force on 30000 random cases. A new test checks which periods are written and how, and fails without the change; six glyphs are added as an expected output. It and the vector fuzzer are clean under ASan and UBSan, the test under MSan, and the fuzzer ran three minutes with failing allocations. Full test suite passes. 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.