4
# Simple convertor from bdf to gd font format.
6
# Author: Jan Pazdziora, adelton@fi.muni.cz, http://www.fi.muni.cz/~adelton/
7
# at Faculty of Informatics, Masaryk University in Brno, Czech Republic.
10
# fstobdf -s fontserverhost:7100 -fn 8x16 | ./bdftogd FontLarge gdfontl
19
{ die "usage: bdftogd fontname filename, eg. bdftogd FontLarge gdfontl\n"; }
22
$gdname = 'gd' . $gdname unless $gdname =~ /^gd/i;
25
$filename = 'gd' . $filename unless $filename =~ /^gd/i;
27
if (-f "$filename.c") { die "File $filename.c already exists, won't overwrite\n"; }
28
if (-f "$filename.h") { die "File $filename.h already exists, won't overwrite\n"; }
31
my (@data, @left, @bottom);
32
my ($globalleft, $globaltop);
34
my ($minchar, $maxchar);
36
my ($copyright, $fontdef);
46
my ($tag, $value) = split / /, $_, 2;
47
die "Font is not fixed width\n"
48
if $tag eq 'SPACING' and not $value =~ /[CM]/i;
50
$currentchar = $value if $tag eq 'ENCODING';
51
$minchar = $currentchar if not defined $minchar
52
or $currentchar < $minchar;
53
$maxchar = $currentchar if not defined $maxchar
54
or $currentchar > $maxchar;
56
if ($tag eq 'ENDCHAR')
59
my $bottom = $globaltop - $bottom[$currentchar];
63
{ $data[$currentchar] = substr $data[$currentchar], 0, length($data[$currentchar]) - $bottom * $width; }
65
{ $data[$currentchar] .= '0' x (-$bottom * $width); }
68
if ($tag eq 'FONTBOUNDINGBOX')
70
my ($tag, $wid, $hei, $left, $top) = split / /;
79
if ($tag eq 'FONT' and not defined $fontdef)
80
{ $fontdef = $value; }
81
if ($tag eq 'COPYRIGHT' and not defined $copyright)
82
{ $copyright = $value; }
86
my ($tag, $wid, $hei, $left, $bottom) = split / /;
89
$left[$currentchar] = $left;
90
$bottom[$currentchar] = $bottom;
96
my $value = pack 'H*', $_;
97
my $bits = unpack 'B*', $value;
98
$bits = ('0' x $left[$currentchar]) . $bits;
99
$bits .= '0' x ($width - length $bits);
100
$bits = substr $bits, 0, $width;
101
$data[$currentchar] .= $bits;
104
if ($tag eq 'BITMAP')
107
$data[$currentchar] = '';
113
This is a header file for gd font, generated using
114
bdftogd version $VERSION by Jan Pazdziora, adelton\@fi.muni.cz
120
if (defined $copyright)
123
The original bdf was holding following copyright:
131
No copyright info was found in the original bdf.
136
open FILEC, "> $filename.c" or die "Error writing $filename.c: $!\n";
137
open FILEH, "> $filename.h" or die "Error writing $filename.h: $!\n";
142
#include "$filename.h"
144
char ${gdname}Data[] = {
147
$minchar = 0 unless defined $minchar;
148
$maxchar = 255 unless defined $maxchar;
149
for (my $i = $minchar; $i <= $maxchar; $i++)
151
$data[$i] = '' unless defined $data[$i];
152
$data[$i] = '0' x ($width * $height - length $data[$i]) . $data[$i];
154
print FILEC "/* Char $i */\n";
155
for my $line (0 .. $height - 1)
156
{ print FILEC join ',', split(//, substr($data[$i], $line * $width, $width)), "\n"; }
162
for my $line (0 .. $height - 1)
163
{ print substr($data[$i], $line * $width, $width), "\n"; }
166
my $capdef = "\U_${filename}_H_";
172
gdFont ${gdname}Rep = {
173
@{[ $maxchar - $minchar + 1]},
180
gdFontPtr ${gdname} = &${gdname}Rep;
182
/* This file has not been truncated. */
198
extern gdFontPtr $gdname;