They can be combined with the bitwise OR operator ( |). When extracting outlines from fonts, be sure to set the FT_LOAD_NO_HINTING flag. The default is usually OK for rendering fonts to bitmap images. The load_flags option takes various flags which alter the way glyphs are loaded. It defaults to 0, and since most fonts only contain one face it rarely needs to be provided. The index option specifies which face to load from the file. Return a Font::FreeType::Face object representing a font face from the specified file. 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, %options) This is a class method, which doesn't take any arguments. new()Ĭreate a new 'instance' of the freetype library and return the object. Unless otherwise stated, all methods will die if there is an error. See the documentation for Font::FreeType::Glyph for details of the format of the bitmap array reference that returns, and for other ways to get information about a glyph. Glyphs can be rendered to bitmap images, among other things: my $bitmap = $glyph->bitmap
Programs to view font glyphs code#
Then load a particular glyph (an image of a character), either by character code (in Unicode) or the actual character: my $glyph = $face->glyph_from_char_code(65) If your font is scalable (i.e., not a bitmapped 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) This can be used to load faces from files, for example: my $freetype = Font::FreeType->new To use the library, first create a Font::FreeType object.
Programs to view font glyphs full#
Full details of the API are contained in this documentation, and (more importantly) the documentation for the Font::FreeType::Face and Font::FreeType::Glyph classes. The quickest way to get started with this library is to look at the examples in the examples directory of the distribution. The Font::FreeType API is not intended to replicate the C API of the FreeType library - it offers a much more Perl-friendly interface.
Contributions welcome, particularly if you know more than I do (which isn't much) about fonts and the FreeType2 library. See the TODO file to get a handle on how far along this work is. Some of the values returned may be wrong, or not scaled correctly. The API may change in ways that break programs based on it, but I don't think it will change much. It'll be another release or two before it stabilizes. Warning: this module is currently in 'beta' stage. It can render images of characters with high-quality hinting and antialiasing, extract metrics information, and extract the outlines of characters in scalable formats like TrueType. All the font access is done through the FreeType2 library, which supports many formats. This module allows Perl programs to conveniently read information from font files. My $glyph = $face->glyph_from_char('A') DESCRIPTION Font::FreeType - read font files and render glyphs from Perl using FreeType2 SYNOPSIS use Font::FreeType