#!/usr/bin/perl use Font::BDF; use Pod::Usage; use Getopt::Long; use File::Basename; my $data = "file.dat"; my $length = 24; my $verbose; my $help = 0; my $output = undef; my $fontname; my $encoding = "Unicode"; my $suffix = ".sfd"; my $fontforge = "fontforge"; $result = GetOptions('help|?' => \$help, "output=s" => \$output, "weight=s" => \$weight, "fullname=s" => \$fullname, "familyname=s" => \$familyname, "fontname=s" => \$fontname, "encoding=s" => \$encoding, "ttf" => \$ttf, ) or pod2usage(2); pod2usage(1) if $help; if ($ARGV[0]) { my ($name, $path, $suffix) = fileparse($ARGV[0], qr{\..*}); if (!defined $fontname) { $fontname = (length $name) ? "\u$name" : "MyFont"; $fontname =~ s/[-_](.)/\u$1/g; $fontname =~ s/[^a-zA-Z0-9]//g; } if (!defined $output) { $output = "$path$name.sfd"; $ttfoutput = "$path$fontname.ttf" } else { $ttfoutput = $output } } else { if (!defined $fontname) { $fontname = "MyFont" } if (!defined $output) { $output = "font.sfd"; $ttfoutput = "font.ttf" } else { $ttfoutput = $output } } if ($ttf) { $output = "/tmp/$$.sfd"; } $scale = 100; $fudge = 1; my $f = Font::BDF->new_from_bdf(\*ARGV); my %p = $f->get_properties; my $ascent = $p{FONT_ASCENT} * $scale; my $descent = $p{FONT_DESCENT} * $scale; open OUT, ">$output" or die $!; select(OUT); my $num_chars = $f->encoded_chars; my $max_chars = 0; for my $x ($f->encoded_chars) { if ($x + 1 > $max_chars) { $max_chars = $x + 1 } } print "SplineFontDB: 1.0\n"; sub print_field { my ($name, $value) = @_; if (length $value) { print "$name: $value\n"; } } print_field("FontName", $fontname); print_field("FullName", $fullname); print_field("FamilyName", $familyname); print_field("Weight", $weight); print_field("Encoding", $encoding); print_field("Ascent", $ascent); print_field("Descent", $descent); print_field("BeginChars", "$max_chars $num_chars"); for my $enc ($f->encoded_chars) { my ($name, $offset) = $f->get_char_info ($enc); my ($hoff, $voff) = @$offset; $hoff *= $scale; $voff *= $scale; my ($pixels) = $f->get_pixels($enc); print < reads in a X11 bitmap font in BDF format, and outputs a file in the native B format, SFD. =cut