View on GitHub

Font-FreeType-raku

Read font files and render glyphs using FreeType2

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

class Font::FreeType::BitMap

Bitmaps from rendered glyphs

Synopsis

use Font::FreeType;

my Font::FreeType $freetype .= new;
my $face = $freetype.face('Vera.ttf');
$face.set-char-size(24, 24, 100, 100);

for $face.glyph-images('Hi') {
    print .outline.svg
        if .is-outline;

    # Render into an array of strings, one byte per pixel.
    my $bitmap = .bitmap;
    my $top = $bitmap.top;
    my $left = $bitmap.left;

    # print a string representation
    print $bitmap.Str;
}

Description

This class represents the bitmap image of a rendered glyph.

Methods

pixel-mode()

The rendering pixel mode. One of:

depth()

The calculated color depth in bits. For example FT_PIXEL_MODE_GRAY has a color depth of 8.

width()

The width of each row, in bytes

rows()

The number of rows in the image

pitch()

Used to calculate the padding at the end of each row.

pixels

Returns a numeric shaped array of dimensions $.width and $height. Each item represents one pixel of the image, starting from the top left. A value of 0 indicates background (outside the glyph outline), and 255 represents a point inside the outline.

If anti-aliasing is used then shades of grey between 0 and 255 may occur. Anti-aliasing is performed by default, but can be turned off by passing the FT_RENDER_MODE_MONO option.

pgm

Renders the bitmap and constructs it into a PGM (portable grey-map) image file, which it returns as a Buf, suitable for output to a binary file.

The PGM image returned is in the ‘binary’ format, with one byte per pixel. It is not an efficient format, but can be read by many image manipulation programs. For a detailed description of the format see http://netpbm.sourceforge.net/doc/pgm.html

The render-glyph.pl example program uses this method.

Str()

Returns an ASCII display representation of the rendered glyph.

convert()

produces a new bitmap, re-rendered as eight bit FT_PIXEL_MODE_GRAY.

Authors

Geoff Richards qef@laxan.com

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.