| 1 | package Image::Index::LaTeX; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008009; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use File::Find qw(finddepth); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Image::Size; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | sub new | ||||||||||||||||||||
| 12 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 13 | 1 | my ($class, @args) = @_; | |||||||||||||||||||
| 14 | 1 | my $self = bless {}, $class; | |||||||||||||||||||
| 15 | 1 | return $self->_init(@args); | |||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | sub _init | ||||||||||||||||||||
| 19 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
_init: called CC=3 SCAR=11.5
| |||||||||||||||||||||
| 20 | 1 | my ($self, @dirs_or_files) = @_; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # build list of image filenames | ||||||||||||||||||||
| 23 | $self->{'images'} = [ | ||||||||||||||||||||
| 24 | grep { | ||||||||||||||||||||
| 25 | 1 | ▶ | -f $_ && /\.(jpe?g|png|pdf|eps)$/i; | ||||||||||||||||||
|
Condition33%1/3
-f $_ && /\.(jpe?g|png|pdf|eps)$/i
MC/DC0%0/2
-f $_ && /\.(jpe?g|png|pdf|eps)$/i
-f $_
/\.(jpe?g|png|pdf|eps)$/i
Truth table33%1/3
A && B
A= -f $_B= /\.(jpe?g|png|pdf|eps)$/i
| |||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | map { | ||||||||||||||||||||
| 28 | 1 | my @files = (); | |||||||||||||||||||
| 29 | (-d $_ ? | ||||||||||||||||||||
| 30 | 0 | ▶ | finddepth(sub { push @files, $File::Find::name }, $_) : | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 31 | 1 | ▶ | do { push @files, $_ } ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 1 | @files; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | @dirs_or_files | ||||||||||||||||||||
| 35 | ]; | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1 | $self->{'tmpl'} = { | |||||||||||||||||||
| 38 | 'latex' => q{ | ||||||||||||||||||||
| 39 | \documentclass{article} | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | \usepackage[margin=1cm]{geometry} | ||||||||||||||||||||
| 42 | \usepackage{graphicx} | ||||||||||||||||||||
| 43 | \usepackage{epstopdf} | ||||||||||||||||||||
| 44 | \geometry{screen} | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | \begin{document} | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | %[GRAPHICS]% | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | \end{document} | ||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 'context' => q{ | ||||||||||||||||||||
| 54 | \starttext | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | %[GRAPHICS]% | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | \stoptext | ||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 1 | return $self; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | sub tex | ||||||||||||||||||||
| 66 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
tex: called CC=7 SCAR=28.2
Pod
documented
| |||||||||||||||||||||
| 67 | 1 | my ($self, %opts) = @_; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 1 | ▶ | my $flavour = lc($opts{'flavour'} || 'LaTeX'); | ||||||||||||||||||
|
Condition50%1/2
$opts{'flavour'} || 'LaTeX'
MC/DC0%0/1
$opts{'flavour'} || 'LaTeX'
$opts{'flavour'}
Truth table50%1/2
A
A= $opts{'flavour'}
| |||||||||||||||||||||
| 70 | 1 | ▶ | die "Error: supported flavours are: 'LaTeX' or 'ConTeXt'\n" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | if $flavour !~ /^(latex|context)$/; | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | my $graphics = | ||||||||||||||||||||
| 74 | join '', | ||||||||||||||||||||
| 75 | map { | ||||||||||||||||||||
| 76 | 0 | my $file = $_; | |||||||||||||||||||
| 77 | 0 | my ($width, $height) = (0, 0); | |||||||||||||||||||
| 78 | 0 | ▶ | ($width, $height) = imgsize($file) if $file =~ /\.(png|jpe?g)$/i; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | ($flavour eq 'latex' ? | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 81 | '\includegraphics['. | ||||||||||||||||||||
| 82 | ($width > $height ? | ||||||||||||||||||||
| 83 | 'width=\textwidth' : | ||||||||||||||||||||
| 84 | 'height=\textheight').']{'.$file.'}'."\n". | ||||||||||||||||||||
| 85 | '\newpage'."\n" | ||||||||||||||||||||
| 86 | : | ||||||||||||||||||||
| 87 | '\useexternalfigure['.$file.']['. | ||||||||||||||||||||
| 88 | ($width > $height ? | ||||||||||||||||||||
| 89 | 'width=\textwidth' : | ||||||||||||||||||||
| 90 | 'height=\textheight').']'."\n" | ||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | 1 | @{$self->{'images'}}; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 1 | my $tex = $self->{'tmpl'}->{$flavour}; | |||||||||||||||||||
| 96 | 1 | $tex =~ s/\%\[GRAPHICS\]\%/$graphics/; | |||||||||||||||||||
| 97 | 1 | return $tex; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 1 | 1; | |||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||