Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1KB

  1. #!/usr/bin/perl
  2. use strict;
  3. # This script converts "space-dot" fonts to binary "glyph rows". One byte for
  4. # each row. In a 5x7 font, each glyph thus use 7 bytes.
  5. # Resulting bytes are aligned to the **left** of the byte. Therefore, for
  6. # a 5-bit wide char, ". . ." translates to 0b10101000
  7. # Left-aligned bytes are easier to work with when compositing glyphs.
  8. my $fn = @ARGV[0];
  9. unless ($fn =~ /.*(\d)x(\d)\.txt/) { die "$fn isn't a font filename" };
  10. my ($width, $height) = ($1, $2);
  11. if ($width > 8) { die "Can't have a width > 8"; }
  12. print STDERR "Reading a $width x $height font.\n";
  13. my $handle;
  14. unless (open($handle, '<', $fn)) { die "Can't open $fn"; }
  15. # We start the binary data with our first char, space, which is not in our input
  16. # but needs to be in our output.
  17. print pack('C*', (0) x $height);
  18. while (<$handle>) {
  19. unless (/( |\.){0,${width}}\n/) { die "Invalid line format '$_'"; }
  20. my @line = split //, $_;
  21. my $num = 0;
  22. for (my $i=0; $i<$width; $i++) {
  23. if (@line[$i] eq '.') {
  24. $num += (1 << (7-$i));
  25. }
  26. }
  27. print pack('C', $num);
  28. }