SIRTX-Font
view release on metacpan or search on metacpan
}
},
"develop" : {
"requires" : {
"Test::Pod" : "1.41"
}
},
"runtime" : {
"recommends" : {
"File::Spec" : "3.84",
"Image::Magick" : "0"
},
"requires" : {
"Carp" : "1.35",
"perl" : "v5.20.0"
}
},
"test" : {
"requires" : {
"Test::Exception" : "0.30",
"Test::More" : "1.3",
name: SIRTX-Font
no_index:
directory:
- t
provides:
SIRTX::Font:
file: lib/SIRTX/Font.pm
version: v0.6.0
recommends:
File::Spec: '3.84'
Image::Magick: '0'
requires:
Carp: '1.35'
perl: v5.20.0
resources:
repository: ssh://gitea@gitea.dev.loewenfelsen.net/11201-Loewenfelsen/SIRTX-Font.git
version: v0.06
x_generated_by_perl: v5.36.0
x_serialization_backend: 'YAML::Tiny version 1.73'
x_spdx_expression: Artistic-2.0
# This file is generated by Dist::Zilla::Plugin::CPANFile v6.030
# Do not edit this file directly. To change prereqs, edit the `dist.ini` file.
requires "Carp" => "1.35";
requires "perl" => "v5.20.0";
recommends "File::Spec" => "3.84";
recommends "Image::Magick" => "0";
on 'test' => sub {
requires "Test::Exception" => "0.30";
requires "Test::More" => "1.3";
requires "Test::Warn" => "0.30";
};
on 'configure' => sub {
requires "ExtUtils::MakeMaker" => "0";
};
author = Philipp Schafft <lion@cpan.org>
copyright_holder = Philipp Schafft <lion@cpan.org>
license = Artistic_2_0
copyright_year = 2025-2026
[Prereqs]
perl = v5.20
Carp = 1.35
[Prereqs / RuntimeRecommends]
Image::Magick = 0
File::Spec = 3.84
;[Prereqs / RuntimeSuggests]
[Prereqs / TestRequires]
Test::More = 1.3
Test::Exception = 0.30
Test::Warn = 0.30
[MetaNoIndex]
lib/SIRTX/Font.pm view on Meta::CPAN
foreach my $glyph (sort {$index_update{$a} <=> $index_update{$b}} keys %index_update) {
print $out $glyphs->[$glyph];
}
}
sub import_glyph {
my ($self, $in) = @_;
if (!eval {$in->isa('Image::Magick')}) {
require Image::Magick;
my $p = Image::Magick->new;
$p->Read($in);
$in = $p;
}
return $self->_import_glyph_wbmp($in->ImageToBlob(magick => 'wbmp'));
}
sub _import_glyph_wbmp {
my ($self, $data) = @_;
my ($w, $h);
lib/SIRTX/Font.pm view on Meta::CPAN
$glyph = int($glyph) if defined $glyph;
croak 'No valid glyph given' unless defined($glyph) && $glyph >= 0;
$glyph = $self->{glyphs}[$glyph];
croak 'No valid glyph given' unless defined($glyph);
if ($self->width >= 128 || $self->height >= 128 || $self->bits != 1) {
croak 'Unsupported glyph size';
}
require Image::Magick;
$p = Image::Magick->new(magick => 'wbmp');
$p->BlobToImage(pack('CCCC', 0, 0, $self->width, $self->height).$glyph);
return $p;
}
sub export_alias_map {
my ($self, $filename, %opts) = @_;
my $chars = $self->{chars};
my %glyph_map;
lib/SIRTX/Font.pm view on Meta::CPAN
} elsif ($w <= 16) {
return unpack('n*', $glyph);
} else {
croak 'Unsupported glyph width';
}
}
sub render {
require List::Util;
require Image::Magick;
my ($self, $string) = @_;
my @lines = split(/\r?\n/, $string);
my $max_line = List::Util::max(map {length} @lines);
my $width = $self->width;
my $height = $self->height;
my $p = Image::Magick->new;
my %handle_cache;
$p->Set(size => sprintf('%ux%u', $max_line * $width, scalar(@lines) * $height));
$p->Read('canvas:white');
for (my $row = 0; $row < scalar(@lines); $row++) {
my $line = $lines[$row];
my $len = length($line);
for (my $column = 0; $column < $len; $column++) {
lib/SIRTX/Font.pm view on Meta::CPAN
Writes the current font in the SIRTX format to the given handle.
=head2 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 L<Image::Magick>.
=head2 import_alias_map
$font->import_alias_map($filename);
(experimental, since v0.04)
Imports an alias map from the given file.
The format is one alias group per line.
lib/SIRTX/Font.pm view on Meta::CPAN
B<Note:>
All rules of L</import_glyph> apply.
Entries are merged, data already present in the font is not cleared.
B<Note:>
In order to deduplicate entries a call to L</gc> might be considered.
=head2 export_glyph_as_image_magick
my Image::Magick $image = $font->export_glyph_as_image_magick($glyph);
(experimental, since v0.01)
Exports a single glyph as a image object.
=head2 export_alias_map
$font->export_alias_map($filename);
(experimental, since v0.04)
lib/SIRTX/Font.pm view on Meta::CPAN
(experimental, since v0.06)
Analyses the font to find additional attributes automatically.
This can be useful specifically when importing pre-existing fonts.
However the result should be manually checked as the values might not reflect reality.
=head2 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, since v0.03)
Renders a text using the loaded font.
=head1 AUTHOR
Philipp Schafft <lion@cpan.org>
( run in 2.323 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )