| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Imager::DTP::Line::Vertical; |
|
2
|
1
|
|
|
1
|
|
6
|
use base Imager::DTP::Line; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
97
|
|
|
3
|
|
|
|
|
|
|
use strict; |
|
4
|
|
|
|
|
|
|
use vars qw($VERSION); |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.03'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub draw { |
|
9
|
|
|
|
|
|
|
my $self = shift; |
|
10
|
|
|
|
|
|
|
my %o = @_; |
|
11
|
|
|
|
|
|
|
my $x = ($o{x})? $o{x} : 0; |
|
12
|
|
|
|
|
|
|
my $y = ($o{y})? $o{y} : 0; |
|
13
|
|
|
|
|
|
|
# re-calculate bounding box |
|
14
|
|
|
|
|
|
|
$self->_calcWidthHeight(); |
|
15
|
|
|
|
|
|
|
my $lineWidth = ($o{leading})? $o{leading} : $self->getWidth(); |
|
16
|
|
|
|
|
|
|
# draw box - debug |
|
17
|
|
|
|
|
|
|
if($o{debug}){ |
|
18
|
|
|
|
|
|
|
$o{target}->box(filled=>1,color=>'#EFEFEF',xmin=>$x,ymin=>$y,xmax=>$x+$lineWidth, |
|
19
|
|
|
|
|
|
|
ymax=>$y+$self->getHeight()); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
foreach my $ltr (@{$self->getLetters()}){ |
|
22
|
|
|
|
|
|
|
my $nowx = sprintf("%.0f",($lineWidth - $ltr->getAdvancedWidth()) / 2) + $x; |
|
23
|
|
|
|
|
|
|
$ltr->draw(target=>$o{target},x=>$nowx,y=>$y,debug=>$o{debug}, |
|
24
|
|
|
|
|
|
|
others=>$o{others}); |
|
25
|
|
|
|
|
|
|
$y += $ltr->getGlobalAscent() - $ltr->getGlobalDescent + $self->getWspace(); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
return 1; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _calcWidthHeight { |
|
31
|
|
|
|
|
|
|
my $self = shift; |
|
32
|
|
|
|
|
|
|
return undef if($self->{isUpdated}); |
|
33
|
|
|
|
|
|
|
return undef if(@{$self->getLetters()} == 0); |
|
34
|
|
|
|
|
|
|
my %o = @_; |
|
35
|
|
|
|
|
|
|
my ($w,$h,$a,$d) = qw(0 0 0 0); |
|
36
|
|
|
|
|
|
|
my $wspace = $self->getWspace(); |
|
37
|
|
|
|
|
|
|
foreach my $ltr (@{$self->getLetters()}){ |
|
38
|
|
|
|
|
|
|
$ltr->_calcWidthHeight(); |
|
39
|
|
|
|
|
|
|
$w = ($ltr->getWidth() > $w)? $ltr->getWidth() : $w; |
|
40
|
|
|
|
|
|
|
$h += $ltr->getGlobalAscent() - $ltr->getGlobalDescent + $wspace; |
|
41
|
|
|
|
|
|
|
$a = ($ltr->getGlobalAscent() > $a)? $ltr->getGlobalAscent() : $a; |
|
42
|
|
|
|
|
|
|
# remember, descent is a negative integer |
|
43
|
|
|
|
|
|
|
$d = ($ltr->getGlobalDescent() < $d)? $ltr->getGlobalDescent() : $d; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
$h -= $wspace; # don't need the last wspace |
|
46
|
|
|
|
|
|
|
$self->{height} = $h; |
|
47
|
|
|
|
|
|
|
$self->{width} = $w; |
|
48
|
|
|
|
|
|
|
$self->{ascent} = $a; |
|
49
|
|
|
|
|
|
|
$self->{descent} = $d; |
|
50
|
|
|
|
|
|
|
$self->{isUpdated} = 1; |
|
51
|
|
|
|
|
|
|
return 1; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _setText_parse { |
|
55
|
|
|
|
|
|
|
my $self = shift; |
|
56
|
|
|
|
|
|
|
my %o = @_; |
|
57
|
|
|
|
|
|
|
my ($i,$skip) = qw(0 0); |
|
58
|
|
|
|
|
|
|
my @text = split(//,$o{text}); |
|
59
|
|
|
|
|
|
|
foreach my $t (@text){ |
|
60
|
|
|
|
|
|
|
if($skip){ |
|
61
|
|
|
|
|
|
|
$skip=0; $i++; next; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
my $ltr; |
|
64
|
|
|
|
|
|
|
# if special letter |
|
65
|
|
|
|
|
|
|
if($self->_isDoubleDigitNum($i,\@text)){ |
|
66
|
|
|
|
|
|
|
$ltr = Imager::DTP::Letter->new(text=>$t.$text[$i+1],font=>$o{font}); |
|
67
|
|
|
|
|
|
|
# skip the next $t loop |
|
68
|
|
|
|
|
|
|
$skip=1; |
|
69
|
|
|
|
|
|
|
# normal text |
|
70
|
|
|
|
|
|
|
}else{ |
|
71
|
|
|
|
|
|
|
$ltr = Imager::DTP::Letter->new(text=>$t,font=>$o{font}); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
push(@{$self->{letters}},$ltr) if($ltr); |
|
74
|
|
|
|
|
|
|
$i++; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
return 1; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _isDoubleDigitNum { |
|
80
|
|
|
|
|
|
|
my ($self,$i,$txt) = @_; |
|
81
|
|
|
|
|
|
|
return ( $txt->[$i] =~ /[0-9]/ && |
|
82
|
|
|
|
|
|
|
(defined($txt->[$i+1]) && $txt->[$i+1] =~ /[0-9]/) && |
|
83
|
|
|
|
|
|
|
(!defined($txt->[$i-1]) || (defined($txt->[$i-1]) && $txt->[$i-1] !~ /[0-9]/)) && |
|
84
|
|
|
|
|
|
|
(!defined($txt->[$i+2]) || (defined($txt->[$i+2]) && $txt->[$i+2] !~ /[0-9]/)) ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _isTwoCapitalLetters { |
|
88
|
|
|
|
|
|
|
my ($self,$i,$txt) = @_; |
|
89
|
|
|
|
|
|
|
return ( $txt->[$i] =~ /[A-Z]/ && |
|
90
|
|
|
|
|
|
|
(defined($txt->[$i+1]) && $txt->[$i+1] =~ /[A-Z]/) && |
|
91
|
|
|
|
|
|
|
(!defined($txt->[$i-1]) || (defined($txt->[$i-1]) && $txt->[$i-1] !~ /[A-Z]/)) && |
|
92
|
|
|
|
|
|
|
(!defined($txt->[$i+2]) || (defined($txt->[$i+2]) && $txt->[$i+2] !~ /[A-Z]/)) ); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
__END__ |