FontConfig-raku

[Raku PDF Project] / [FontConfig Module] / FontConfig

Description

FontConfig is the base class for FontConfig::Pattern (queries) and FontConfig::Match (matches).

Font Properties

Common font properties include:

Field Values / Constants Description
family Str Font family names
familylang Hash Family names by language code
style Str Font style. Overrides weight and slant
stylelang Str Styles by language code
fullname Str Font full names (often includes style)
fullnamelang| Hash Fullnames by language code
slant Int / roman=0, italic=100, oblique=110 Slant of glyphs
weight Int / thin=0, extralight=40, ultralight=40, light=50 demilight=55 book=70 regular=80 normal=80 medium=100 demibold=180 bold=200 extrabold=205 black=210 extrablack=215 Weight of glyphs
size Range Point size
width Int / ultracondensed=50, extracondensed=63, condensed=75, semicondensed=87, normal=100, semiexpanded=113, expanded=125, extraexpanded=150, ultraexpanded=200 Width of glyphs
pixelsize Num Pixel size
spacing Int / proportional=0, dual=90, mono=100, charcell=110 Spacing between glyphs
foundry Str Font foundry name
antialias Bool Whether glyphs can be antialiased
hinting Bool Whether the rasterizer uses hinting
file Str The filename holding the font
outline Bool Whether the glyphs are outlines
charset CharSet Unicode chars encoded by the font
color Bool Whether any glyphs have color
fontformat Str E.g. 'CFF', 'TrueType', 'Type 1'
fontversion Int Version number of the font
postscriptname Str Font postscript name
scalable Bool Whether glyphs can be scaled

The full list of properties is extensive and implementation dependant. For more properties,

Methods

constant

method constant(Str $name --> UInt)

Fontconfig has symbolic constants for numeric properties. For example, in the pattern: Ariel;weight=bold, bold, evaluates to 200. The constant() method can be used to look-up these constants.

my \bold = FontConfig.constant("bold"); # 200
if $match<bold> >= bold {
    say "matching font is bold";
}

Note that the Raku bindings resolve symbolic constants when a string is assigned to a numeric property. So:

$match<weight> = "extrabold";

Is equivalent to:

$match<weight> = FontConfig.constant("extrabold");

query-ft-face

method query-ft-face(Pointer() $face, Str() :$file, UInt :$id --> FontConfig)

This method computes a FontConfig pattern based on the attributes of an existing FreeType font. It can be used to discover FontConfig attributes for a specific font.

The match() method will find the best font, reachable by FontConfig’s configuration, that matches the original font, which may or may not be the original font.

The following example requires installation of the Font::FreeType module.

use FontConfig;
use Font::FreeType;
my $file = "t/fonts/Vera.ttf";
my Font::FreeType::Face $face = Font::FreeType.face($file);
my FontConfig $patt .= query-ft-face($face, :$file);
say $patt.fullname; # Bitstream Vera Sans
say $patt.file;     # t/fonts/Vera.ttf
say $patt.weight;   # 80

AT-KEY, ASSIGN-KEY, keys, elems, pairs, values

$patt<weight> = 205;
$patt<weight> = 'bold';
say $patt<weight>;
$patt<weight>:delete;

This class provides am associative interface to FontConfig properties.

Numeric values in the pattern may be set to ranges:

$patt<weight> = 195..205;

Values may also hold a list, such as a list of font families:

$patt<family> = <Arial sans>;

Str

The Str method serializes a pattern to a string representation;

say $patt.Str; # Arial,sans:style=italic:weight=205

version

method version returns Version

This method returns the installed fontconfig library version. Please note that the minimum supported version is v2.13.1.