File: TTF.pm

package info (click to toggle)
libsdl-perl 2.548-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,972 kB
  • sloc: perl: 13,985; ansic: 583; makefile: 35
file content (61 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package SDLx::TTF;
use strict;
use warnings;
use Carp;

use SDL;
use SDL::TTF;
use SDL::TTF::Font;

our $VERSION = 2.548;

sub new
{
  my ($class, $font) = @_;

	my $self = {};

	unless ( SDL::Config->has('SDL_ttf') ) {
		Carp::cluck("SDL_ttf support has not been compiled");
	}
	unless ( SDL::TTF::was_init() )
	{
	   Carp::cluck ("Cannot init TTF: " . SDL::get_error() ) unless SDL::TTF::init() == 0;
	   $self->{inited} = 1;	
	   $self->{style} = {
		normal => TTF_STYLE_NORMAL,
		bold   => TTF_STYLE_BOLD,
		italic => TTF_STYLE_ITALIC,
		underline => TTF_STYLE_UNDERLINE,
		strikethrough => TTF_STYLE_STRIKETHROUGH
		};
	}

	my $ttf_font;
	unless ( $ttf_font = SDL::TTF::open_font($font, $size ))
	{
	
   	   Carp::cluck ("Cannot make a TTF font from location ($font) or size($size), due to: ". SDL::get_error );

	} 

	$self->{ttf_font} = $ttf_font;
	
	if (  $style && ( my $t_style = $self->{style}->{$style} )  )
	{
		 SDL::TTF::set_font_style($ttf_font, $t_style);
	}
	
	
  return bless $self, $class;
 
}


sub DESTROY {
	my $self = shift;
	SDL::TTF::quit if $self->{inited};

}

1;