pdf-raku / Font-FreeType-raku

Read font files and render glyphs using FreeType2
Artistic License 2.0
2 stars 3 forks source link

Create (or add to an existing method) an option to use ligatures with a font if available #24

Open tbrowder opened 9 months ago

tbrowder commented 9 months ago

I'm experimenting with GNU Freefonts which are OpenType and have kerning and ligatures. When I produce font samples in PDF I use the :kern option which works fine, but I don't see any way to automatically use ligatures if they are available.

dwarring commented 9 months ago

I'm considering the use of the HarfBuzz module, which does general purpose shaping including kerning, ligatures and combining characters. It works well on OpenType, although it doesn't seem to handle Type1 fonts.

tbrowder commented 9 months ago

Sounds like a plan. I did see reference to a ligature substitution method with opentype fonts using FreeType at https://learn.microsoft.com.

dwarring commented 6 months ago

Latest PDF::Content (0.8.1) introduces a :shape option. Latest PDF::Font::Loader (0.8.2) is also needed for non-core fonts.

For core fonts and Type1 fonts, the :shape option just means discretionary ligature substitution + kerning.

For TrueType and OpenType fonts, HarfBuzz is used to to 'shaping' I.e. font glyph substitution and placement. Ligatures do become a bit more complicated with these font types. They may contain arbitrary discretionary ligatures for pairs of glyphs ( a bit like kerning tables).

I've gone with HarfBuzz as part of a push to better internationalization. For example the shaping rules for Arabic alphabets become more complex. Hopefully this can now been handled.

tbrowder commented 6 months ago

So, for OpenType fonts, if I use ":shape, :!kern", does the shaping include kerning effects via HarfBuzz?

dwarring commented 6 months ago

No, that will disable kerning, but keep other shaping, including ligatures.

tbrowder commented 1 month ago

So then I can use both :shape and :kern now, true?