line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::WIoZ::Word; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$App::WIoZ::Word::VERSION = '0.004'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
1046
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#use feature 'say'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'text' => ( |
9
|
|
|
|
|
|
|
is => 'ro', required => 1, isa => 'Str' |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'weight' => ( |
13
|
|
|
|
|
|
|
is => 'ro', required => 0, isa => 'Int' |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'font' => ( |
17
|
|
|
|
|
|
|
is => 'rw', isa => 'HashRef', |
18
|
|
|
|
|
|
|
default => sub { {font => 'LiberationSans', type => 'normal', weight => 'bold'} } |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'width' => ( |
22
|
|
|
|
|
|
|
is => 'rw', isa => 'Int' |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'height' => ( |
26
|
|
|
|
|
|
|
is => 'rw', isa => 'Int' |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'size' => ( |
30
|
|
|
|
|
|
|
is => 'rw', isa => 'Num' |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'color' => ( |
34
|
|
|
|
|
|
|
is => 'rw', isa => 'Str' |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has 'p' => ( |
38
|
|
|
|
|
|
|
is => 'rw', isa => 'App::WIoZ::Point' |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has 'c' => ( |
42
|
|
|
|
|
|
|
is => 'rw', isa => 'App::WIoZ::Point' |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'p2' => ( |
46
|
|
|
|
|
|
|
is => 'rw', isa => 'App::WIoZ::Point' |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'show' => ( |
50
|
|
|
|
|
|
|
is => 'rw', isa => 'Int', |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has 'angle' => ( |
54
|
|
|
|
|
|
|
is => 'ro', isa => 'Str', |
55
|
|
|
|
|
|
|
default => sub {return rand(1.0) > 0.85 ? -1 * 2 * atan2(1, 1) : 0;} |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub update_c { |
59
|
|
|
|
|
|
|
my ($self,$c) = @_; |
60
|
|
|
|
|
|
|
my $th = $self->height; |
61
|
|
|
|
|
|
|
my $tl = $self->width; |
62
|
|
|
|
|
|
|
my $center = App::WIoZ::Point->new(x=>$c->x,y=>$c->y); |
63
|
|
|
|
|
|
|
my $p = App::WIoZ::Point->new(x=>$c->x-int($tl/2),y=>$c->y+int($th/2)); |
64
|
|
|
|
|
|
|
my $p2 = App::WIoZ::Point->new(x=>$c->x+int($tl/2),y=>$c->y-int($th/2)); |
65
|
|
|
|
|
|
|
$self->c($center); |
66
|
|
|
|
|
|
|
$self->p($p); |
67
|
|
|
|
|
|
|
$self->p2($p2); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub update_size { |
71
|
|
|
|
|
|
|
my ($self,$ya,$size) = @_; |
72
|
|
|
|
|
|
|
$ya->cr->select_font_face($self->font->{font},$self->font->{type},$self->font->{weight}); |
73
|
|
|
|
|
|
|
$ya->cr->set_font_size($size); |
74
|
|
|
|
|
|
|
#$ya->cr->rotate($self->angle); |
75
|
|
|
|
|
|
|
my $te = $ya->cr->text_extents ($self->text); |
76
|
|
|
|
|
|
|
my $fe = $ya->cr->font_extents; |
77
|
|
|
|
|
|
|
#my $th = $fe->{"height"};#-4*$fe->{"descent"}; |
78
|
|
|
|
|
|
|
my $th = $fe->{"height"}-2*$fe->{"descent"}; |
79
|
|
|
|
|
|
|
my $tl = $te->{"width"};#+2*$te->{"x_bearing"}; |
80
|
|
|
|
|
|
|
$self->size($size); |
81
|
|
|
|
|
|
|
if ($self->angle < 0) { |
82
|
|
|
|
|
|
|
$self->height(int($tl+2*$te->{"x_bearing"})); |
83
|
|
|
|
|
|
|
$self->width(int($th)); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
|
|
|
|
|
|
$self->height(int($th)); |
87
|
|
|
|
|
|
|
$self->width(int($tl)); |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub crange { |
92
|
|
|
|
|
|
|
my ($self,$h,$scale) = @_; |
93
|
|
|
|
|
|
|
my $x1 = ($self->p->x/$scale); |
94
|
|
|
|
|
|
|
my $y1 = ($self->p->y/$scale); |
95
|
|
|
|
|
|
|
my $x2 = ($self->p2->x/$scale); |
96
|
|
|
|
|
|
|
my $y2 = ($self->p2->y/$scale); |
97
|
|
|
|
|
|
|
my ($min, $max) = $h->rect_to_n_range ($x1,$y1, $x2,$y2); |
98
|
|
|
|
|
|
|
my ($rx1,$ry1) = $h->n_to_xy($h->xy_to_n($x1,$y1)); |
99
|
|
|
|
|
|
|
my ($rx2,$ry2) = $h->n_to_xy($h->xy_to_n($x2,$y2)); |
100
|
|
|
|
|
|
|
# say " ==> ($rx1,$ry1 $rx2,$ry2) $min,$max"; |
101
|
|
|
|
|
|
|
my @in = (); |
102
|
|
|
|
|
|
|
foreach my $n ($min .. $max) { |
103
|
|
|
|
|
|
|
my ($x,$y) = $h->n_to_xy($n); |
104
|
|
|
|
|
|
|
#say "$n $x,$y"; |
105
|
|
|
|
|
|
|
#say " . $n in" |
106
|
|
|
|
|
|
|
# if $x>=$rx1 && $x<=$rx2 && $y<= $ry1 && $y >= $ry2; |
107
|
|
|
|
|
|
|
push @in, $n |
108
|
|
|
|
|
|
|
if $x>=$rx1 && $x<=$rx2 && $y<= $ry1 && $y >= $ry2; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
#say join '-',@in; |
111
|
|
|
|
|
|
|
return @in; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub is_free { |
116
|
|
|
|
|
|
|
my ($self,$ya) = @_; |
117
|
|
|
|
|
|
|
my $curve = $ya->fcurve; |
118
|
|
|
|
|
|
|
my $scale = $ya->scale; |
119
|
|
|
|
|
|
|
my @ranges = $self->crange($curve,$scale); |
120
|
|
|
|
|
|
|
foreach my $hp (@ranges) { |
121
|
|
|
|
|
|
|
my @test = @{$ya->cused} ; |
122
|
|
|
|
|
|
|
return undef if ( grep $_ == $hp, @test ); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
return @ranges; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |