File Coverage

lib/PDF/Boxer/Doc.pm
Criterion Covered Total %
statement 9 35 25.7
branch 0 4 0.0
condition n/a
subroutine 3 12 25.0
pod 0 2 0.0
total 12 53 22.6


line stmt bran cond sub pod time code
1             package PDF::Boxer::Doc;
2             {
3             $PDF::Boxer::Doc::VERSION = '0.004';
4             }
5 3     3   17 use Moose;
  3         5  
  3         22  
6             # ABSTRACT: Hold PDF::API2 stuff
7              
8 3     3   21165 use namespace::autoclean;
  3         7  
  3         25  
9              
10 3     3   3948 use PDF::API2;
  3         1006391  
  3         1924  
11              
12             has 'file' => ( isa => 'Str', is => 'ro' );
13              
14             has 'pdf' => ( isa => 'Object', is => 'ro', lazy_build => 1 );
15             sub _build_pdf{
16 0     0     return PDF::API2->new( -file => shift->file );
17             }
18              
19             has 'page' => ( isa => 'Object', is => 'rw', lazy_build => 1 );
20             sub _build_page{
21 0     0     my ($self) = @_;
22 0           my $page = $self->pdf->page;
23 0           $page->mediabox(0,0,$self->page_width, $self->page_height);
24             #$page->cropbox($self->page_width-10, $self->page_height);
25 0           return $page;
26             }
27              
28             # default to A4
29             has 'page_width' => ( isa => 'Int', is => 'ro', lazy_build => 1 );
30             has 'page_height' => ( isa => 'Int', is => 'ro', lazy_build => 1 );
31 0     0     sub _build_page_width{ 595 }
32 0     0     sub _build_page_height{ 842 }
33              
34             has 'gfx' => ( isa => 'Object', is => 'rw', lazy_build => 1 );
35 0     0     sub _build_gfx{ shift->page->gfx }
36              
37             has 'text' => ( isa => 'Object', is => 'rw', lazy_build => 1 );
38             sub _build_text{
39 0     0     my ($self) = @_;
40 0           $self->gfx;
41 0           my $txt = $self->page->text;
42 0           $txt->compressFlate;
43 0           return $txt;
44             }
45              
46             has 'fonts' => ( isa => 'HashRef', is => 'ro', lazy_build => 1 );
47             sub _build_fonts{
48 0     0     my ($self) = @_;
49             return {
50 0           'Helvetica' => { type => 'corefont', id => 'Helvetica', -encoding => 'latin1' },
51             'Helvetica-Bold' => { type => 'corefont', id => 'Helvetica-Bold', -encoding => 'latin1' },
52             'Helvetica-Italic' => { type => 'corefont', id => 'Helvetica-Oblique', -encoding => 'latin1' },
53             'Times' => { type => 'corefont', id => 'Times', -encoding => 'latin1' },
54             'Times-Bold' => { type => 'corefont', id => 'Times-Bold', -encoding => 'latin1' },
55             }
56             }
57              
58             sub new_page{
59 0     0 0   my ($self) = @_;
60 0           $self->clear_page;
61 0           $self->clear_text;
62 0           $self->clear_gfx;
63             }
64              
65             sub font{
66 0     0 0   my ($self, $name) = @_;
67 0           my $font = $self->fonts->{$name};
68 0 0         die "cannot find font '$name' in fonts list" unless $font;
69 0 0         return $font unless ref($font) eq 'HASH';
70 0           my $font_type = delete $font->{type};
71 0           my $font_id = delete $font->{id};
72 0           return $self->fonts->{$name} = $self->pdf->$font_type($font_id, %$font);
73             }
74              
75             __PACKAGE__->meta->make_immutable;
76              
77             1;
78              
79             __END__
80             =pod
81              
82             =head1 NAME
83              
84             PDF::Boxer::Doc - Hold PDF::API2 stuff
85              
86             =head1 VERSION
87              
88             version 0.004
89              
90             =head1 AUTHOR
91              
92             Jason Galea <lecstor@cpan.org>
93              
94             =head1 COPYRIGHT AND LICENSE
95              
96             This software is copyright (c) 2012 by Jason Galea.
97              
98             This is free software; you can redistribute it and/or modify it under
99             the same terms as the Perl 5 programming language system itself.
100              
101             =cut
102