class HexaPDF::Layout::TextShaper

Parent

This class is used to perform text shaping, i.e. changing the position of glyphs (e.g. for kerning) or substituting one or more glyphs for other glyphs (e.g. for ligatures).

The class contains two shaping engines: A very limited custom one and one based on HarfBuzz. Which one is used for shaping can be selected via the Style#shaping_engine property.

The custom implementation is always used for Type1 fonts and supports kerning and ligature substitution. It also supports the ‘kern’ table for TrueType fonts if HarfBuzz is not used.

For complex scripts or the need of special font features it is recommended to use the shaping engine based on HarfBuzz, even though it is slightly slower. For it to work the harfbuzz-ruby gem needs to be installed. OpenType features can be activated and deactivated using Style#font_features.

Public Instance Methods

shape_text(text_fragment)

Shapes the given text fragment. Returns either the in-place modified fragment or, for complex shaping, an array of fragments.

The style properties Style#shaping_engine, Style#font_features, Style#font_script, Style#language and Style#direction are used for shaping.