Rendering arbitrary-scale emojis using the Slug algorithm

This article outlines how the Slug algorithm can be incorporated into the HarfBuzz GPU library to render vector color fonts (emojis) at arbitrary scales, overcoming the limitations of traditional bitmap and SDF methods.
With the recent release of Eric Lengyel's Slug algorithm into the public domain, an open-source implementation has quickly made its way into the HarfBuzz repository as a new HarfBuzz GPU library. HarfBuzz is no longer just a text shaping library; it also handles glyph rendering now. Currently, the library only directly deals with rendering ordinary single-color glyphs. This post outlines how the Slug algorithm could be incorporated to render vector color fonts (commonly emojis) at arbitrary scales.
Traditionally, on-screen text is drawn by rasterizing glyphs on the CPU as bitmaps. This only looks good if bitmaps are not scaled significantly. An alternative is Signed Distance Field (SDF), but it rounds corners when scaled up. The Slug algorithm does away with prerendered bitmaps, calculating glyph coverage onto each pixel directly within the fragment shader. It is fast, robust, and allows perfect rendering at any scale or 3D transformation.
Rendering single-color glyphs is simple using HarfBuzz GPU by encoding outline curves into a texture buffer. For color fonts like COLRv0 and COLRv1, the process is more complex. COLRv0 uses simple layered glyphs, while COLRv1 involves a full render tree with transforms and gradients. HarfBuzz's hb-paint component helps by providing parsed drawing commands, allowing developers to implement complex emoji rendering by combining Slug's coverage calculation with advanced color fill techniques.
Source: Hacker News












