App-WIoZ
view release on metacpan or search on metacpan
lib/App/WIoZ/Word.pm view on Meta::CPAN
package App::WIoZ::Word;
{
$App::WIoZ::Word::VERSION = '0.004';
}
use Moose;
#use feature 'say';
has 'text' => (
is => 'ro', required => 1, isa => 'Str'
);
has 'weight' => (
is => 'ro', required => 0, isa => 'Int'
);
has 'font' => (
is => 'rw', isa => 'HashRef',
default => sub { {font => 'LiberationSans', type => 'normal', weight => 'bold'} }
);
has 'width' => (
is => 'rw', isa => 'Int'
);
has 'height' => (
is => 'rw', isa => 'Int'
);
has 'size' => (
is => 'rw', isa => 'Num'
);
has 'color' => (
is => 'rw', isa => 'Str'
);
has 'p' => (
is => 'rw', isa => 'App::WIoZ::Point'
);
has 'c' => (
is => 'rw', isa => 'App::WIoZ::Point'
);
has 'p2' => (
is => 'rw', isa => 'App::WIoZ::Point'
);
has 'show' => (
is => 'rw', isa => 'Int',
);
has 'angle' => (
is => 'ro', isa => 'Str',
default => sub {return rand(1.0) > 0.85 ? -1 * 2 * atan2(1, 1) : 0;}
);
sub update_c {
my ($self,$c) = @_;
my $th = $self->height;
my $tl = $self->width;
my $center = App::WIoZ::Point->new(x=>$c->x,y=>$c->y);
my $p = App::WIoZ::Point->new(x=>$c->x-int($tl/2),y=>$c->y+int($th/2));
my $p2 = App::WIoZ::Point->new(x=>$c->x+int($tl/2),y=>$c->y-int($th/2));
$self->c($center);
$self->p($p);
$self->p2($p2);
}
sub update_size {
my ($self,$ya,$size) = @_;
$ya->cr->select_font_face($self->font->{font},$self->font->{type},$self->font->{weight});
$ya->cr->set_font_size($size);
#$ya->cr->rotate($self->angle);
my $te = $ya->cr->text_extents ($self->text);
my $fe = $ya->cr->font_extents;
#my $th = $fe->{"height"};#-4*$fe->{"descent"};
my $th = $fe->{"height"}-2*$fe->{"descent"};
( run in 1.162 second using v1.01-cache-2.11-cpan-98e64b0badf )