source: git/lib/make-pixel-font @ 08e858b

line_contentsproj-api-updatestereo
Last change on this file since 08e858b was d4d6909, checked in by Olly Betts <olly@…>, 11 years ago

lib/make-pixel-font,src/glbitmapfont.cc,src/glbitmapfont.h: Space the
glyphs to leave a one pixel gap either side of each one (so two
between adjacent glyphs). Mostly this reduces the horizontal width,
but it adds a pixel for characters like "m" and two in a few cases.

git-svn-id: file:///home/survex-svn/survex/trunk@3857 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100755
File size: 2.0 KB
Line 
1#!/usr/bin/perl
2use warnings;
3use strict;
4
5my %bitno = (0 => 0);
6for (0 .. 31) {
7    $bitno{1 << $_} = $_;
8}
9
10my $last_ch = -1;
11open U, '<', '/usr/share/unifont/unifont.hex' or die $!;
12open O, '>', 'unifont.pixelfont' or die $!;
13while (<U>) {
14    my ($ch, $hex) = /^([[:xdigit:]]+):([[:xdigit:]]+)$/;
15    if (!defined $ch) {
16        print "Bad line: $_";
17        next;
18    }
19    $ch = hex($ch);
20#    print "$ch:\n";
21
22    while (++$last_ch < $ch) {
23        # print "Missing entry for ".($last_ch - 1 )."\n";
24        print O pack 'C', 0x00;
25    }
26
27    # $len is 0, 2 or 4
28    my $len = length($hex) / 16;
29    my $packcode;
30    if ($len == 4) {
31        $packcode = 'n';
32    } elsif ($len == 2) {
33        $packcode = 'C';
34    } elsif ($len == 0) {
35        $packcode = '';
36    } else {
37        die "No handling for len = $len\n";
38    }
39    my $data = '';
40    my $start;
41    my $n = 0;
42    my $pixels_set = 0;
43    my $width = $len * 4;
44    if ($len) {
45        my @data = ();
46        for (0 .. 15) {
47            my $c = substr($hex, (15 - $_) * $len, $len);
48            my $row = hex($c);
49            $pixels_set |= $row;
50            if (!defined $start) {
51                # Skip blank rows at the bottom.
52                next unless $row;
53                $start = $_;
54            }
55            $n = $_ if $row;
56            push @data, $row;
57
58#       my $b = sprintf $fmt, $row;
59#       $b =~ y/01/ @/;
60#       print "\t$b\n";
61        }
62
63        my $left_gap = 0;
64        my $lsb_used = $pixels_set & -$pixels_set;
65        my $msb_used = 1 << ($len * 4 - 1);
66        while ($msb_used > $pixels_set) {
67            $msb_used >>= 1;
68            ++$left_gap;
69        }
70        $data = join '', map {pack($packcode, $_ << $left_gap)} @data;
71        my $right_gap = $bitno{$lsb_used} + $left_gap;
72        $right_gap = 0 if ($left_gap == 16);
73        $width -= $right_gap;
74    } else {
75        $width -= 2;
76    }
77
78    if (!defined $start) {
79        # No set pixels.
80        print O pack 'C', ($len * 4 - 4);
81        die "not really empty!" unless $hex =~ /^0*$/;
82    } else {
83        die "really empty!" if $hex =~ /^0*$/;
84        $n = $n + 1 - $start;
85        print O pack 'C', (($len / 2) << 6) | $width;
86        print O pack 'C', ($start << 4) | ($n - 1);
87        die "too little data (".length($data)." < ".$n."*".($len/2).")" if length($data) < $n * $len/2;
88        print O substr($data, 0, $n * $len / 2);
89    }
90}
91close O or die $!;
Note: See TracBrowser for help on using the repository browser.