chiark / gitweb /
Add bdf normaliser (to cope with fontforge output directly, since bdftopcf | pcf2bdf...
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 25 Apr 2016 01:12:52 +0000 (02:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 25 Apr 2016 01:12:52 +0000 (02:12 +0100)
bdfnorm [new file with mode: 0755]
debian/changelog
mkrules

diff --git a/bdfnorm b/bdfnorm
new file mode 100755 (executable)
index 0000000..da20e76
--- /dev/null
+++ b/bdfnorm
@@ -0,0 +1,54 @@
+#!/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";
+       s/./ unpack "B4", pack "H*", $& /ge;
+#      print "# $_\n";
+       $_ = ("0" x ($cbbox[2] - $fbbox[2])) . $_;
+#      print "# $_\n";
+       s/0+$//;
+#      print "# $_\n";
+       $_ .= "0" x ($numbytes*8 - length);
+#      print "# $_\n";
+       s/.{4}/ unpack "H", pack "B4", $& /ge;
+       $_ .= "\n";
+    }
+    print;
+}
index 55fcd04..3e2a321 100644 (file)
@@ -11,6 +11,8 @@ xfonts-traditional (1.7.2~~iwj) UNRELEASED; urgency=medium
   * An internal error message in printrule is improved slightly.
   * Add debhelper-build-stamp to .gitignore.
   * Permit new foundry names to contain "."s.
+  * Add bdf normaliser (to cope with fontforge output directly, since
+     bdftopcf | pcf2bdf sometimes fails).
 
  -- Ian Jackson <ijackson@chiark.greenend.org.uk>  Sun, 24 Apr 2016 22:07:21 +0100
 
diff --git a/mkrules b/mkrules
index d16d6b4..3c5f935 100755 (executable)
--- a/mkrules
+++ b/mkrules
@@ -43,9 +43,9 @@ while read keyword rest; do
                                ./ffconvert.pe "$f/$pcf"
                                # 1. fontforge writes a silly filename
                                # 2. our crappy machinery copes only
-                               #  with BDFs from pcf2bdf, not from
-                               #  fontforge
-                               bdftopcf <"$f/$pcf".BDF*.bdf |pcf2bdf >$out
+                               #  with BDFs all of whose chars have
+                               #  the bbox of the font
+                               ./bdfnorm <"$f/$pcf".BDF*.bdf >$out
                        else
                                echo >&2 "cannot make $out!"
                                exit 1