#!/usr/bin/perl -w use strict; use POSIX; our @fbbox; our @cbbox; our $numbytes; our $zeroes; our $botpad; $|=1; while (<>) { if (m/^FONTBOUNDINGBOX\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)$/) { die if @fbbox; @fbbox = ($1,$2,$3,$4); # xsz ysz xoff yoff # FONTBOUNDINGBOX 10 20 0 -4 } elsif (m/^BBX\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)$/) { die unless @fbbox; @cbbox = ($1,$2,$3,$4); print "BBX @fbbox\n"; next; } elsif (m/^BITMAP\b/) { die unless @cbbox; $numbytes = ceil($fbbox[0] / 8); $zeroes = ('00' x $numbytes)."\n"; $botpad = $cbbox[3] - $fbbox[3]; my $toppad = $fbbox[1] - $cbbox[1] - $botpad; print; print $zeroes x $toppad; next; } elsif (m/^ENDCHAR\b/) { die unless defined $zeroes; print $zeroes x $botpad; $zeroes = undef; } elsif (defined $zeroes) { chomp; m/[^0-9A-F]/ and die "$& ?"; # print "# $_\n"; $_ = unpack "B*", pack "H*", $_; # print "# $_\n"; $_ = ("0" x ($cbbox[2] - $fbbox[2])) . $_; # print "# $_\n"; s/0+$//; # print "# $_\n"; $_ .= "0" x ($numbytes*8 - length); # print "# $_\n"; $_ = unpack "H*", pack "B*", $_; $_ .= "\n"; } print; }