5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
7 # ------------------------------------------------------------------------------
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
39 @ISA = qw(SDL::Surface);
43 my $class = ref($proto) || $proto;
47 $self->{-mode} = $options{-mode} || $options{-m} || SDL::TEXT_SHADED();
48 $self->{-name} = $options{-name} || $options{-n};
49 $self->{-size} = $options{-size} || $options{-s};
50 $self->{-fg} = $options{-foreground} || $options{-fg} || $SDL::Color::black;
51 $self->{-bg} = $options{-background} || $options{-bg} || $SDL::Color::white;
53 die "SDL::TTFont::new requires a -name\n"
54 unless ($$self{-name});
56 die "SDL::TTFont::new requires a -size\n"
57 unless ($$self{-size});
59 $self->{-font} = SDL::TTFOpenFont($self->{-name},$self->{-size});
61 die "Could not open font $$self{-name}, ", SDL::GetError(), "\n"
62 unless ($self->{-font});
70 SDL::FreeSurface($self->{-surface});
71 SDL::TTFCloseFont($self->{-font});
75 my ($self,$surface,$x,$y,@text) = @_;
77 die "Print requies an SDL::Surface"
78 unless( ref($surface) && $surface->isa("SDL::Surface") );
80 SDL::FreeSurface($self->{-surface}) if ($$self{-surface});
82 $$self{-surface} = SDL::TTFPutString($$self{-font},$$self{-mode},
83 $$surface,$x,$y,${$$self{-fg}},${$$self{-bg}},join("",@text));
85 die "Could not print \"", join("",@text), "\" to surface, ",
86 SDL::GetError(), "\n" unless ($$self{-surface});
90 my ($self,@text) = @_;
91 my $aref = SDL::TTFSizeText($$self{-font},join(" ",@text));
97 SDL::TTFFontHeight($$self{-font});
102 SDL::TTFFontAscent($$self{-font});
107 SDL::TTFFontDescent($$self{-font});
112 SDL::TTFSetFontStyle($$self{-font},SDL::TTF_STYLE_NORMAL());
117 SDL::TTFSetFontStyle($$self{-font},SDL::TTF_STYLE_BOLD());
122 SDL::TTFSetFontStyle($$self{-font},SDL::TTF_STYLE_ITALIC());
128 SDL::TTFSetFontStyle($$self{-font},SDL::TTF_STYLE_UNDERLINE());
133 $$self{-mode} = SDL::TEXT_SHADED();
138 $$self{-mode} = SDL::TEXT_SOLID();
143 $$self{-mode} = SDL::TEXT_BLENDED();
148 $$self{-mode} = SDL::UTF8_SHADED();
153 $$self{-mode} = SDL::UTF8_SOLID();
158 $$self{-mode} = SDL::UTF8_BLENDED();
163 $$self{-mode} = SDL::UNICODE_SHADED();
168 $$self{-mode} = SDL::UNICODE_SOLID();
171 sub unicode_blended {
173 $$self{-mode} = SDL::UNICODE_BLENDED();
176 die "Could not initialize True Type Fonts\n"
177 if ( SDL::TTFInit() < 0);
187 SDL::TTFont - a SDL perl extension
191 $font = new TTFont -name => "Utopia.ttf", -size => 18;
195 L<SDL::TTFont> is a module for applying true type fonts to L<SDL::Surface>.
203 L<perl> L<SDL::Surface>