File Coverage

blib/lib/BeamerReveal/FrameConverter.pm
Criterion Covered Total %
statement 24 53 45.2
branch 0 6 0.0
condition n/a
subroutine 8 12 66.6
pod 2 3 66.6
total 34 74 45.9


line stmt bran cond sub pod time code
1             # -*- cperl -*-
2             # ABSTRACT: FrameConverter
3              
4              
5             package BeamerReveal::FrameConverter;
6             our $VERSION = '20260208.1851'; # VERSION
7              
8 1     1   527833 use strict;
  1         3  
  1         49  
9 1     1   7 use warnings;
  1         2  
  1         83  
10              
11 1     1   8 use Carp;
  1         2  
  1         116  
12              
13 1     1   643 use File::Which;
  1         1786  
  1         75  
14 1     1   7 use File::Path;
  1         4  
  1         99  
15              
16 1     1   575 use BeamerReveal::IPC::Run;
  1         4  
  1         57  
17 1     1   8 use IPC::Run qw(harness start pump finish);
  1         2  
  1         78  
18              
19 1     1   693 use BeamerReveal::Log;
  1         3  
  1         932  
20              
21 0     0 0   sub nofdigits { length( "$_[0]" ) }
22              
23              
24             sub new {
25 0     0 1   my $class = shift;
26 0           my ( $base, $outputdir, $pdffile, $xres, $yres, $progressId ) = @_;
27              
28 0           my $self = {
29             base => $base,
30             outputdir => $outputdir,
31             xres => $xres,
32             yres => $yres,
33             file => $pdffile,
34             progressId => $progressId,
35             };
36 0 0         $class = (ref $class ? ref $class : $class );
37 0           bless $self, $class;
38              
39 0           my $logger = $BeamerReveal::Log::logger;
40            
41 0 0         $self->{pdftoppm} = File::Which::which( 'pdftoppm' )
42             or $logger->fatal( "Error: your setup is incomplete, I cannot find pdftoppm (part of the poppler library)\n" .
43             "Install 'Poppler-utils' and make sure pdftoppm is accessible in a directory on your PATH list variable\n" );
44              
45 0 0         $logger->fatal( "Error: cannot find $pdffile, run your latex compiler first to produce the PDF file." ) unless ( -r $pdffile );
46            
47 0           $self->{slides} = "$self->{base}/media/Slides";
48            
49 0           for my $item ( qw(slides) ) {
50 0           File::Path::rmtree( "$outputdir/$self->{$item}" );
51 0           File::Path::make_path( "$outputdir/$self->{$item}" );
52             }
53              
54 0           return $self;
55             }
56              
57              
58              
59              
60             sub toJPG {
61 0     0 1   my $self = shift;
62            
63             my $cmd = [ $self->{pdftoppm},
64             $self->{file},
65             "$self->{outputdir}/$self->{slides}/slide",
66             '-jpeg',
67             '-jpegopt',
68             'optimize=y,quality=85',
69 0           '-scale-to-x', @{[1.5*$self->{xres}]},
70 0           '-scale-to-y', @{[1.5*$self->{yres}]},
  0            
71             '-progress',
72             ];
73 0           my $logger = $BeamerReveal::Log::logger;
74 0           my $maxSlide = 0;
75             BeamerReveal::IPC::Run::runsmart( $cmd, 2, qr/^(\d+) (\d+) .*$/,
76             sub {
77 0     0     while( scalar @_ ) {
78 0           my ( $a, $b ) = ( shift @_, shift @_ );
79             $logger->progress( $self->{progressId},
80 0           $a, "background $1/$2", $b );
81 0           $maxSlide = $b;
82             }
83             },
84 0           0, # coreId
85             2, # indent
86             undef, # directory
87             "Error: frame conversion failed, is your beamer PDF damaged?"
88             );
89              
90 0           my @list = ( 0 ); # create a dummy element to allow for one-indexed addressing
91            
92 0           for (my $i = 1; $i <= $maxSlide; ++$i ) {
93 0           push @list, sprintf( "$self->{slides}/slide-%0" . nofdigits( $maxSlide ) . 'd.jpg',
94             $i );
95             }
96 0           return \@list;
97             }
98              
99             1;
100              
101             __END__