File Coverage

blib/lib/PDF/Make/Extract/Result.pm
Criterion Covered Total %
statement 36 36 100.0
branch 4 4 100.0
condition n/a
subroutine 10 10 100.0
pod 5 5 100.0
total 55 55 100.0


line stmt bran cond sub pod time code
1             package PDF::Make::Extract::Result;
2 42     42   201 use strict;
  42         65  
  42         1159  
3 42     42   164 use warnings;
  42         56  
  42         1334  
4 42     42   147 use Object::Proto;
  42         64  
  42         2163  
5 42     42   14525 use PDF::Make::Extract::Block;
  42         89  
  42         1328  
6              
7             BEGIN {
8 42     42   747 Object::Proto::define('PDF::Make::Extract::Result',
9             'data:ArrayRef:default([])',
10             );
11 42         12537 Object::Proto::import_accessors('PDF::Make::Extract::Result');
12             }
13              
14             sub blocks {
15 63     63 1 1778 my ($self) = @_;
16 63         85 return map { PDF::Make::Extract::Block->new(%$_) } @{data($self)};
  259         1298  
  63         175  
17             }
18              
19 2     2 1 1088 sub block_count { scalar @{data($_[0])} }
  2         15  
20              
21             sub text_positions {
22 48     48 1 2943 my ($self) = @_;
23 48         92 my @items;
24 48         133 for my $block ($self->blocks) {
25 198         355 for my $line ($block->lines) {
26 605         837 for my $word ($line->words) {
27 1626 100       8867 push @items, {
    100          
28             text => $word->text,
29             x => $word->x0,
30             y => $word->y0,
31             w => $word->x1 - $word->x0,
32             h => $word->y1 - $word->y0,
33             font_size => $word->font_size,
34             baseline => $line->baseline,
35             (defined $word->mcid ? (mcid => $word->mcid) : ()),
36             (defined $word->tag ? (tag => $word->tag) : ()),
37             };
38             }
39             }
40             }
41 48         306 return @items;
42             }
43              
44             sub words {
45 1     1 1 4414 my ($self) = @_;
46 1         1 my @w;
47 1         3 for my $block ($self->blocks) {
48 3         5 for my $line ($block->lines) {
49 3         7 push @w, $line->words;
50             }
51             }
52 1         4 return @w;
53             }
54              
55             sub to_string {
56 12     12 1 6529 my ($self) = @_;
57 12         39 return join "\n\n", map { $_->to_string } $self->blocks;
  56         162  
58             }
59              
60             1;
61              
62             __END__