5 if($ARGV[0] eq "--help")
8 usage: bdftopsf [+h][+u|-u][+1|-1]|[-h[+r|-r]] [+o|-o OUTPUT]
9 [--] [INPUT [TABLE...]]
11 +h PSF mode - write a PSF header. This is the default.
12 +u Write an unicode table. Default for fonts with more
14 -u Don't write unicode table. Default for fonts with 256
16 +1 Use PSF1. Default for fonts with 256 or 512 characters,
17 width 8 and height less than 256.
18 -1 Use PSF2. Default for all other fonts.
20 -h RAW mode - write no PSF header (and no unicode table,
22 +r Reject 512 character fonts. This is the default. Most
23 (if not all) UNIX systems won't handle these properly.
24 -r Allow 512 character fonts.
26 +o Output to INPUT.psf or INPUT.raw (replacing the .bdf in
28 -o NAME Output to NAME.
30 -- Terminate the option list.
32 INPUT RAW and PSF1: a 256 or 512 character BDF file with
33 width = 8 and height between 1 and 255. PSF2: a BDF
34 with width between 1 and 1200, height between 1 and
35 2400 and number of characters between 1 and 2048.
37 TABLE A duplicate unicodes table. Each line must either be
38 blank or contain two hexadecimal unicodes, each
39 consisting of maximum 4 digits. Used for PSF with
40 unicode data only, otherwise treated as error.
42 If no input or output are specified, the standard output is
43 the standard input and output are used.
45 Any options not specified in the above order are treated as
51 if($ARGV[0] eq "--version")
54 bdftopsf.pl 0.2.0, Copyright (C) 2005 Dimitar Toshkov Zhekov
56 This program is free software; you can redistribute it and/or
57 modify it under the terms of the GNU General Public License as
58 published by the Free Software Foundation; either version 2 of
59 the License, or (at your option) any later version.
61 This program is distributed in the hope that it will be useful,
62 but WITHOUT ANY WARRANTY; without even the implied warranty of
63 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64 GNU General Public License for more details.
66 Report bugs to jimmy\@is-vn.bg
87 if($ARGV[0] eq "+r") { shift @ARGV; }
95 if($ARGV[0] eq "+h") { shift @ARGV; }
102 elsif($ARGV[0] eq "-u")
113 elsif($ARGV[0] eq "-1")
125 elsif($ARGV[0] eq "-o")
129 $ARGV[0] ne "" || die("$0: -o requires a non-empty argument\n");
134 if($ARGV[0] eq "--") { shift @ARGV; }
135 elsif($ARGV[0] =~ /^([-+][0-9a-z])$/) { print STDERR
"$0: suspicuous $1, use -- to terminate the option list\n"; }
138 if($#ARGV < 0) { $ARGV[0] = "-"; }
140 open(BDF
, "<$ARGV[0]") || die("$0: $ARGV[0]: $!\n");
144 if(/^FONTBOUNDINGBOX\s+([0-9]+)\s+([0-9]+).*$/)
149 elsif(/^CHARS\s+([0-9]+)$/)
156 ($width > 0 && $width <= 1200) || die("$0: $ARGV[0]: width $width zero or too big\n");
157 ($height > 0 && $height <= 2400) || die("$0: $ARGV[0]: height $height zero or too big\n");
158 ($chars > 0 && $chars <= 2048) || die("$0: $ARGV[0]: CHARS $chars zero or too big\n");
160 $minimal = $width != 8 || $height >= 256 || ($chars != 256 && $chars != 512);
161 $header != 0 || $minimal == 0 || die("$0: $ARGV[0]: RAW format: invalid width $width, height $height or CHARS $chars\n");
162 $chars == 256 || $reject == 0 || die("$0: $ARGV[0]: RAW format: CHARS $chars rejected, use -r to accept\n", $chars);
164 if(!defined($unicode)) { $unicode = $chars > 256; }
165 if(!defined($version)) { $version = $minimal; }
166 else { $version >= $minimal || die("$0: $ARGV[0]: requested version ", $version + 1, ", required ", $minimal + 1, "\n"); }
168 if(!defined($output)) { $output = "-"; }
169 elsif($output eq "") { if($ARGV[0] =~ /^(.*).bdf$/) { $output = "$1$suffix" ; } else { $output = "$ARGV[0]$suffix"; } }
171 $linesize = ($width + 7) >> 3;
172 $charsize = $linesize * $height;
174 sub int { $int = $!; }
178 $output ne "-" && unlink($output) != 1 && print STDERR
"$0: $output: $!\n";
182 open(OUT
, ">$output") || die("$0: $output: $!\n");
184 binmode(OUT
) || bye
("$0: $output: $!\n");
188 if($version == 0) { printf OUT
"%c%c%c%c", 0x36, 0x04, ($chars == 512) + $unicode * 2, $height; }
191 printf OUT
"%c%c%c%c", 0x72, 0xB5, 0x4A, 0x86;
192 printf OUT
"%c%c%c%c", 0x00, 0x00, 0x00, 0x00;
193 printf OUT
"%c%c%c%c", 0x20, 0x00, 0x00, 0x00;
194 printf OUT
"%c%c%c%c", $unicode, 0x00, 0x00, 0x00;
195 printf OUT
"%c%c%c%c", $chars & 0xFF, $chars >> 8, 0x00, 0x00;
196 printf OUT
"%c%c%c%c", $charsize & 0xFF, ($charsize >> 8) & 0xFF, $charsize >> 16, 0x00;
197 printf OUT
"%c%c%c%c", $height & 0xFF, $height >> 8, 0x00, 0x00;
198 printf OUT
"%c%c%c%c", $width & 0xFF, $width >> 8, 0x00, 0x00;
206 while(/^([0-9a-fA-F]{2})(([0-9a-fA-F]{2})*)$/)
208 printf OUT
"%c", hex($1);
215 $bytes == $linesize || bye
("$0: $ARGV[0]: invalid number of bytes $bytes on data line $lines\n");
219 if(/^ENCODING\s+([0-9]+)$/)
222 if($1 != 65535) { $unidup{$1}[0] = $1; }
224 elsif(/^ENDFONT$/) { last; }
238 open(DUP
, "<$ARGV[0]") || bye
("$0: $ARGV[0]: $!\n");
242 /^([0-9a-fA-F]{1,4})\s+([0-9a-fA-F]{1,4})$/ || bye
("$0: $ARGV[0]: invalid unicode(s) $_\n");
243 $duplicate = hex($2);
244 hex($1) != $duplicate || bye
("$0: $ARGV[0]: invalid duplicate entry $_\n");
245 foreach(@
{$unidup{hex($1)}}) { if($_ == $duplicate) { $duplicate = 65535; last; } }
246 if($duplicate != 65535) { push @
{$unidup{hex($1)}}, $duplicate; }
251 else { bye
("$0: invalid number of arguments\n"); }
254 @unimap == $chars || bye
("$0: $output: invalid number of chars @unimap\n");
255 @unimap * $charsize == $lines * $linesize || bye
("$0: $output: invalid number of data lines $lines\n");
261 foreach(@
{$unidup{$_}}) {
262 if($version == 0) { printf OUT
"%c%c", $_ & 0xFF, $_ >> 8; }
263 elsif($_ <= 0x7F) { printf OUT
"%c", $_; }
265 if($_ <= 0x7FF) { printf OUT
"%c", 0xC0 + ($_ >> 6); }
266 else { printf OUT
"%c%c", 0xE0 + ($_ >> 12), 0x80 + (($_ >> 6) & 0x3F); }
267 printf OUT
"%c", 0x80 + ($_ & 0x3F);
270 printf OUT
"%c", 0xFF;
271 if($version == 0) { printf OUT
"%c", 0xFF; }
275 close OUT
|| bye
("$0: $output: $!\n");
276 defined($int) && bye
("$0: $int\n");