| 1 | # -*- cperl -*- | ||||||||||
| 2 | # ABSTRACT: FrameConverter | ||||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | package BeamerReveal::FrameConverter; | ||||||||||
| 6 | 1 | our $VERSION = '20261115.1249'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use File::Which; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use File::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use BeamerReveal::IPC::Run; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use IPC::Run qw(harness start pump finish); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use BeamerReveal::Log; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub nofdigits { length( "$_[0]" ) } | ||||||||
|
Subroutine
nofdigits: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 25 | 0 | 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 | ▶ | $class = (ref $class ? ref $class : $class ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | bless $self, $class; | |||||||||
| 38 | |||||||||||
| 39 | 0 | my $logger = $BeamerReveal::Log::logger; | |||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | $self->{pdftoppm} = File::Which::which( 'pdftoppm' ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $logger->fatal( "Error: cannot find $pdffile, run your latex compiler first to produce the PDF file." ) unless ( -r $pdffile ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | sub toJPG { | ||||||||
|
Subroutine
toJPG: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 61 | 0 | 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}]}, | |||||||||
| 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 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 77 | 0 | ▶ | while( scalar @_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 0 | push @list, sprintf( "$self->{slides}/slide-%0" . nofdigits( $maxSlide ) . 'd.jpg', | |||||||||
| 94 | $i ); | ||||||||||
| 95 | } | ||||||||||
| 96 | 0 | return \@list; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 1 | 1; | |||||||||
| 100 | |||||||||||
| 101 | __END__ | ||||||||||