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