| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Imager::DTP::Line; |
|
2
|
2
|
|
|
2
|
|
12
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
67
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
131
|
|
|
4
|
2
|
|
|
2
|
|
2433
|
use utf8; |
|
|
2
|
|
|
|
|
20
|
|
|
|
2
|
|
|
|
|
9
|
|
|
5
|
2
|
|
|
2
|
|
1177
|
use Imager::DTP::Letter; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use vars qw($VERSION); |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.05'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
|
|
|
|
|
|
my $self = shift; |
|
12
|
|
|
|
|
|
|
my %o = @_; |
|
13
|
|
|
|
|
|
|
my $p = { |
|
14
|
|
|
|
|
|
|
letters => [], |
|
15
|
|
|
|
|
|
|
width => 0, |
|
16
|
|
|
|
|
|
|
height => 0, |
|
17
|
|
|
|
|
|
|
ascent => 0, |
|
18
|
|
|
|
|
|
|
descent => 0, |
|
19
|
|
|
|
|
|
|
wspace => 0, |
|
20
|
|
|
|
|
|
|
# check flag for _calcWidthHeight needs |
|
21
|
|
|
|
|
|
|
isUpdated => 0, |
|
22
|
|
|
|
|
|
|
# check flag enabled for lines created during text-wrap |
|
23
|
|
|
|
|
|
|
isWrap => (defined($o{isWrap}))? $o{isWrap} : 0, |
|
24
|
|
|
|
|
|
|
}; |
|
25
|
|
|
|
|
|
|
$self = bless($p,$self); |
|
26
|
|
|
|
|
|
|
$self->setWspace(pixel=>$o{wspace}) if($o{wspace}); |
|
27
|
|
|
|
|
|
|
if($o{text}){ |
|
28
|
|
|
|
|
|
|
$self->setText(text=>$o{text},font=>$o{font}); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
if($o{xscale} || $o{yscale}){ |
|
31
|
|
|
|
|
|
|
$self->setLetterScale(x=>$o{xscale},y=>$o{yscale}); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
return $self; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub draw { |
|
37
|
|
|
|
|
|
|
confess "draw - this is an abstract method"; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub setText { |
|
41
|
|
|
|
|
|
|
my $self = shift; |
|
42
|
|
|
|
|
|
|
my %o = @_; |
|
43
|
|
|
|
|
|
|
# get last letter's font preference |
|
44
|
|
|
|
|
|
|
if(!defined($o{font}) && @{$self->{letters}} > 0){ |
|
45
|
|
|
|
|
|
|
$o{font} = $self->{letters}[-1]{font}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
# validation |
|
48
|
|
|
|
|
|
|
if(ref($o{font}) !~ /^Imager::Font(::.+)?$/){ |
|
49
|
|
|
|
|
|
|
confess "font: must define an Imager::Font Object"; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
$o{text} = ' ' if(!defined($o{text})); # to create a blank line |
|
52
|
|
|
|
|
|
|
$o{text} =~ s/\r\n/\n/g; # replace CR+LF to LF |
|
53
|
|
|
|
|
|
|
$o{text} =~ s/\r/\n/g; # replace CR to LF |
|
54
|
|
|
|
|
|
|
$o{text} =~ s/\n/ /g; # replace line feeds to space |
|
55
|
|
|
|
|
|
|
$o{text} =~ s/\t/ /g; # replace tabs to 4 spaces |
|
56
|
|
|
|
|
|
|
# clear current letters |
|
57
|
|
|
|
|
|
|
$self->{letters} = [] if(!$o{add}); |
|
58
|
|
|
|
|
|
|
$self->_setText_parse(text=>$o{text},font=>$o{font}); |
|
59
|
|
|
|
|
|
|
$self->{isUpdated} = 0; |
|
60
|
|
|
|
|
|
|
return 1; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _setText_parse { |
|
64
|
|
|
|
|
|
|
confess "_setText_parse - this is an abstract method"; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub setWspace { |
|
68
|
|
|
|
|
|
|
my $self = shift; |
|
69
|
|
|
|
|
|
|
my %o = @_; |
|
70
|
|
|
|
|
|
|
if(defined($o{pixel}) && $o{pixel} !~ /^(-)?\d+$/){ |
|
71
|
|
|
|
|
|
|
confess "pixel: must be an integer ($o{pixel})"; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
$self->{wspace} = (defined $o{pixel})? $o{pixel} : 0; |
|
74
|
|
|
|
|
|
|
$self->{isUpdated} = 0; |
|
75
|
|
|
|
|
|
|
return 1; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub setLetterScale { |
|
79
|
|
|
|
|
|
|
my $self = shift; |
|
80
|
|
|
|
|
|
|
my %o = @_; |
|
81
|
|
|
|
|
|
|
foreach my $ltr (@{$self->getLetters()}){ |
|
82
|
|
|
|
|
|
|
$ltr->setScale(@_); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
return 1; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _calcWidthHeight { |
|
88
|
|
|
|
|
|
|
confess "_calcWidthHeight - this is an abstract method"; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub getLetters { |
|
92
|
|
|
|
|
|
|
return shift->{letters}; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
sub getWidth { |
|
95
|
|
|
|
|
|
|
my $self = shift; |
|
96
|
|
|
|
|
|
|
$self->_calcWidthHeight(); |
|
97
|
|
|
|
|
|
|
return $self->{width}; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
sub getHeight { |
|
100
|
|
|
|
|
|
|
my $self = shift; |
|
101
|
|
|
|
|
|
|
$self->_calcWidthHeight(); |
|
102
|
|
|
|
|
|
|
return $self->{height}; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
sub getAscent { |
|
105
|
|
|
|
|
|
|
my $self = shift; |
|
106
|
|
|
|
|
|
|
$self->_calcWidthHeight(); |
|
107
|
|
|
|
|
|
|
return $self->{ascent}; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
sub getDescent { |
|
110
|
|
|
|
|
|
|
my $self = shift; |
|
111
|
|
|
|
|
|
|
$self->_calcWidthHeight(); |
|
112
|
|
|
|
|
|
|
return $self->{descent}; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
sub getWspace { |
|
115
|
|
|
|
|
|
|
return shift->{wspace}; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
|
119
|
|
|
|
|
|
|
__END__ |