$hb=HarfBuzz::Shaper->new([options])
Creates a new shaper object.
Options:
• font= > fontfilename
• size= > textsize$hb->reset([full])
Reset (clear) the buffer settings for font, size, language, direction and script. With full, also clears
the font cache.
$hb->set_font(fontfilename[,size])
Explicit way to set the font (and, optionally, the size) used for shaping.
The settings persist across shaper() calls. Call without arguments to remove the settings.
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.
The setting persist across shaper() calls. Call without arguments to remove the setting.
$hb->set_text(text[,...])
Sets the text to shape. Multiple arguments are concatenated.
Note that the text must be Perl strings.
The setting persist across shaper() calls. Call without arguments to remove the setting.
$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> and
<https://css-tricks.com/almanac/properties/f/font-feature-settings/#values>.
Multiple feature strings may be supplied.
Call without arguments to remove the persistent features.
$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.
The setting persist across shaper() calls. Call without arguments to remove the setting.
$hb->get_language
Returns the language currently set for this shaper, as a string.
When called after a successful shaper() call, it returns the actual value used by shaper().
$hb->set_script(script)
Sets the script (alphabet) for shaping. script must be a string containing a valid ISO-15924 script code.
For example, "Latn" for the Latin (Western European) script, or "Arab" for arabic script.
If you don't set a script, shaper() will make a guess based on the text string. This may or may not yield
desired results.
The setting persist across shaper() calls. Call without arguments to remove the setting.
$hb->get_script
Returns the script currently set for this shaper, as a string.
When called after a successful shaper() call, it returns the actual value used by shaper().
$hb->set_direction(dir)
Sets the direction for shaping. dir must be a string containing a valid direction setting: LTR (left-to-
right), RTL (right-to-left), TTB (top-to-bottom), or BTT (bottom-to-top).
If you don't set a direction, shaper() will make a guess based on the text string. This may or may not
yield desired results.
The setting persist across shaper() calls. Call without arguments to remove the setting.
$hb->get_direction
Returns the direction currently set for this shaper, as a string.
When called after a successful shaper() call, it returns the actual value used by shaper().
$info=$hb->shaper([reftofeatures])
Performs the actual shape operation.
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!
$info=$hb->get_extents
Get the extents of the (shaped) buffer.
Upon completion an array of hashes is returned with one element for each glyph.
The hash contains the following items:
x_bearing Distance from the x-origin to the left extremum of the glyph.
y_bearing Distance from the top extremum of the glyph to the y-origin.
width; Distance from the left extremum of the glyph to the right extremum.
height Distance from the top extremum of the glyph to the bottom extremum.
g Glyph index in font (CId)
The values are scaled to the font size as set with set_size().
Note that the number of glyphs does not necessarily match the number of input characters!
$info=$hb->get_font_extents(dir)
Get the extents of the font in the given direction.
dir may be omitted, it defaults to the direction currently set, or 'ltr' if no direction was set.
Upon completion returns a hash with the following items:
ascend The height of typographic ascenders.
descend The height of typographic ascenders.
line_gap The suggested line-spacing gap.
The values are scaled to the font size as set with set_size().
Note that typically ascender is positive and descender negative, in coordinate systems that grow up.