summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/bdf2fbcon115
1 files changed, 78 insertions, 37 deletions
diff --git a/bin/bdf2fbcon b/bin/bdf2fbcon
index a266431..cc49432 100755
--- a/bin/bdf2fbcon
+++ b/bin/bdf2fbcon
@@ -126,6 +126,7 @@ sub convert
my $input_fh;
my $output_fh;
my $line;
+ my $font;
if ($input eq $output and $input ne "-") {
warning("Input and output files are equal");
@@ -146,12 +147,14 @@ sub convert
}
}
+ $font = init_font(%opts);
$line = readline($input_fh);
if ($line =~ m/^STARTFONT 2.[12]$/) {
- convert_bdf_2_1($input_fh, $output_fh, %opts);
+ parse_bdf_2_1($input_fh, $font);
} else {
error(4, "Unsupported input format");
}
+ write_fbcon($output_fh, $font);
if ($input ne "-") {
close($input_fh);
@@ -164,24 +167,46 @@ sub convert
}
}
-sub convert_bdf_2_1
+sub init_font
{
- my ($input_fh, $output_fh, %opts) = @_;
- my $font_w;
- my $font_h;
+ my (%opts);
+ my $font;
+ my $i;
+
+ $font = {
+ 'comments' => [],
+ 'idx' => undef,
+ 'name' => undef,
+ 'width' => undef,
+ 'height' => undef,
+ 'chars' => [],
+ };
+
+ $font->{'width'} = $opts{'w'} if (exists($opts{'w'}));
+ $font->{'height'} = $opts{'h'} if (exists($opts{'h'}));
+
+ for ($i = 0; $i < 255; ++$i) {
+ $font->{'chars'}[$i] = {
+ 'name' => 'hello',
+ 'encoding' => undef,
+ 'bitmap' => [],
+ };
+ }
+
+ return $font;
+}
+
+sub parse_bdf_2_1
+{
+ my ($input_fh, $font) = @_;
my $section;
my $found_end;
my $line;
my $stmt;
my $arg;
my @argv;
- my $font_idx;
- my $font_name;
my $char;
- $font_w = $opts{'w'} if (exists($opts{'w'}));
- $font_h = $opts{'h'} if (exists($opts{'h'}));
-
$section = BDF_2_1_SECTION_NONE;
$found_end = 0;
while ($line = readline($input_fh)) {
@@ -191,22 +216,16 @@ sub convert_bdf_2_1
($stmt, @argv) = split(/[ \t]+/, $line);
if ($section == BDF_2_1_SECTION_NONE) {
if ($stmt eq 'FONTBOUNDINGBOX') {
- $font_w = $argv[0] unless ($font_w);
- $font_h = $argv[1] unless ($font_h);
+ unless ($font->{'width'}) {
+ $font->{'width'} = $argv[0];
+ }
+ unless ($font->{'height'}) {
+ $font->{'height'} = $argv[1];
+ }
} elsif ($stmt eq 'COMMENT') {
- printf($output_fh "/* %s */\n", $arg);
+ push(@{$font->{'comments'}}, $arg);
} elsif ($stmt eq 'STARTPROPERTIES') {
- print($output_fh
- "/* Generated by bdf2fbcon */\n\n");
- print($output_fh "#include <linux/font.h>\n\n");
$section = BDF_2_1_SECTION_PROPERTIES;
- } elsif ($stmt eq 'CHARS') {
- # XXX
- printf($output_fh "#define FONTDATAMAX %d\n\n",
- 0);
- printf($output_fh "static const unsigned char" .
- " fontdata_%s[FONTDATAMAX] = {\n",
- $font_name);
} elsif ($stmt eq 'STARTCHAR') {
$char = $argv[0];
$section = BDF_2_1_SECTION_CHAR;
@@ -216,19 +235,16 @@ sub convert_bdf_2_1
}
} elsif ($section == BDF_2_1_SECTION_PROPERTIES) {
if ($stmt eq 'FONT_NAME') {
- $font_idx = uc($arg);
- $font_idx =~ s/[^A-Z0-9_]//g;
- $font_name = lc($arg);
- $font_name =~ s/[^a-z0-9_]/_/g;
+ $font->{'idx'} = uc($arg);
+ $font->{'idx'} =~ s/[^A-Z0-9_]//g;
+ $font->{'name'} = lc($arg);
+ $font->{'name'} =~ s/[^a-z0-9_]/_/g;
} elsif ($stmt eq 'ENDPROPERTIES') {
$section = BDF_2_1_SECTION_NONE;
}
} elsif ($section == BDF_2_1_SECTION_CHAR) {
if ($stmt eq 'ENCODING') {
- printf($output_fh "\n\t/* %d 0x%x '%s' */\n",
- $argv[0],
- $argv[0],
- $char);
+ $font->{'chars'}[$argv[0]]->{'name'} = $char;
} elsif ($stmt eq 'ENDCHAR') {
$section = BDF_2_1_SECTION_NONE;
}
@@ -236,14 +252,39 @@ sub convert_bdf_2_1
}
warning("Missing end of font") unless ($found_end);
+}
+
+sub write_fbcon
+{
+ my ($output_fh, $font) = @_;
+ my $i;
+ my $char;
+
+ for (@{$font->{'comments'}}) {
+ printf($output_fh "/* %s */\n", $_);
+ }
+ printf($output_fh "/* Generated by bdf2fbcon */\n\n");
+ printf($output_fh "#include <linux/font.h>\n\n");
+ # XXX
+ printf($output_fh "#define FONTDATAMAX %d\n\n", 0);
+ printf($output_fh "static const unsigned char" .
+ " fontdata_%s[FONTDATAMAX] = {\n",
+ $font->{'name'});
+
+ for ($i = 0; $i < 255; ++$i) {
+ $char = $font->{'chars'}[$i];
+ printf($output_fh "\n\t/* %d 0x%x '%s' */\n",
+ $i, $i, $char->{'name'});
+ }
printf($output_fh "\n};\n\n");
- printf($output_fh "const struct font_desc font_%s = {\n", $font_name);
- printf($output_fh "\t.idx\t= %s_IDX,\n", $font_idx);
- printf($output_fh "\t.name\t= \"%s\",\n", $font_idx);
- printf($output_fh "\t.width\t= %d,\n", $font_w);
- printf($output_fh "\t.height\t= %d,\n", $font_h);
- printf($output_fh "\t.data\t= fontdata_%s,\n", $font_name);
+ printf($output_fh "const struct font_desc font_%s = {\n",
+ $font->{'name'});
+ printf($output_fh "\t.idx\t= %s_IDX,\n", $font->{'idx'});
+ printf($output_fh "\t.name\t= \"%s\",\n", $font->{'idx'});
+ printf($output_fh "\t.width\t= %d,\n", $font->{'width'});
+ printf($output_fh "\t.height\t= %d,\n", $font->{'height'});
+ printf($output_fh "\t.data\t= fontdata_%s,\n", $font->{'name'});
# XXX
printf($output_fh "\t.pref\t= ???,\n");
printf($output_fh "};\n");