File: render-glyph.pl

package info (click to toggle)
libfont-freetype-perl 0.16-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 872 kB
  • sloc: perl: 366; sh: 3; makefile: 3
file content (30 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/perl -w
use strict;
use Font::FreeType;

die "Usage: $0 font-filename character/Unicode-number [point-size] > foo.pgm\n"
  unless @ARGV >= 2 && @ARGV <= 3;
my ($filename, $char, $size) = @ARGV;

my $dpi = 100;

my $face = Font::FreeType->new->face($filename);

# If the size wasn't specified, and it's a bitmap font, then leave the size
# to the default, which will be right.
if ($face->is_scalable || $size) {
    $size ||= 72;
    $face->set_char_size($size, $size, $dpi, $dpi);
}

# Accept character codes in hex or decimal, otherwise assume it's the
# actual character itself.
if ($char =~ /^0x[\dA-F]+$/i) { $char = hex $char }
elsif ($char !~ /^\d+$/)      { $char = ord $char }
my $glyph = $face->glyph_from_char_code($char);
die "No glyph for character '$char'.\n" unless $glyph;

my ($pgm, $left, $top) = $glyph->bitmap_pgm;
print $pgm;

# vi:ts=4 sw=4 expandtab