HexaPDF 0.5.0 - Advanced Text Layout

Published on

HexaPDF continues to grow and mature, with this release bringing advanced text layout as first step into providing full document layout features.

Support HexaPDF —   Become a Patron!

Advanced text layout means that HexaPDF is now able to:

  • Apply kerning and ligatures to text, with the possibility to easily add other positioning or substitution steps (e.g. for correctly positioning diacritical marks)

  • Apply different styles to different parts of the text of a paragraph (example)

  • Wrap lines while supporting special characters like non-breaking spaces, soft-hyphens and zero-width spaces (example)

  • Use arbitrarily shaped boxes for text layout (example)

  • Align text horizontally and vertically, e.g. left, center, right and justify; and top, center, bottom (example)

  • Mix text and inline boxes, e.g. for showing images or arbitrary drawings together with text (example)

  • Calculate the height of a text box without drawing it, or limiting the height and retrieving the overflowing items

In essence HexaPDF::Layout::TextBox together with the other classes in HexaPDF::Layout is similar to Prawn’s formatted text box implementation. However, HexaPDF still lacks some text box features like text colors, links or underlining. This will be fixed with a future release.

To see how HexaPDF’s implementation compares to Prawn’s in terms of performance I adapted the text rendering benchmark to use the text box implementations. The results (see the text box benchmark for details and caveats) are rather promising, with HexaPDF being about 10 times faster than Prawn!

HexaPDF’s text box implementation can already be used to compose whole documents but it is still only another stepping stone on the way to full document layout features. There are major parts missing for this, like automatic page breaking, tables, column layout and a composition class to make using all these parts easier.

As always, have a look at the changelog for an overview of all changes. And if you have a request, drop me an e-mail or open an issue!