This text mixes scripts. HarfBuzz shapes one script per run, so this preview may be incorrect.
Welcome to HarfBuzz World
Explore HarfBuzz shaping, subsetting, and rendering in your
browser. This site also demonstrates how to use
harfbuzz-world.cc,
a single-file amalgamation for C and C++ projects.
shape — inspect the glyph
stream in a table alongside an SVG preview.
subset — create and download
a font subset for the current text.
raster — render text to pixels
at the chosen size and download a PNG.
vector — export shaped text
as SVG or PDF.
gpu — render text on the GPU
using the Slug algorithm, with shaders for all platforms.
info — query names, metrics,
tables, characters, glyphs, layout data, variations, and palettes.
Each tab includes code examples and further reading.
Embedding
Add HarfBuzz as a submodule or vendored checkout, then compile
src/harfbuzz-world.cc
as C++. The amalgamation combines the library's source files
into a single translation unit:
c++ -std=c++11 -O2 \
-c third_party/harfbuzz/src/harfbuzz-world.cc \
-o harfbuzz-world.o
Link the resulting object into your application and use HarfBuzz's public C API:
#include <hb.h>
#include <hb-ot.h>
hb_blob_t *blob = hb_blob_create_from_file ("MyFont.ttf");
hb_face_t *face = hb_face_create (blob, 0);
hb_font_t *font = hb_font_create (face);
hb_buffer_t *buf = hb_buffer_create ();
hb_buffer_add_utf8 (buf, "Hello", -1, 0, -1);
hb_buffer_guess_segment_properties (buf); /* toy: real apps set script/lang/dir explicitly */
hb_shape (font, buf, NULL, 0);
unsigned len;
hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buf, &len);
hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buf, NULL);
/* …draw the glyphs… */
Customizing the build
Configure the amalgamation with preprocessor definitions.
Pass them on the command line (-DHB_TINY) or
define them in a small wrapper header that then includes
harfbuzz-world.cc.
HB_TINY— enable a compact build by disabling optional features, including deprecated APIs, variable fonts, AAT, legacy fallbacks, hinting, glyph names, math, name-table access, and metrics. It also selects compiler optimizations for size. All script shapers remain available. Use theHB_HAS_*flags below to include the subsystems you need.HB_HAS_SUBSET— includehb-subsetfor font subsetting.HB_HAS_RASTER— includehb-rasterfor software rendering.HB_HAS_VECTOR— includehb-vectorfor SVG and PDF output.HB_HAS_GPU— includehb-gpufor GPU rendering with the Slug algorithm.HB_HAS_FREETYPE,HB_HAS_GLIB,HB_HAS_ICU,HB_HAS_GRAPHITE,HB_HAS_CAIRO, and others — enable the corresponding library integrations.
To restore a feature disabled by HB_TINY,
undefine its HB_NO_* flag in your override
header. For example, undefine HB_NO_AAT
to enable shaping with Apple Advanced Typography
tables such as morx, kerx,
and trak, used by some macOS system fonts.
Building for the web (Emscripten)
The amalgamation also compiles to WebAssembly with
em++. This site's build enables shaping,
subsetting, raster rendering, vector output, and AAT
support. The GPU tab embeds a separate hb-gpu demo.
em++ -std=c++11 -Oz -flto \
-I third_party/harfbuzz/src \
-DHB_TINY -DHB_HAS_SUBSET -DHB_HAS_RASTER \
-DHB_HAS_VECTOR -DHB_HAS_GPU \
bindings.cc third_party/harfbuzz/src/harfbuzz-world.cc \
-sMODULARIZE=1 -sALLOW_MEMORY_GROWTH=1 \
-sEXPORTED_FUNCTIONS='["_my_shape_export","_malloc","_free"]' \
-o myhb.js
See this site's
scripts/build.sh
and
src/bindings.cc
for a complete working example.
Resources
- github.com/harfbuzz/harfbuzz — source, issues, releases.
- harfbuzz.github.io — user manual and API reference.
- BUILD.md — build and packaging instructions, including Meson.
- CONFIG.md
— an overview of compile-time configuration. See
src/hb-config.hh
(
HB_NO_*feature gates and theHB_TINY/HB_LEAN/HB_MINIpresets) and src/hb-features.h.in (theHB_HAS_*subsystem flags). - github.com/harfbuzz/harfbuzz-world.cc — source for this site.
Other languages
HarfBuzz is also available through these bindings and ports:
- HarfRust — a fully safe Rust port of the HarfBuzz shaper that also exposes a C API.
- uharfbuzz — Python bindings, used by FontTools.
- harfbuzzjs — JavaScript and WebAssembly bindings for browsers and Node.js.
Turn text into positioned glyphs with HarfBuzz. HarfBuzz maps characters to glyphs, then applies the font's substitution and positioning rules. The SVG shows the result; the table lists the glyphs, input characters, advances, and offsets.
Rows list glyphs from left to right in visual order, regardless of text direction.
1 Grapheme mode keeps combining marks with their base characters; character mode can keep them separate. Shaping may still merge clusters in either mode.
Code snippet
Learn more
Text shaping turns a Unicode string and a font into
positioned glyphs. HarfBuzz handles complex writing
systems, including Arabic, Indic, and Khmer, along with
OpenType features, variable fonts including version 2
of the avar table,
and Apple Advanced Typography (AAT).
Subset the current font for the text above with hb-subset, retaining the glyphs and layout rules needed to shape the text. The preview uses the resulting subset font, and the text remains selectable.
Could not create a subset. Try changing the text or choosing another font.
Font table sizes
Code snippet
Learn more
Font subsetting removes unused glyphs and font data while preserving the layout rules needed for shaping. Common uses include creating smaller web fonts and subsets for document embedding. The subsetter can also produce static instances of variable fonts, limit or reshape the variation space, and change default axis values.
Render text at the chosen size with hb-raster and download the result as a PNG. The canvas below displays the rendered pixels. This demo uses unhinted outlines; see hb-ft for FreeType integration.
Code snippet
Learn more
The software rasterizer supports COLRv1 gradients, compositing, and transforms, as well as embedded PNG glyph images. Monochrome outlines produce A8 coverage masks; color glyphs produce premultiplied BGRA32 pixels. It renders without hinting and is designed for high-DPI displays and embedded use.
Export shaped text as SVG or PDF with hb-vector. The SVG appears below. Both formats include the glyph artwork, so the files can be viewed without installing the original font.
Code snippet
Learn more
hb-vector produces SVG and PDF output from glyph outlines and COLRv1 color paint data. SVG is useful for previews, web graphics, and debugging. PDF output can encode color glyphs in Type 3 fonts while preserving scalable outlines for applications such as LibreOffice.
hb-gpu renders text using the Slug algorithm and supports DirectX, Metal, OpenGL, OpenGL ES, WebGL2, and WebGPU. This demo uses WebGL2 and decodes glyph outlines and color data in the fragment shader—no raster atlas required. The standalone hb-gpu demo offers more controls and a WebGPU build.
Click the preview to animate, drag to pan, scroll to zoom, and right-drag to rotate in 3D.
Code snippet
Learn more
hb-gpu targets games, UI frameworks, and other real-time applications. It renders glyph outlines and COLRv1 color paint data in fragment shaders. The client manages an atlas of encoded glyph data, while the GPU rasterizes glyphs at the requested scale. Shader sources are available in GLSL, WGSL, MSL, and HLSL.
Inspect technical information about the current font.
Names
Style
Metrics
Baselines
Tables
Characters
Glyphs
Layout scripts
Layout features
Variations
Color palettes
Meta
Code snippet
Learn more
hb-info reports names and technology by default, and can enumerate the font's tables, cmap, glyph set, OpenType layout, variation, palette, and metadata records. This view exposes those same categories through HarfBuzz's public C APIs.