File Coverage

blib/lib/PDF/Make/Builder/Shape/Line.pm
Criterion Covered Total %
statement 32 33 96.9
branch 7 10 70.0
condition 4 6 66.6
subroutine 5 5 100.0
pod 1 1 100.0
total 49 55 89.0


line stmt bran cond sub pod time code
1             package PDF::Make::Builder::Shape::Line;
2 42     42   214 use strict;
  42         74  
  42         1165  
3 42     42   175 use warnings;
  42         63  
  42         1631  
4 42     42   165 use Object::Proto;
  42         49  
  42         2987  
5              
6             BEGIN {
7 42     42   2234 Object::Proto::define('PDF::Make::Builder::Shape::Line',
8             'fill_colour:Str:default(#000)',
9             'x:Num', 'y:Num',
10             'ex:Num', 'ey:Num',
11             'type:Str:default(solid)',
12             'dash:ArrayRef',
13             );
14 42         11700 Object::Proto::import_accessors('PDF::Make::Builder::Shape::Line');
15             }
16              
17             sub add {
18 6     6 1 14 my ($self, $builder) = @_;
19 6         19 my $page = $builder->page;
20 6         17 my $canvas = $page->canvas;
21 6         23 my $font = $builder->font;
22              
23 6   66     32 my $lx = $self->x // $page->content_x;
24 6   66     19 my $lex = ex($self) // ($page->content_x + $page->width);
25 6         16 my $ly = $self->y;
26 6         8 my $ley = ey($self);
27              
28 6 50       17 if (!defined $ly) {
29 6         16 $ly = $page->cursor_y;
30             }
31 6 50       18 $ley = defined $ley ? $ley : $ly;
32              
33 6         23 my ($r, $g, $b) = $font->hex_to_rgb(fill_colour $self);
34              
35 6         169 $canvas->q->w(1)->RG($r, $g, $b);
36              
37 6         13 my $tp = type $self;
38 6         11 my $d = dash $self;
39 6 50       44 if ($d) {
    100          
    100          
40 0         0 $canvas->d($d, 0);
41             } elsif ($tp eq 'dashed') {
42 1         5 $canvas->d([6, 3], 0);
43             } elsif ($tp eq 'dots') {
44 1         12 $canvas->J(1)->d([0, 4], 0);
45             }
46              
47 6         73 $canvas->m($lx, $ly)->l($lex, $ley)->S->Q;
48              
49             # Advance cursor
50 6         22 $page->advance_y(2);
51              
52 6         14 return $self;
53             }
54              
55             1;
56              
57             __END__