Font::...::Glyph(3pm)
๐ Font::...::Glyph(3pm) โ like, the whole entire manual page, bestie
okay so this is the Font::FreeType::Glyph page from the User Contributed Perl Documentation, and honestly? it's giving "small class, huge main character energy" โจ because a glyph is literally one single character image and it still gets its own whole module. obsessed.
๐ธ NAME ๐ธ
Font::FreeType::Glyph โ glyphs from font typefaces loaded from Font::FreeType. that's it, that's the name, no cap ๐
โจ SYNOPSIS โจ
here's the vibe in code form, do not touch, it's exact:
use Font::FreeType;
my $freetype = Font::FreeType->new;
my $face = $freetype->face('Vera.ttf');
$face->set_char_size(24, 24, 100, 100);
my $glyph = $face->glyph_from_char('A');
my $glyph = $face->glyph_from_char_code(65);
# Render into an array of strings, one byte per pixel.
my ($bitmap, $left, $top) = $glyph->bitmap;
# Read vector outline.
$glyph->outline_decompose(
move_to => sub { ... },
line_to => sub { ... },
conic_to => sub { ... },
cubic_to => sub { ... },
);
like, one line you're grabbing a glyph with 'A', next line you're grabbing the same glyph with 65, because a character and its code are the same thing wearing different outfits ๐
๐ฆ DESCRIPTION ๐ฆ
so this class represents an individual glyph โ that's a character image, fyi โ loaded from a font. periodt. ๐
if you're wondering "okay but how do I get a glyph object tho", that's a whole other page: see Font::FreeType::Face, and specifically the glyph_from_char_code() and glyph_from_char() methods over there. iykyk ๐ซถ
things you can do with glyphs include:
- Get metadata about the glyph, such as the size of its image and other metrics. lowkey the receipts of what the glyph looks like ๐
- Render a bitmap image of the glyph (if it's from a vector font) or extract the existing bitmap (if it's from a bitmap font), using the
bitmap()method. so either you're making the pixels or you're just taking the pixels that were already there, slay either way ๐ฅ - Extract a precise description of the lines and curves that make up the glyph's outline, using the
outline_decompose()method. this is the โจartisticโจ one, it's literally handing you the curves ๐ง
ngl, if you actually want to understand the numbers instead of just vibing with them, go read the real breakdown. for a detailed description of the meaning of glyph metrics, and the structure of vectorial outlines, see <http://freetype.sourceforge.net/freetype2/docs/glyphs/>
okay don't go anywhere, there's more of this page coming ๐ญ๐
๐ METHODS ๐
โ ๏ธ okay bestie, important vibe check first: unless a method says otherwise, all of these methods will die if thereโs an error ๐ญ and the metrics are scaled to the size of the font face. no cap.
๐ผ๏ธ bitmap([render-mode])
If the glyph is from a bitmap font, you get the bitmap image back. If itโs from a vector font, the outline gets rendered into a bitmap at the faceโs current size. cute.
Three values come back, in this order:
- the bitmap itself
- the number of pixels from the origin to the left of the area the bitmap describes
- the number of pixels from the origin to the top of the bitmap area โ positive being up โ๏ธ
The bitmap value is a reference to an array. Each item in the array is one line of the bitmap, starting from the top. Each item is a string of bytes, with one byte per pixel, starting from the left. A value of 0 means background (outside the glyph outline), and 255 means a point inside the outline. slay.
If antialiasing is used, shades of grey between 0 and 255 can show up. Antialiasing is performed by default, but you can turn it off by passing FT_RENDER_MODE_MONO.
Get the bitmap size like this, bestie:
my ($bitmap, $left, $top) = $glyph->bitmap;
my $width = length $bitmap->[0];
my $height = @$bitmap;
The optional render_mode argument can be any one of these:
FT_RENDER_MODE_NORMALโ the default. Uses antialiasing. โจFT_RENDER_MODE_LIGHTโ changes the hinting algorithm so the glyph image is closer to its real shape, but probably more fuzzy. Only available with Freetype version2.1.4or newer.FT_RENDER_MODE_MONOโ renders with antialiasing disabled. Each pixel will be either0or255. periodt.FT_RENDER_MODE_LCDโ renders in colour for an LCD display, with three times as many pixels across the image as normal. This mode probably wonโt work yet. Only available with Freetype version2.1.3or newer.FT_RENDER_MODE_LCD_Vโ renders in colour for an LCD display, with three times as many rows down the image as normal. This mode probably wonโt work yet. Only available with Freetype version2.1.3or newer.
๐ช bitmap_magick([render_mode])
A simple wrapper around the bitmap() method. It renders the bitmap the normal way and returns it as an Image::Magick object, which you can then composite onto a larger bitmapped image, or manipulate using any of the features available in Image::Magick. icon behavior.
The image is in the gray format, with a depth of 8 bits.
The left and top distances in pixels are returned as well, in the same way as for the bitmap() method.
This method โ especially using the left and top offsets to position the bitmap correctly โ is demonstrated in the magick.pl example program. ๐ซถ
๐ง bitmap_pgm([render_mode])
Another simple wrapper around the bitmap() method. It renders the bitmap and constructs it into a PGM (portable grey-map) image file, which it returns as a string. The optional render-mode is passed directly to the bitmap() method.
The PGM image returned is in the binary format, with one byte per pixel. It is not an efficient format, but it can be read by many image manipulation programs. For a detailed description of the format see <http://netpbm.sourceforge.net/doc/pgm.html>. iykyk.
The left and top distances in pixels are returned as well, in the same way as for the bitmap() method.
The render-glyph.pl example program uses this method. ๐
๐ข char_code()
The character code (in Unicode) of the glyph. It could potentially return codes in other character sets if the font doesnโt have a Unicode character mapping, but most modern fonts do.
๐ฆ has_outline()
True if the glyph has a vector outline, in which case it is safe to call outline_decompose(). Otherwise, the glyph only has a bitmap image.
๐ height()
The height of the glyph. yes bestie, thatโs the whole thing.
โก๏ธ horizontal_advance()
The distance from the origin of this glyph to the place where the next glyphโs origin should be. Only applies to horizontal layouts. Always positive, so for right-to-left text (such as Hebrew) it should be subtracted from the current glyphโs position.
๐ข index()
The glyphโs index number in the font. This number is determined by the FreeType library, and so isnโt necessarily the same as any special index number used by the font format.
โฌ
๏ธ left_bearing()
The left side bearing โ the distance from the origin to the left of the glyph image. Usually positive for horizontal layouts and negative for vertical ones.
๐ฅ load()
Tell FreeType to load the glyph. There are very few reasons to use this, as it is called implicitly if needed, by most of the other methods.
A few of these reasons include: timing or profiling tests of FreeType, debugging FreeType via side effects of glyph loading (by setting FT2_DEBUG).
๐ท๏ธ name()
The name of the glyph, if the font format supports glyph names, otherwise undef.
๐ฆ outline_bbox()
The bounding box of the glyphโs outline. This box will enclose all the 'ink' that would be laid down if the outline were filled in. It is calculated by studying each segment of the outline, so may not be particularly efficient.
The bounding box is returned as a list of four values, so call it like this:
my ($xmin, $ymin, $xmax, $ymax) = $glyph->outline_bbox();
๐ outline_decompose(%callbacks)
This method extracts a description of the glyphโs outline, scaled to the faceโs current size. It will die if the glyph doesnโt have an outline (if it comes from a bitmap font). ๐
Vector outlines of glyphs are represented by a sequence of operations. Each operation can start a new curve (by moving the imaginary pen position), or draw a line or curve from the current position of the pen to a new position. This Perl interface walks through the outline calling subroutines โ through code references you supply โ for each operation. Arguments are passed to your subroutines as normal, in @_.
โ ๏ธ Note: when you intend to extract the outline of a glyph, always pass the FT_LOAD_NO_HINTING option when creating the face object, or the hinting will distort the outline. fr fr.
The %callbacks parameter should contain three or four of the following keys, each with a reference to a sub as its value. The conic_to handler is optional, but the others are required.
"move_to"โ move the pen to a new position, without adding anything to the outline. The first operation should always bemove_to, but characters with disconnected parts, such as"i", might have several of these. The x and y coordinates of the new pen position are supplied."line_to"โ move the pen to a new position, drawing a straight line from the old position. The x and y coordinates of the new pen position are supplied. Depending on how youโre using this information, you may have to keep track of the previous position yourself."conic_to"โ move the pen to a new position, drawing a conic Bรฉzier arc (also known as a quadratic Bรฉzier curve) from the old position, using a single control point. If you donโt supply aconic_tohandler, all conic curves will be automatically translated into cubic curves. The x and y coordinates of the new pen position are supplied, followed by the x and y coordinates of the control point."cubic_to"โ move the pen to a new position, drawing a cubic Bรฉzier arc from the old position, using two control points. Cubic arcs are the ones produced in PostScript by thecurvetooperator. The x and y coordinates of the new pen position are supplied, followed by the x and y coordinates of the first control point, then the same for the second control point.
Note that TrueType fonts use conic curves and PostScript ones use cubic curves. ๐
๐จ๏ธ postscript([file-handle])
Generate PostScript code to draw the outline of the glyph. More precisely, the output constructs a PostScript path for the outline, which can then be filled in or stroked as you like.
The glyph-to-eps.pl example program shows how to wrap the output in enough extra code to generate a complete EPS file.
If you pass a file-handle to this method, it writes the PostScript code to that file; otherwise it returns the code as a string.
โก๏ธ right_bearing()
The distance from the right edge of the glyph image to the place where the origin of the next character should be (i.e., the end of the advance width). Only applies to horizontal layouts. Usually positive.
๐ svg_path()
Turns the outline of the glyph into a string in a format suitable for including in an SVG graphics file, as the d attribute of a path element. Note that because SVGโs coordinate system has its origin in the top left corner, the outline will be upside down. An SVG transformation can be used to flip it. ๐
The glyph-to-svg.pl example program shows how to wrap the output in enough XML to generate a complete SVG file, and one way of transforming the outline to be the right way up.
If you pass a file-handle to this method, it writes the path string to that file; otherwise it returns the string.
โฌ๏ธ vertical_advance()
The distance from the origin of the current glyph to the place where the next glyphโs origin should be, moving down the page. Only applies to vertical layouts. Always positive.
โ๏ธ width()
The width of the glyph. This is the distance from the left side to the right side โ not the amount you should move along before placing the next glyph when typesetting. For that, see the horizontal_advance() method. bestie, donโt mix them up ๐
๐ SEE ALSO ๐
Font::FreeTypeFont::FreeType::Face
โ๏ธ 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.
thatโs the whole page, bestie ๐ source/version: perl v5.42.3; date: 2026-08-19; page: Font::...::Glyph(3pm) โ mwah ๐ซถโจ
๐ฆ where this page comes from
- ubuntu stonking: libfont-freetype-perl 0.16-3build5 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms