Font::PCF - read an X11 PCF font file
Font::PCF
use Font::PCF; my $font = Font::PCF->open( "/usr/share/fonts/X11/misc/9x15.pcf.gz" ); my $glyph = $font->get_glyph_for_char( "A" ); sub printbits { my ( $bits ) = @_; while( $bits ) { print +( $bits & (1<<31) ) ? '#' : ' '; $bits <<= 1; } print "\n"; } printbits $_ for $glyph->bitmap->@*;
Instances of this class provide read access to the "PCF" format font files that are typically found as part of an X11 installation.
This module was written just to be sufficient for generating font bitmaps to encode in microcontroller programs for display on OLED panels. It is possibly useful for other use-cases as well, but may required more methods adding.
$font = Font::PCF->open( $path )
Opens the PCF file from the given path, and returns a new instance containing the data from it. Throws an exception if an error occurs.
$glyph = $font->get_glyph_for_char( $char )
Returns a Glyph struct representing the unicode character; given as a character string.
Each glyph structure returned by "get_glyph_for_char" has the following methods:
@bits = $glyph->bitmap->@*
Returns a reference to the array containing lines of the bitmap for this character. Each line is represented by an integer, where high bits represent set pixels. The MSB is the leftmost pixel of the character.
$pixels = $glyph->width
The total number of pixels per line stored in the bitmaps.
$pixels = $glyph->left_side_bearing $pixels = $glyph->right_side_bearing
The number of pixels of bearing (that is, blank pixels of space) to either side of the character data.
$pixels = $glyph->ascent $pixels = $glyph->descent
The number of pixels above and below the glyph.
$str = $glyph->name
The PostScript name for the glyph
Paul Evans <leonerd@leonerd.org.uk>
To install Font::PCF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Font::PCF
CPAN shell
perl -MCPAN -e shell install Font::PCF
For more information on module installation, please visit the detailed CPAN module installation guide.