line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Image::Index::LaTeX; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25593
|
use 5.008009; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
5
|
use File::Find qw(finddepth); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
97
|
|
7
|
1
|
|
|
1
|
|
3916
|
use Image::Size; |
|
1
|
|
|
|
|
5533
|
|
|
1
|
|
|
|
|
681
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
{ |
13
|
1
|
|
|
1
|
1
|
13
|
my ($class, @args) = @_; |
14
|
1
|
|
|
|
|
3
|
my $self = bless {}, $class; |
15
|
1
|
|
|
|
|
6
|
return $self->_init(@args); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _init |
19
|
|
|
|
|
|
|
{ |
20
|
1
|
|
|
1
|
|
3
|
my ($self, @dirs_or_files) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# build list of image filenames |
23
|
1
|
50
|
|
|
|
13
|
$self->{'images'} = [ |
24
|
|
|
|
|
|
|
grep { |
25
|
1
|
|
|
|
|
2
|
-f $_ && /\.(jpe?g|png|pdf|eps)$/i; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
map { |
28
|
1
|
|
|
|
|
3
|
my @files = (); |
29
|
|
|
|
|
|
|
(-d $_ ? |
30
|
0
|
|
|
0
|
|
0
|
finddepth(sub { push @files, $File::Find::name }, $_) : |
31
|
1
|
50
|
|
|
|
13
|
do { push @files, $_ } ); |
|
1
|
|
|
|
|
2
|
|
32
|
1
|
|
|
|
|
3
|
@files; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
@dirs_or_files |
35
|
|
|
|
|
|
|
]; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
4
|
$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
|
|
|
|
|
4
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub tex |
66
|
|
|
|
|
|
|
{ |
67
|
1
|
|
|
1
|
1
|
6
|
my ($self, %opts) = @_; |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
50
|
|
|
5
|
my $flavour = lc($opts{'flavour'} || 'LaTeX'); |
70
|
1
|
50
|
|
|
|
14
|
die "Error: supported flavours are: 'LaTeX' or 'ConTeXt'\n" |
71
|
|
|
|
|
|
|
if $flavour !~ /^(latex|context)$/; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
my $graphics = |
74
|
|
|
|
|
|
|
join '', |
75
|
|
|
|
|
|
|
map { |
76
|
1
|
|
|
|
|
4
|
my $file = $_; |
77
|
0
|
|
|
|
|
0
|
my ($width, $height) = (0, 0); |
78
|
0
|
0
|
|
|
|
0
|
($width, $height) = imgsize($file) if $file =~ /\.(png|jpe?g)$/i; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
0
|
($flavour eq 'latex' ? |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
2
|
@{$self->{'images'}}; |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
3
|
my $tex = $self->{'tmpl'}->{$flavour}; |
96
|
1
|
|
|
|
|
5
|
$tex =~ s/\%\[GRAPHICS\]\%/$graphics/; |
97
|
1
|
|
|
|
|
110
|
return $tex; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |