3 # a SDL perl extension for SDL_ttf support
5 # Copyright (C) David J. Goehrig 2002
18 @ISA = qw(SDL::Surface);
22 my $class = ref($proto) || $proto;
26 $self->{-mode} = $options{-mode} || $options{-m} || TEXT_SHADED();
27 $self->{-name} = $options{-name} || $options{-n};
28 $self->{-size} = $options{-size} || $options{-s};
29 $self->{-fg} = $options{-foreground} || $options{-fg} || $SDL::Color::black;
30 $self->{-bg} = $options{-background} || $options{-bg} || $SDL::Color::white;
32 croak "SDL::TTFont::new requires a -name\n"
33 unless ($$self{-name});
35 croak "SDL::TTFont::new requires a -size\n"
36 unless ($$self{-size});
38 $self->{-font} = SDL::TTFOpenFont($self->{-name},$self->{-size});
40 croak "Could not open font $$self{-name}, ", SDL::GetError(), "\n"
41 unless ($self->{-font});
49 SDL::FreeSurface($self->{-surface});
50 SDL::TTFCloseFont($self->{-font});
54 my ($self,$surface,$x,$y,@text) = @_;
56 croak "Print requies an SDL::Surface"
57 unless( ref($surface) && $surface->isa("SDL::Surface") );
59 SDL::FreeSurface($self->{-surface}) if ($$self{-surface});
61 $$self{-surface} = SDL::TTFPutString($$self{-font},$$self{-mode},
62 $$surface,$x,$y,${$$self{-fg}},${$$self{-bg}},join("",@text));
64 croak "Could not print \"", join("",@text), "\" to surface, ",
65 SDL::GetError(), "\n" unless ($$self{-surface});
69 my ($self,@text) = @_;
70 my $aref = SDL::TTFSizeText($$self{-font},join(" ",@text));
76 SDL::TTFFontHeight($$self{-font});
81 SDL::TTFFontAscent($$self{-font});
86 SDL::TTFFontDescent($$self{-font});
91 SDL::TTFSetFontStyle($$self{-font},TTF_STYLE_NORMAL());
96 SDL::TTFSetFontStyle($$self{-font},TTF_STYLE_BOLD());
101 SDL::TTFSetFontStyle($$self{-font},TTF_STYLE_ITALIC());
107 SDL::TTFSetFontStyle($$self{-font},TTF_STYLE_UNDERLINE());
112 $$self{-mode} = TEXT_SHADED();
117 $$self{-mode} = TEXT_SOLID();
122 $$self{-mode} = TEXT_BLENDED();
127 $$self{-mode} = UTF8_SHADED();
132 $$self{-mode} = UTF8_SOLID();
137 $$self{-mode} = UTF8_BLENDED();
142 $$self{-mode} = UNICODE_SHADED();
147 $$self{-mode} = UNICODE_SOLID();
150 sub unicode_blended {
152 $$self{-mode} = UNICODE_BLENDED();
155 croak "Could not initialize True Type Fonts\n"
156 if ( SDL::TTFInit() < 0);
166 SDL::TTFont - a SDL perl extension
170 $font = new TTFont -name => "Utopia.ttf", -size => 18;
174 L<SDL::TTFont> is a module for applying true type fonts to L<SDL::Surface>.
182 L<perl> L<SDL::Surface>