source: trunk/termtv/utils/bdf2fontdescr.pl@ 18513

Last change on this file since 18513 was 17407, checked in by tbretz, 11 years ago
First version.
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/usr/bin/perl
2use warnings;
3use strict;
4
5# convert from *unicode* x11 bdf files to the font description used in makefont.pl
6
7die "Usage: perl $0 < input.bcf > output.txt" if -t STDIN or @ARGV;
8
9sub handle_char {
10 my ($char) = @_;
11
12 my $bitmap_data;
13 my $codepoint;
14 my ($bbx_h, $bbx_w, $bbx_x, $bbx_y);
15
16 for ( grep { defined and length } split /\n/, $char ) {
17 if ( /^ENCODING (\d+)$/ ) {
18 $codepoint = $1;
19 } elsif ( /^BBX\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s*$/ ) {
20 ($bbx_w, $bbx_h, $bbx_x, $bbx_y) = ($1,$2,$3,$4);
21 } elsif ( /^BITMAP(.*)$/ ) {
22 $bitmap_data = $1;
23 } elsif ( defined $bitmap_data ) {
24 $bitmap_data .= "\n$_";
25 }
26 }
27
28 die "bad char: no bitmap\n$char" unless defined $bitmap_data;
29 die "bad char: no codepoint\n$char" unless defined $codepoint;
30 die "bad char: no bounding box\n$char" unless defined $bbx_h;
31
32 print "\nU+".unpack("H4", pack "n", $codepoint)."\n";
33 for my $row ( grep { defined and length } split /\s+/, $bitmap_data ) {
34 my $bits = unpack "B*", pack "H*", $row;
35 $bits = substr $bits, 0, $bbx_w; # doesn't work??
36 $bits =~ tr/01/.X/;
37 print "$bits\n";
38 }
39}
40
41print "# generated with bdf2fontdescr.pl\n";
42
43my $char;
44while ( <STDIN> ) {
45 tr/[\r\n]//d;
46
47 if ( /^FONT (.+)$/ ) {
48 warn "Font does not appear to be an ISO10646 (Unicode) font.\n"
49 if !/-ISO10646-/i && !/-iso8859-1/i; # ISO8859-1 has the same codepoints
50 } elsif ( /^STARTCHAR/ ) {
51 $char = '';
52 } elsif ( /^ENDCHAR/ ) {
53 handle_char($char);
54 undef $char;
55 } elsif ( /^COMMENT (.+)$/ ) {
56 print "# $1\n";
57 } elsif ( defined $char ) {
58 $char .= $_."\n";
59 }
60}
61
Note: See TracBrowser for help on using the repository browser.