#!/usr/bin/perl -w
use strict;
use Pt2500pc;
use GD;
use Data::Dumper;

#my $pt = new Pt2500pc('/dev/ttyS1');
my $pt = new Pt2500pc('/dev/bus/usb/005/008');
die "Error: $pt->{error}" if $pt->{error};

sub label($$) {
    my ($text,$font) = @_;

    my $fy = $pt->{pixelwidth}-20;
    my $fh = $pt->{pixelwidth}-35;

    my @bounds = GD::Image->stringFT(-1, $font, $fh, 0, -3, $fy, $text);
    my $width = $bounds[2];    

    my $img = new GD::Image($width, $pt->{pixelwidth});
    print STDERR "Label $text is $width x $pt->{pixelwidth}\n";
    $img->colorAllocate(255,255,255);
    $img->colorAllocate(0,0,0);
    $img->filledRectangle(0,0, $width, $pt->{pixelwidth}, 0);
    $img->stringFT(-1, $font, $fh, 0, -3, $fy, $text);
    
#    open PNG, "|display";
#    print PNG $img->png;
#    close PNG;

    return $img;
}

#my $FONT = '/home/ff/projects/InfoPusher/gl/data/arial.ttf';
my $FONT = '/usr/share/fonts/truetype/freefont/FreeSans.ttf';
#my $FONT = '/home/ff/projects/Gargh/tests/postscript/ocrbms.ttf';

my @images = map { chomp; label($_, $FONT); } <DATA>;
$pt->print(@images);


__DATA__
Vidkærvej 1
