https://bitbucket.org/hudson/magic-lantern
Revision 9c3b8683360c90c018916001cb0b26e6151d98b3 authored by hudson@kremvax on 09 August 2009, 20:27:14 UTC, committed by hudson@kremvax on 09 August 2009, 20:27:14 UTC
1 parent b4b34d2
Raw File
Tip revision: 9c3b8683360c90c018916001cb0b26e6151d98b3 authored by hudson@kremvax on 09 August 2009, 20:27:14 UTC
Add menu timeout config. Fix bug 63
Tip revision: 9c3b868
mkfont
#!/usr/bin/perl
#
# Generate a program-space font definition from a textual representation.
# For speed in representation, each 8-line character is split into
# separate bytes, stripped by the line number.
#
use warnings;
use strict;
use Getopt::Long;

my $font_width		= 8;
my $font_height		= 12;
my $font_type		= 'const unsigned';
my $font_name		= 'font';

GetOptions(
	"name=s"		=> \$font_name,
	"width=i"		=> \$font_width,
	"height=i"		=> \$font_height,
) or die "$0: Bad argument\n";


print <<"";
#include "font.h"
struct font ${font_name} = {
	.width		= $font_width,
	.height		= $font_height,
	.bitmap		= {

# Paragraph mode
$/ = "\n\n";

my $index = 0;
my $base = ord( ' ' );
my $offset = 0;

while(<>)
{
	my ($key,@rows) = split /\n/;

	my ($pos) = $key =~ /^(.) =/;

	for my $line (0..$font_height-1)
	{
		my $row = $rows[ $line ] || ( ' ' x $font_width );
		# Pad with spaces to the width of the font
		$row .= ' ' x (32 - length($row));

		my $bits = $row;
		$bits =~ s/[^ ]/1/g;
		$bits =~ s/[ ]/0/g;

		# Fix $pos for special chars
		$pos = "\\$pos" if $pos eq '\\' or $pos eq '\'';

		my $val = unpack( "N", pack( "B*", $bits ) );

		printf "[ '%s' + (%2d << 7) ] = 0x%08x, // $row\n",
			$pos,
			$line,
			$val;
	}

	print "\n";
}


print <<"";
	},
};

__END__
back to top