Help language development. Donate to The Perl Foundation

Font::FreeType cpan:WARRINGD last updated on 2018-11-13

Font-FreeType-0.1.1/

Build Status

NAME

Font::FreeType - read font files and render glyphs from Perl using FreeType2

SYNOPSIS

use Font::FreeType;

my Font::FreeType $freetype .= new;
my $face = $freetype.face('t/fonts/Vera.ttf');

$face.set-char-size(24, 24, 100, 100);
for $face.glyph-images('ABC') {
    my $outline = .outline;
    my $bitmap = .bitmap;
    # ...
}

DESCRIPTION

This module allows Perl programs to conveniently read information from font files. All the font access is done through the FreeType2 library, which supports many formats. It can render images of characters with high-quality hinting and anti-aliasing, extract metrics information, and extract the outlines of characters in scalable formats like TrueType.

The quickest way to get started with this library is to look at the examples in the examples directory of the distribution. Full details of the API are contained in this documentation, and (more importantly) the documentation for the Font::FreeType::Face class.

To use the library, first create a Font::FreeType object. This can be used to load faces from files, for example:

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

If your font is scalable (i.e., not a bit-mapped font) then set the size and resolution you want to see it at, for example 24pt at 100dpi:

$face.set-char-size(24, 24, 100, 100);

Then load particular glyphs (an image of a character):

for $face.glyph-images('ABC') {
    # Glyphs can be rendered to bitmap images, among other things:
    my $bitmap = .bitmap;
    say $bitmap.Str;
}

METHODS

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

new()

Create a new 'instance' of the freetype library and return the object. This is a class method, which doesn't take any arguments. If you only want to load one face, then it's probably not even worth saving the object to a variable:

my $face = Font::FreeType.new.face('Vera.ttf');

face(filename|blob, :$index, :load-flags)

Return a Font::FreeType::Face object representing a font face from the specified file or Blob.

The :index option specifies which face to load from the file. It defaults to 0, and since most fonts only contain one face it rarely needs to be provided.

The :load-flags option takes various flags which alter the way glyphs are loaded. The default is usually OK for rendering fonts to bitmap images. When extracting outlines from fonts, be sure to set the FT_LOAD_NO_HINTING flag.

The following load flags are available. They can be combined with the bit-wise OR operator (|). The symbols are exported by the module and so will be available once you do use Font::FreeType.

version()

Returns the version number of the underlying FreeType library being used. If called in scalar context returns a Version consisting of a number in the format "major.minor.patch".

SCRIPTS

font-say

font-say [--resolution=<Int>] [--kern] [--hint] [--ascend=<Int>] [--descend=<Int>] [--char-spacing=<Int>] [--word-spacing=<Int>] [--bold=<Int>] [--mode=<Mode> (lcd lcd-v light mono normal)] [--verbose] <font-file> <text>

This script displays text as bitmapped characters, using a given font. For example:

% bin/font-say t/fonts/Vera.ttf 'FreeType!'
##########                                     ##############                                       ##
##########                                     ##############                                       ##
###             ###      ###          ###            ###                      ####         ###      ##
###        ########    #######      #######          ###    ###      ###  #########      #######    ##
###        ########   #########    #########         ###     ###    ###   ##########    #########   ##
#########  ####      ####   ###   ####   ###         ###     ###    ###   ####   ####  ####   ###   ##
#########  ####      ###     ###  ###     ###        ###     ####  ###    ####    ###  ###     ###  ##
#########  ###       ###########  ###########        ###      ###  ###    ###     ###  ###########  ##
###        ###       ###########  ###########        ###      ###  ###    ###     ###  ###########  ##
###        ###       ###          ###                ###       ######     ###     ###  ###          ##
###        ###       ###          ###                ###       ######     ####    ###  ###
###        ###       ####     #   ####     #         ###       #####      ####   ####  ####     #   ##
###        ###        #########    #########         ###        ####      ##########    #########   ##
###        ###         ########     ########         ###        ####      #########      ########   ##
                        #####        #####                      ###       ### ####        #####
                                                                ###       ###
                                                             #####        ###
                                                             #####        ###
                                                             ###          ###

INSTALL

Font::FreeType depends on the freetype native library, so you must install that prior to using this module.

SEE ALSO

AUTHORS

Geoff Richards qef@laxan.com

Ivan Baidakou dmol@cpan.org

David Warring david.warring@gmail.com (Perl 6 Port)

COPYRIGHT

Copyright 2004, Geoff Richards.

Ported from Perl 5 to 6 by David Warring david.warring@gmail.com Copyright 2017.

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