pdf-raku / PDF-Font-Loader-raku

Font loader for the PDF tool-chain
Artistic License 2.0
1 stars 3 forks source link

Add a :kern attribute to 'find-font' for limiting font searches to fonts with kerning ability #25

Open tbrowder opened 1 year ago

tbrowder commented 1 year ago

When

dwarring commented 1 year ago

Unfortunately, fontconfig doesn't have a good ability to select fonts with kerning and isn't really extensible. The newly introduced :best($n) and :all options does at least make it possible to get a list of fonts, that can then be filtered by additional critera. For example:

use PDF::Font::Loader;
use Font::FreeType;
use Font::FreeType::Face;
my Font::FreeType $ft .= new;
my $series = PDF::Font::Loader.find-font(:best(10), :!serif, :weight<bold>,);
my Str @best = $series.Array;
# prefer a font with kerning
my Str $best-font = @best.first: -> $file {
    my Font::FreeType::Face $face = $ft.face: $file;
    $face.has-kerning;
}
# fall-back to best matching font without kerning
$best-font //= @best.head;

note "best font: " ~ $best-font;