| 1 | package PDF::FromHTML::Template::Element::Line; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | BEGIN { | ||
| 6 | use vars qw(@ISA); | ||
| 7 | @ISA = qw(PDF::FromHTML::Template::Element); | ||
| 8 | |||
| 9 | use PDF::FromHTML::Template::Element; | ||
| 10 | } | ||
| 11 | |||
| 12 | sub render | ||
| 13 | { | ||
| 14 | my $self = shift; | ||
| 15 | my ($context) = @_; | ||
| 16 | |||
| 17 | return 0 unless $self->should_render($context); | ||
| 18 | |||
| 19 | return 1 if $context->{CALC_LAST_PAGE}; | ||
| 20 | |||
| 21 | my $p = $context->{PDF}; | ||
| 22 | $p->save_state; | ||
| 23 | |||
| 24 | $self->set_color($context, 'COLOR', 'both'); | ||
| 25 | |||
| 26 | my $vals = $self->make_vals($context); | ||
| 27 | |||
| 28 | my $width = $context->get($self, 'WIDTH') || 1; | ||
| 29 | |||
| 30 | $p->linewidth($width); | ||
| 31 | $p->move($vals->{X1}, $vals->{Y1}); | ||
| 32 | $p->line($vals->{X2}, $vals->{Y2}); | ||
| 33 | $p->stroke; | ||
| 34 | |||
| 35 | $p->restore_state; | ||
| 36 | |||
| 37 | return 1; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub make_vals | ||
| 41 | { | ||
| 42 | my $self = shift; | ||
| 43 | my ($context) = @_; | ||
| 44 | |||
| 45 | my ($x1, $x2, $y1, $y2) = map { $context->get($self, $_) } qw(X1 X2 Y1 Y2); | ||
| 46 | |||
| 47 | my %vals; | ||
| 48 | unless (defined $x1 && defined $x2) | ||
| 49 | { | ||
| 50 | #GGG Is the use of W a potential bug here? | ||
| 51 | my ($pw, $left, $right, $w) = map { | ||
| 52 | $context->get($self, $_) | ||
| 53 | } qw( PAGE_WIDTH LEFT_MARGIN RIGHT_MARGIN W ); | ||
| 54 | |||
| 55 | $w = $pw - $right - $left unless defined $w; | ||
| 56 | |||
| 57 | if (defined $x1) | ||
| 58 | { | ||
| 59 | $x2 = $x1 + $w; | ||
| 60 | $x2 = $right if $x2 > $right; | ||
| 61 | } | ||
| 62 | elsif (defined $x2) | ||
| 63 | { | ||
| 64 | $x1 = $x2 - $w; | ||
| 65 | $x1 = $left if $x1 < $left; | ||
| 66 | } | ||
| 67 | else | ||
| 68 | { | ||
| 69 | $x1 = $left; | ||
| 70 | $x2 = $x1 + $w; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | @vals{qw(X1 X2)} = ($x1, $x2); | ||
| 74 | |||
| 75 | unless (defined $y1 && defined $y2) | ||
| 76 | { | ||
| 77 | if (defined $y1) | ||
| 78 | { | ||
| 79 | $y2 = $y1; | ||
| 80 | } | ||
| 81 | elsif (defined $y2) | ||
| 82 | { | ||
| 83 | $y1 = $y2; | ||
| 84 | } | ||
| 85 | else | ||
| 86 | { | ||
| 87 | $y1 = $y2 = $context->get($self, 'Y'); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | @vals{qw(Y1 Y2)} = ($y1, $y2); | ||
| 91 | |||
| 92 | $self->{VALS} = \%vals; | ||
| 93 | |||
| 94 | return \%vals; | ||
| 95 | } | ||
| 96 | |||
| 97 | 1; | ||
| 98 | __END__ |