PDF/Page.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use Renard::Incunabula::Common::Setup;
2 package Renard::Block::Format::PDF::Page;
3 # ABSTRACT: Page from a PDF document
4 $Renard::Block::Format::PDF::Page::VERSION = '0.005';
5 use Moo;
6 use MooX::HandlesVia;
7 use Cairo;
8 use POSIX qw(ceil);
9  
10 use Renard::Incunabula::Common::Types qw(Str InstanceOf HashRef);
11 use Renard::Incunabula::Document::Types qw(ZoomLevel PageNumber);
12  
13 has document => (
14 is => 'ro',
15 required => 1,
16 isa => InstanceOf['Renard::Block::Format::PDF::Document'],
17 );
18  
19 has page_number => ( is => 'ro', required => 1, isa => PageNumber, );
20  
21 has zoom_level => ( is => 'ro', required => 1, isa => ZoomLevel, );
22  
23 has png_data => (
24 is => 'lazy', # _build_png_data
25 isa => Str,
26 );
27  
28 method _build_png_data() {
29 my $png_data = Renard::API::MuPDF::mutool::get_mutool_pdf_page_as_png(
30 $self->document->filename, $self->page_number, $self->zoom_level
31 );
32 }
33  
34  
35 has _size => (
36 is => 'lazy',
37 isa => HashRef,
38 handles_via => 'Hash',
39 handles => {
40 width => ['get', 'width'],
41 height => ['get', 'height'],
42 },
43 );
44  
45 method _build__size() {
46 my $page_identity = $self->document
47 ->identity_bounds
48 ->[ $self->page_number - 1 ];
49  
50 # multiply to account for zoom-level
51 my $w = ceil($page_identity->{dims}{w} * $self->zoom_level);
52 my $h = ceil($page_identity->{dims}{h} * $self->zoom_level);
53  
54 { width => $w, height => $h };
55 }
56  
57  
58 with qw(
59 Renard::Incunabula::Page::Role::CairoRenderableFromPNG
60 );
61  
62 1;
63  
64 __END__