NAME
SIRTX::Font - module for working with SIRTX font files
VERSION
version v0.03
SYNOPSIS
use SIRTX::Font;
my SIRTX::Font $font = SIRTX::Font->new;
$font->read('cool-font.sf');
$font->write('cool-font.sf');
if ($font->has_codepoint(0x1234)) { ... }
printf("%ux%u\@%u\n", $font->width, $font->height, $font->bits);
$font->glyph_for(0x1234, $font->import_glyph('U+1234.png'));
This module implements an interface to SIRTX font files.
All methods in this module die
on error unless documented otherwise.
CHARACTER LISTS
This module includes a few methods that use named character lists. There refer to one or more of the build-in charater lists.
Currently defined:
ascii
-
All printable ASCII characters.
dec-mcs
-
All printable characters in DEC-MCS (Multinational Character Set).
dec-sg
-
All printable characters in DEC-SG (Special Graphics).
dec-tech
-
All printable characters in DEC Technical.
sirtx-characters
-
All characters in the SIRTX character list (provided by SIRTX on old non-Unicode terminals that support DLLCS).
important
-
Characters that are considered important in the context of SIRTX. Each base font SHOULD provide at least those characters. This also includes entries from at least
dec-mcs
,dec-sg
, andsirtx-characters
, but may contain more. cp-850
-
Code page 850 (often used on classic DOS systems).
cp-858
-
Code page 858 (often used on more modern DOS systems).
cp-437
-
Code page 437 (original IBM PC character set).
METHODS
new
my SIRTX::Font $font = SIRTX::Font->new;
Creates a new font object. No parameters are supported.
gc
$font->gc;
(experimental)
Takes the trash out. This will remove unused glyphs and deduplicate glyphs that are still in use.
Note: After a call to this all glyph numbers become invalid.
width
$font->width($width);
my $width = $font->width;
Sets or gets the width of character cells.
height
$font->height($height);
my $height = $font->height;
Sets or gets the height of character cells.
bits
$font->bits($bits);
my $bits = $font->bits;
Sets or gets the bits per pixel of character cells.
codepoints
my $codepoints = $font->codepoints;
Returns the number of known code points.
Note: Must be called in scalar context.
glyphs
my $glyphs = $font->glyphs;
Returns the number of known glyphs.
Note: This is not the number of glyphs that is exported on write, as unused glyphs might be skipped.
Note: Must be called in scalar context.
has_codepoint
my $bool = $font->has_codepoint($codepoint);
Returns a true value if the code point is knowm, otherwise return a false value.
remove_codepoint
$font->remove_codepoint(0x1234);
Removes a code point from the font. This will not remove the glyph.
If the code point is not known this method will do nothing.
has_all_codepoints_from
my $bool = $font->has_all_codepoints_from( @lists );
# e.g.:
my $bool = $font->has_all_codepoints_from('important');
my $bool = $font->has_all_codepoints_from(qw(dec-mcs dec-sg));
Returns a true value if all code points from the given lists are included, otherwise false.
Note: This is faster than calling "missing_codepoints_from" and checking if it returned any items.
missing_codepoints_from
my @codepoints = $font->missing_codepoints_from( @lists );
# e.g.:
my @codepoints = $font->missing_codepoints_from('important');
Returns the code points missing from the given lists that are missing in this font.
Note: If you only want to check if all code points are included use "has_all_codepoints_from" which is faster.
remove_codepoint_not_in
$font->remove_codepoint_not_in( @lists );
# e.g.:
$font->remove_codepoint_not_in('dec-mcs');
Removes all code points from the current font that are not in the given lists. This can be used to strip a larger font to a subset efficiently.
Note: This will only remove the code points, not the glyphs as per "remove_codepoint".
glyph_for
my $glyph = $font->glyph_for($codepoint); # $codepoint is 0x1234 or 'U+1234'
$font->glyph_for($codepoint => $glyph);
Sets or gets the glyph for a given code point.
default_glyph_for
$glyph = $font->default_glyph_for($codepoint => $glyph);
Sets the glyph for the code point if it has no glyph set so far. Returns the new glyph (if the code point was modified) or the old (if it was already set).
alias_glyph
$font->alias_glyph($from, $to);
Aliases the glyph for code point $from
to the same as code point $to
.
See also "glyph_for".
default_alias_glyph
$font->default_alias_glyph($from, $to);
Aliases the glyph for code point $from
to the same as code point $to
if $from
has no glyph set.
add_default_aliases
$font->add_default_aliases;
# or:
$font->add_default_aliases($level);
(experimental)
Adds aliases as per "default_alias_glyph" for known homoglyphs.
The following levels are supported:
common-small
-
A set if code point aliases that are both likely homoglyphs as well as hard to pick up by rendering engines.
common-large
-
A set of code point aliases that are likely homoglyphs, some might be picked up by rendering engines. This includes the aliases from
common-small
. common-all
-
A set of code point aliases that are likely homoglyphs, including those that should be picked up by rendering engines. This includes the aliases from
common-small
, andcommon-large
.
Note: This operation cannot easly be undone.
Note: The levels are not yet stable in this version. Future versions might use different sets of code points aliases.
read
$font->read($handle);
Reads a font file into memory. If any data is already loaded the data is merged.
write
$font->write($handle);
Writes the current font in the SIRTX format to the given handle.
import_glyph
my $glyph = $font->import_glyph($filename);
Imports a glyph from a file. The glyph index is returned.
The supported formats depend on the installed modules. See also Image::Magick.
import_directory
$font->import_directory($filename [, %opts ]);
(experimental)
Imports a directory into the font. The directory contains of files with a name of the code point plus the extention png or wbmp (e.g. U+1F981.png
).
There is one option supported: incremental
. If set to a true value it will cause mappings for already known code points to be skipped. This can result in a massive speedup. Only use if you are sure no entries have been altered.
Note: All rules of "import_glyph" apply. Entries are merged, data already present in the font is not cleared.
Note: In order to deduplicate entries a call to "gc" might be considered.
export_glyph_as_image_magick
my Image::Magick $image = $font->export_glyph_as_image_magick($glyph);
(experimental)
Exports a single glyph as a image object.
render
my Image::Magick $image = $font->render($string);
# e.g.:
my Image::Magick $image = $font->render("Hello World!");
$image->Transparent(color => 'white'); # transparent background
$image->Write('hello.png');
(experimental)
Renders a text using the loaded font.
AUTHOR
Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2025 by Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)