pdf-raku / PDF-Font-Loader-raku

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

Add an option to return a list of all font files meeting the search criteria. #28

Closed tbrowder closed 1 year ago

tbrowder commented 1 year ago

The user may have thousands of fonts available meeting the input criteria and want to make his own choice.

dwarring commented 1 year ago

Thanks Tom, I am working on FontConfig to add the ability to return a list of fonts, sorted by best-matching first.

tbrowder commented 1 year ago

Thanks, David, you're the best!

dwarring commented 1 year ago

Options added to latest PDF::Font::Loader 0.7.4 and FontConfig 0.1.4.

:best(20) will return up to the best 20 matching fonts. Example taken from doco which tries to find the best font with kerning:

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;

There's also an :all option the returns all fonts sorted by best match first, if you want to exhaustively scan all fonts on the system, see doco.

tbrowder commented 1 year ago

Thanks, David!