Scroll to navigation

Font::FreeType::Face(3pm) User Contributed Perl Documentation Font::FreeType::Face(3pm)

NAME

Font::FreeType::Face - font typefaces loaded from Font::FreeType

SYNOPSIS

    use Font::FreeType;
    my $freetype = Font::FreeType->new;
    my $face = $freetype->face('Vera.ttf');

DESCRIPTION

This class represents a font face (or typeface) loaded from a font file. Usually a face represents all the information in the font file (such as a TTF file), although it is possible to have multiple faces in a single file.

Never 'use' this module directly; the class is loaded automatically from Font::FreeType. Use the "Font::FreeType->face()" method to create a new Font::FreeType::Face object from a filename.

METHODS

Unless otherwise stated, all methods will die if there is an error.

The height above the baseline of the 'top' of the font's glyphs, scaled to the current size of the face.
Informs FreeType of an ancillary file needed for reading the font. Hasn't been tested yet.
The index number of the current font face. Usually this will be zero, which is the default. See "Font::FreeType->face()" for how to load other faces from the same file.
The depth below the baseline of the 'bottom' of the font's glyphs, scaled to the current size of the face. Actually represents the distance moving up from the baseline, so usually negative.
A string containing the name of the family this font claims to be from.
In scalar context returns the number of fixed sizes (of embedded bitmaps) available in the font. In list context returns a list of hashes which detail those sizes. Each hash can contain the following keys, but they will be absent if the information isn't available:
Size of the glyphs in points. Only available with Freetype 2.1.5 or newer.
Height of the bitmaps in pixels.
Width of the bitmaps in pixels.
Resolution the bitmaps were designed for, in dots per inch. Only available with Freetype 2.1.5 or newer.
Resolution the bitmaps were designed for, in pixels per em. Only available with Freetype 2.1.5 or newer.
Iterates through all the characters in the font, and calls code-ref for each of them in turn. Glyphs which don't correspond to Unicode characters are ignored.

Each time your callback code is called, $_ will be set to a Font::FreeType::Glyph object for the current glyph. For an example see the program list-characters.pl provided in the distribution.

Iterates through all the glyphs in the font, and calls code-ref for each of them in turn.

Each time your callback code is called, $_ will be set to a Font::FreeType::Glyph object for the current glyph.

Returns a Font::FreeType::Glyph object for the glyph corresponding to the first character in the string provided. Note that currently non-ASCII characters are not likely to work with this, so you might be better using the "glyph_from_char_code()" method below and the Perl "ord" function.

Returns undef if the glyph is not available in the font and fallback isn't defined; otherwise, i.e. if fallback = true returns fonts missing glyph.

Returns a Font::FreeType::Glyph object for the glyph corresponding to Unicode character char-code. FreeType supports using other character sets, but this module doesn't yet.

Returns undef if the glyph is not available in the font and fallback isn't defined; otherwise, i.e. if fallback = true returns fonts missing glyph.

Looks up a glyph by name and returns the index for that glyph in the font. Returns 0 if the name is not found.
Returns a Font::FreeType::Glyph object for the glyph at the given index.
Looks up a glyph by name and returns a Font::FreeType::Glyph object.

Returns undef if the glyph is not available in the font and fallback isn't defined; otherwise, i.e. if fallback = true returns fonts missing glyph.

True if individual glyphs have names. If so, the names can be retrieved with the "name()" method on Font::FreeType::Glyph objects.

See also "has_reliable_glyph_names()" below.

These return true if the font contains metrics for the corresponding directional layout. Most fonts will contain horizontal metrics, describing (for example) how the characters should be spaced out across a page when being written horizontally like English. Some fonts, such as Chinese ones, may contain vertical metrics as well, allowing typesetting down the page.
True if the font provides kerning information. See the "kerning()" method below.
True if the font contains reliable PostScript glyph names. Some Some fonts contain bad glyph names. This method always returns false when used with Freetype versions earlier than 2.1.1.

See also "has_glyph_names()" above.

The line height of the text, i.e. distance between baselines of two lines of text.
True if the font claims to be in a bold style.
True if all the characters in the font are the same width. Will be true for monospaced fonts like Courier.
Returns true if the font claims to be in an italic style.
True if the font has a scalable outline, meaning it can be rendered nicely at virtually any size. Returns false for bitmap fonts.
True if the font file is in the 'sfnt' format, meaning it is either TrueType or OpenType. This isn't much use yet, but future versions of this library might provide access to extra information about sfnt fonts.
Returns the suggested kerning adjustment between two glyphs. When called in scalar context returns a single value, which should be added to the position of the second glyph on the x axis for horizontal layouts, or the y axis for vertical layouts.

Note: currently always returns the x axis kerning, but this will be fixed when vertical layouts are handled properly.

For example, assuming $left and $right are two Font::FreeType::Glyph objects:

    my $kern_distance = $face->kerning($left->index, $right->index);
    

In list context this returns two values corresponding to the x and y axes, which should be treated in the same way.

The "mode" argument controls how the kerning is calculated, with the following options available:

Grid-fitting (hinting) and scaling are done. Use this when rendering glyphs to bitmaps to make the kerning take the resolution of the output in to account.
Scaling is done, but not hinting. Use this when extracting the outlines of glyphs. If you used the "FT_LOAD_NO_HINTING" option when creating the face then use this when calculating the kerning.
Leave the measurements in font units, without scaling, and without hinting.
Retrieve the load_flags option used.
Setting the load_flags option. Returns the newly set value.
The number of faces contained in the file from which this one was created. Usually there is only one. See "Font::FreeType->face()" for how to load the others if there are more.
The number of glyphs in the font face.
A string containing the PostScript name of the font, or undef if it doesn't have one.
Set the size at which glyphs should be rendered. Metrics are also scaled to match. The width and height will usually be the same, and are in points. The resolution is in dots-per-inch.

When generating PostScript outlines a resolution of 72 will scale to PostScript points.

Set the size at which bitmapped fonts will be loaded. Bitmap fonts are automatically set to the first available standard size, so this usually isn't needed.
A string describing the style of the font, such as 'Roman' or 'Demi Bold'. Most TrueType fonts are just 'Regular'.
The suggested position and thickness of underlining for the font, or undef if the information isn't provided. Currently in font units, but this is likely to be changed in a future version.
The size of the em square used by the font designer. This can be used to scale font-specific measurements to the right size, although that's usually done for you by FreeType. Usually this is 2048 for TrueType fonts.
The current active charmap for this face.
An array of the charmaps of the face.
The outline's bounding box for this face.

SEE ALSO

Font::FreeType, Font::FreeType::Glyph Font::FreeType::CharMap

AUTHOR

Geoff Richards <qef@laxan.com>

COPYRIGHT

Copyright 2004, Geoff Richards.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2020-11-08 perl v5.32.0