The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HarfBuzz::Shaper - Use HarfBuzz for text shaping

SYNOPSIS

    use HarfBuzz::Shaper;
    my $hb = HarfBuzz::Shaper->new;
    $hb->set_font('LiberationSans.ttf');
    $hb->set_size(36);
    $hb->set_text("Hello!");
    my $info = $hb->shaper;

The result is an array of hashes, one element for each glyph to be typeset.

DESCRIPTION

HarfBuzz::Shaper is a perl module that provides access to a small subset of the native HarfBuzz library.

The subset is suitable for typesetting programs that need to deal with complex languages like Devanagari.

This module is intended to be used with module Text::Layout. Feel free to (ab)use it for other purposes.

Following the above example, the returned info is an array of hashes, one element for each glyph to be typeset. The hash contains the following items:

    ax:   horizontal advance
    ay:   vertical advance
    dx:   horizontal offset
    dy:   vertical offset
    g:    glyph index in font (CId)
    name: glyph name

Note that the number of glyphs does not necessarily match the number of input characters!

METHODS

$hb = HarfBuzz::Shaper->new( [ options ] )

Creates a new shaper object.

Options:

  • font = > font filename

  • size = > text size

$hb->set_font( font filename [ , size ] )

Explicit way to set the font (and, optionally, the size) used for shaping.

The font must be a TrueType or OpenType font. Font information is cached internally, after the first call subsequent calls with the same font filename are very fast.

$hb->set_size( size )

Explicit way to set the font size used for shaping.

Note that the font size will in general affect details of the appearance, A 5 point fontsize magnified 10 times is not identical to 50 point font size.

$hb->set_text( text [ , ... ] )

Set the text to shape. Multiple arguments are concatenated.

Note that the text must be Perl strings.

$hb->set_features( feat [ , ... ] )

Sets persistent features for shaping. Features are strings as described in https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-feature-from-string.

Multiple feature strings may be supplied.

$hb->add_features( feat [ , ... ] )

Just like set_features, but the specified features are added to the set of persistent features.

$hb->set_language( lang )

Sets the language for shaping. lang must be a string containing a valid BCP-47 language code.

$hb->get_language

Returns the language currently set for this shaper, as a string.

$info = $hb->shaper( [ ref to features ] )

Performs the shaping.

features is a reference to an array of feature strings. The features will be added to the list of features already set with set_features/add_features. If the first (or only) feature is none all current features will be ignored and only subsequent features are taken into account. Changes apply to this call only, the persistent set of featutes is not modified.

Upon completion an array of hashes is returned with one element for each glyph to be rendered.

The hash contains the following items:

    ax:   horizontal advance
    ay:   vertical advance
    dx:   horizontal offset
    dy:   vertical offset
    g:    glyph index in font (CId)
    name: glyph name

Note that the number of glyphs does not necessarily match the number of input characters!

SEE ALSO

Text::Layout

HarfBuzz website and documentation: https://harfbuzz.github.io/index.html.

BUGS AND DEFICIENCIES

It probably leaks memory. We'll see.

SUPPORT AND DOCUMENTATION

Development of this module takes place on GitHub: https://github.com/sciurius/perl-HarfBuzz-Shaper.

You can find documentation for this module with the perldoc command.

    perldoc HarfBuzz::Shaper

Please report any bugs or feature requests using the issue tracker on GitHub.

HarfBuzz website and documentation: https://harfbuzz.github.io/index.html.

COPYRIGHT AND LICENCE

Copyright (C) 2020 by Johan Vromans

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.