line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Imager::DTP::Textbox::Horizontal; |
2
|
2
|
|
|
2
|
|
46817
|
use base Imager::DTP::Textbox; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1247
|
|
3
|
2
|
|
|
2
|
|
1452
|
use Imager::DTP::Line::Horizontal; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use strict; |
5
|
|
|
|
|
|
|
use vars qw($VERSION); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub _draw_drawLines { |
10
|
|
|
|
|
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
my %o = @_; |
12
|
|
|
|
|
|
|
my $i=0; |
13
|
|
|
|
|
|
|
my $x=($o{x})? $o{x} : 0; |
14
|
|
|
|
|
|
|
my $y=($o{y})? $o{y} : 0; |
15
|
|
|
|
|
|
|
# draw box for debug |
16
|
|
|
|
|
|
|
if($o{debug}){ |
17
|
|
|
|
|
|
|
my $dbgy = $self->_draw_getAlignPos(y=>$y); |
18
|
|
|
|
|
|
|
my $width = ($self->getWrapWidth())? $self->getWrapWidth() : $self->_getWidth(); |
19
|
|
|
|
|
|
|
my $height = ($self->getWrapHeight())? $self->getWrapHeight() : $self->_getHeight(); |
20
|
|
|
|
|
|
|
$o{target}->box(filled=>1,color=>'#BBBBBB',xmin=>$x,ymin=>$dbgy, |
21
|
|
|
|
|
|
|
xmax=>$x+$width,ymax=>$dbgy+$height); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
my $lineHeight = $self->_getMaxLetterSize(); |
24
|
|
|
|
|
|
|
my $lineSpace = $self->_calcLineSpace(); |
25
|
|
|
|
|
|
|
foreach my $line (@{$self->getLines()}){ |
26
|
|
|
|
|
|
|
# line flaws top to down |
27
|
|
|
|
|
|
|
if($i > 0){ |
28
|
|
|
|
|
|
|
$y += $lineHeight; |
29
|
|
|
|
|
|
|
$y += $lineSpace; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
# horizontal align |
32
|
|
|
|
|
|
|
my $linex = $x; |
33
|
|
|
|
|
|
|
if($self->getHalign() eq 'right'){ |
34
|
|
|
|
|
|
|
$linex += $self->_getWidth() - $line->getWidth(); |
35
|
|
|
|
|
|
|
}elsif($self->getHalign() eq 'center'){ |
36
|
|
|
|
|
|
|
$linex += ( $self->_getWidth() - $line->getWidth() )/2; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
# vertical align |
39
|
|
|
|
|
|
|
my $liney = $self->_draw_getAlignPos(y=>$y); |
40
|
|
|
|
|
|
|
# draw line |
41
|
|
|
|
|
|
|
$line->draw(target=>$o{target},x=>$linex,y=>$liney,leading=>$lineHeight, |
42
|
|
|
|
|
|
|
others=>$o{others},debug=>$o{debug}) or die $line->errstr; |
43
|
|
|
|
|
|
|
$i++; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
return 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _draw_getAlignPos { |
49
|
|
|
|
|
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
my %o = @_; |
51
|
|
|
|
|
|
|
if($self->getValign() eq 'bottom'){ |
52
|
|
|
|
|
|
|
$o{y} -= $self->_getHeight(); |
53
|
|
|
|
|
|
|
}elsif($self->getValign() eq 'center'){ |
54
|
|
|
|
|
|
|
$o{y} -= $self->_getHeight()/2; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
return $o{y}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _draw_getStartPos { |
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
my %o = @_; |
62
|
|
|
|
|
|
|
if($self->getHalign() eq 'right'){ |
63
|
|
|
|
|
|
|
return ($o{x}-$self->_getWidth(),$o{y}); |
64
|
|
|
|
|
|
|
}elsif($self->getHalign() eq 'center'){ |
65
|
|
|
|
|
|
|
return ( $o{x} - ($self->_getWidth()/2), $o{y} ); |
66
|
|
|
|
|
|
|
}else{ |
67
|
|
|
|
|
|
|
return ($o{x},$o{y}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _calcWidthHeight { |
72
|
|
|
|
|
|
|
my $self = shift; |
73
|
|
|
|
|
|
|
return undef if($self->{isUpdated}); |
74
|
|
|
|
|
|
|
foreach my $line (@{$self->getLines()}){ |
75
|
|
|
|
|
|
|
$line->_calcWidthHeight(); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
my($w,$h,$i) = qw(0 0 0); |
78
|
|
|
|
|
|
|
my $lineHeight = $self->_getMaxLetterSize(); |
79
|
|
|
|
|
|
|
my $lineSpace = $self->_calcLineSpace(); |
80
|
|
|
|
|
|
|
foreach my $line (@{$self->getLines()}){ |
81
|
|
|
|
|
|
|
$h += $lineHeight; |
82
|
|
|
|
|
|
|
$h += $lineSpace if($i < $#{$self->getLines()}); |
83
|
|
|
|
|
|
|
$h += -$line->getDescent() if($i == $#{$self->getLines()}); |
84
|
|
|
|
|
|
|
$w = ($line->getWidth() > $w) ? $line->getWidth() : $w; |
85
|
|
|
|
|
|
|
$i++; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
$self->{width} = $w; |
88
|
|
|
|
|
|
|
$self->{height} = $h; |
89
|
|
|
|
|
|
|
$self->{isUpdated} = 1; |
90
|
|
|
|
|
|
|
return 1; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _calcWrap_LetterStack_getWrapMax { |
94
|
|
|
|
|
|
|
return shift->getWrapWidth(); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _calcWrap_LetterStack_getLineMax { |
98
|
|
|
|
|
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
my %o = @_; |
100
|
|
|
|
|
|
|
return $o{line}->getWidth(); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _calcWrap_LetterStack_getLetterSize { |
104
|
|
|
|
|
|
|
my $self = shift; |
105
|
|
|
|
|
|
|
my %o = @_; |
106
|
|
|
|
|
|
|
return $o{letter}->getAdvancedWidth(); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _calcWrap_LineStack_getWrapMax { |
110
|
|
|
|
|
|
|
return shift->getWrapHeight(); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _setAlign_setDefault { |
114
|
|
|
|
|
|
|
my $self = shift; |
115
|
|
|
|
|
|
|
$self->{halign} = 'left' if(!$self->{halign}); |
116
|
|
|
|
|
|
|
$self->{valign} = 'top' if(!$self->{valign}); |
117
|
|
|
|
|
|
|
return 1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _getMaxLetterSize { |
121
|
|
|
|
|
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
my $highest=0; |
123
|
|
|
|
|
|
|
foreach my $line (@{$self->getLines()}){ |
124
|
|
|
|
|
|
|
$highest = ($line->getAscent() > $highest)? $line->getAscent() : $highest; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
return $highest; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _getNewLineInstance { |
130
|
|
|
|
|
|
|
my $self = shift; |
131
|
|
|
|
|
|
|
return Imager::DTP::Line::Horizontal->new(@_); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
__END__ |