File Coverage

blib/lib/Renard/Incunabula/Format/PDF/Page.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1 1     1   9 use Renard::Incunabula::Common::Setup;
  1         3  
  1         12  
2             package Renard::Incunabula::Format::PDF::Page;
3             # ABSTRACT: Page from a PDF document
4             $Renard::Incunabula::Format::PDF::Page::VERSION = '0.003';
5 1     1   7531 use Moo;
  1         2  
  1         9  
6 1     1   728 use MooX::HandlesVia;
  1         7272  
  1         7  
7 1     1   390 use Cairo;
  0            
  0            
8             use POSIX qw(ceil);
9              
10             use Renard::Incunabula::Common::Types qw(Str InstanceOf ZoomLevel PageNumber HashRef);
11              
12             has document => (
13             is => 'ro',
14             required => 1,
15             isa => InstanceOf['Renard::Incunabula::Format::PDF::Document'],
16             );
17              
18             has page_number => ( is => 'ro', required => 1, isa => PageNumber, );
19              
20             has zoom_level => ( is => 'ro', required => 1, isa => ZoomLevel, );
21              
22             has png_data => (
23             is => 'lazy', # _build_png_data
24             isa => Str,
25             );
26              
27             method _build_png_data() {
28             my $png_data = Renard::Incunabula::MuPDF::mutool::get_mutool_pdf_page_as_png(
29             $self->document->filename, $self->page_number, $self->zoom_level
30             );
31             }
32              
33              
34             has _size => (
35             is => 'lazy',
36             isa => HashRef,
37             handles_via => 'Hash',
38             handles => {
39             width => ['get', 'width'],
40             height => ['get', 'height'],
41             },
42             );
43              
44             method _build__size() {
45             my $page_identity = $self->document
46             ->identity_bounds
47             ->[ $self->page_number - 1 ];
48              
49             # multiply to account for zoom-level
50             my $w = ceil($page_identity->{dims}{w} * $self->zoom_level);
51             my $h = ceil($page_identity->{dims}{h} * $self->zoom_level);
52              
53             { width => $w, height => $h };
54             }
55              
56              
57             with qw(
58             Renard::Incunabula::Page::Role::CairoRenderableFromPNG
59             );
60              
61             1;
62              
63             __END__
64              
65             =pod
66              
67             =encoding UTF-8
68              
69             =head1 NAME
70              
71             Renard::Incunabula::Format::PDF::Page - Page from a PDF document
72              
73             =head1 VERSION
74              
75             version 0.003
76              
77             =head1 EXTENDS
78              
79             =over 4
80              
81             =item * L<Moo::Object>
82              
83             =back
84              
85             =head1 CONSUMES
86              
87             =over 4
88              
89             =item * L<Renard::Incunabula::Page::Role::CairoRenderable>
90              
91             =item * L<Renard::Incunabula::Page::Role::CairoRenderableFromPNG>
92              
93             =back
94              
95             =head1 ATTRIBUTES
96              
97             =head2 document
98              
99             InstanceOf['Renard::Incunabula::Format::PDF::Document']
100              
101             The document that created this page.
102              
103             =head2 page_number
104              
105             PageNumber
106              
107             The page number that this page represents.
108              
109             =head2 zoom_level
110              
111             ZoomLevel
112              
113             The zoom level for this page.
114              
115             =head2 height
116              
117             The height of the page at with the current parameters.
118              
119             =head2 width
120              
121             The width of the page at with the current parameters.
122              
123             =head1 AUTHOR
124              
125             Project Renard
126              
127             =head1 COPYRIGHT AND LICENSE
128              
129             This software is copyright (c) 2017 by Project Renard.
130              
131             This is free software; you can redistribute it and/or modify it under
132             the same terms as the Perl 5 programming language system itself.
133              
134             =cut