View on GitHub

Font-FreeType-raku

Read font files and render glyphs using FreeType2

[Raku PDF Project] / [Font-FreeType Module] / Font::FreeType

class Font::FreeType - Raku FreeType2 Library Instance

Synopsis

use Font::FreeType;
use Font::FreeType::Face;

my Font::FreeType $freetype .= new;
my Font::FreeType::Face $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

A Font::FreeType object must first be created before other objects may be crated. Fort example to load a Font::FreeType::Face object:

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

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:

face()

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

Return a Font::FreeType::Face object representing a font face from the specified file (Str or IO::Path) or a Blob.

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);

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”.

Authors

Geoff Richards qef@laxan.com

Ivan Baidakou dmol@cpan.org

David Warring david.warring@gmail.com (Raku Port)

Copyright 2004, Geoff Richards.

Ported from Perl to Raku 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.