2 # SDL::Tool::Font - format agnostic font tool
4 # Copyright (C) 2002 David J. Goehrig
6 package SDL::Tool::Font;
18 my $class = ref($proto) || $proto;
22 verify (%option, qw/ -sfont -ttfont -size -fg -bg -foreground -background
23 -normal -bold -italic -underline / ) if $SDL::DEBUG;
25 if ($option{-sfont}) {
26 $$self{-font} = new SDL::Font $option{-sfont};
27 } elsif ($option{-ttfont} || $option{-t}) {
28 $option{-size} ||= 12;
29 $$self{-font} = new SDL::TTFont
30 -name => $option{-ttfont} || $option{-t},
31 -size => $option{-size} || $option{-s},
32 -fg => $option{-foreground} || $option{-fg} ,
33 -bg => $option{-background} || $option{-bg};
34 for (qw/ normal bold italic underline / ) {
36 &{"SDL::TTFont::$_"}($$self{-font});
40 croak "SDL::Tool::Font requires either a -sfont or -ttfont";
51 my ($self,$surface,$x,$y,@text) = @_;
52 croak "Tool::Font::print requires a SDL::Surface\n"
53 unless ($surface->isa('SDL::Surface'));
54 if ($$self{-font}->isa('SDL::Font')) {
56 SDL::SFont::PutString( $$surface, $x, $y, join('',@text));
58 $$self{-font}->print($surface,$x,$y,@text);
70 SDL::Tool::Font - a perl extension
74 L<SDL::Tool::Font> provides a unified interface for applying
75 True Type and SFont fonts to various surfaces.
79 =head2 print ( surface, x, y, text ... )
81 C<SDL::Tool::Font::print> print the given text on the supplied surface
82 with the upper left hand corner starting at the specified coordinates.
90 L<perl> L<SDL::Font> L<SDL::TTFont> L<SDL::Surface>