View on GitHub


Bindings to the harfbuzz-subset font subsetting library

[Raku HarfBuzz Project] / [HarfBuzz-Subset Module]



Bindings to the HarfBuzz Subset font subsetting library.

This module is classed as Experimental, just because the harfbuzz-subset library is not commonly packaged yet, and needs to be built from source.


use HarfBuzz::Subset;

# face to be subsetted
my $file = "t/fonts/NimbusRoman-Regular.otf";

my @unicodes = 'Hello, World!'.ords;
my HarfBuzz::Subset $subset .= new: :face{ :$file }, :input{ :@unicodes };
my Blob() $buf = $subset;
'/tmp/my-nimbus-subset.otf'.IO.spurt: :bin, $buf;


This module binds to the HarfBuzz library’s subsetting capability and allows a font to be compacted to a smaller set of glyphs.

Subsetting is useful in a number of domains, including

class HarfBuzz::Subset Methods


method new( HarfBuzz::Font() :$font!, HarfBuzz::Subset::Input :$input() ) returns HarfBuzz::Subset:D;


Binary image of the subsetted font. This can be saved to a file with the same extension as the input font (typically .ttf or .otf) or embedded somehow (for example in a PDF file).

HarfBuzz subsetting currently works on TrueType, and OpenType font formats. It also accepts TrueType Collections (typically with file extension .ttc). In this case, the converted font will be a simple TrueType font, which should be saved with file extensyion .ttf.

HarfBuzz::Subset::Input Methods


method new(
    UInt :@unicodes,      # unicode code-points to include
    UInt :@glyphs,        # glyph identifiers to include
    Str  :@drop-tables,   # additional SFnt tables to drop
    Bool :$hints=True,    # retain font hinting
    Bool :$retain-gids,   # retain glyph identifiers
    Bool :$subroutines=True,
) returns HarfBuzz::Subset::Input:D;

Creates a font subsetting profile. Only the characters specified in :@unicodes and/or the glyph identifiers specified in :@glyphs are retained.


method COERCE( %(
    :@unicodes, :@glyphs, :@drop-tables,
    :$hints, :$retain-gids, :$subroutines,
) returns HarfBuzz::Subset::Input:D;

An object can be coerced from a Hash of options.

Installation and Dependencies