3 # a SDL perl extension for SDL_ttf support
5 # Copyright (C) David J. Goehrig 2002
16 @ISA = qw(SDL::Surface);
20 my $class = ref($proto) || $proto;
24 $self->{-mode} = $options{-mode} || $options{-m} || TEXT_SHADED();
25 $self->{-name} = $options{-name} || $options{-n};
26 $self->{-size} = $options{-size} || $options{-s};
27 $self->{-fg} = $options{-foreground} || $options{-fg} || $SDL::Color::black;
28 $self->{-bg} = $options{-background} || $options{-bg} || $SDL::Color::white;
30 die "SDL::TTFont::new requires a -name\n"
31 unless ($$self{-name});
33 die "SDL::TTFont::new requires a -size\n"
34 unless ($$self{-size});
36 $self->{-font} = SDL::TTFOpenFont($self->{-name},$self->{-size});
38 die "Could not open font $$self{-name}, ", SDL::GetError(), "\n"
39 unless ($self->{-font});
47 SDL::FreeSurface($self->{-surface});
48 SDL::TTFCloseFont($self->{-font});
52 my ($self,$surface,$x,$y,@text) = @_;
54 die "Print requies an SDL::Surface"
55 unless( ref($surface) && $surface->isa("SDL::Surface") );
57 SDL::FreeSurface($self->{-surface}) if ($$self{-surface});
59 $$self{-surface} = SDL::TTFPutString($$self{-font},$$self{-mode},
60 $$surface,$x,$y,${$$self{-fg}},${$$self{-bg}},join("",@text));
62 die "Could not print \"", join("",@text), "\" to surface, ",
63 SDL::GetError(), "\n" unless ($$self{-surface});
67 my ($self,@text) = @_;
68 my $aref = SDL::TTFSizeText($$self{-font},join(" ",@text));
74 SDL::TTFFontHeight($$self{-font});
79 SDL::TTFFontAscent($$self{-font});
84 SDL::TTFFontDescent($$self{-font});
89 SDL::TTFSetFontStyle($$self{-font},TTF_STYLE_NORMAL());
94 SDL::TTFSetFontStyle($$self{-font},TTF_STYLE_BOLD());
99 SDL::TTFSetFontStyle($$self{-font},TTF_STYLE_ITALIC());
105 SDL::TTFSetFontStyle($$self{-font},TTF_STYLE_UNDERLINE());
110 $$self{-mode} = TEXT_SHADED();
115 $$self{-mode} = TEXT_SOLID();
120 $$self{-mode} = TEXT_BLENDED();
125 $$self{-mode} = UTF8_SHADED();
130 $$self{-mode} = UTF8_SOLID();
135 $$self{-mode} = UTF8_BLENDED();
140 $$self{-mode} = UNICODE_SHADED();
145 $$self{-mode} = UNICODE_SOLID();
148 sub unicode_blended {
150 $$self{-mode} = UNICODE_BLENDED();
153 die "Could not initialize True Type Fonts\n"
154 if ( SDL::TTFInit() < 0);
164 SDL::TTFont - a SDL perl extension
168 $font = new TTFont -name => "Utopia.ttf", -size => 18;
172 L<SDL::TTFont> is a module for applying true type fonts to L<SDL::Surface>.
180 L<perl> L<SDL::Surface>