1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# autolatex - svg2pdf+layers+tex_inkscape.transdef
# Copyright (C) 2013 Stephane Galland <galland@arakhne.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#--------------------------------------------
# See template.txt for details on the fields
#--------------------------------------------
INPUT_EXTENSIONS = .svglt .svg_lt .svglayerstex .svgtexlayers .svg+layers+tex .svg+tex+layers .layers.tex.svg .tex.layers.svg +layers+tex.svg +tex+layers.svg .svgzlt .svgz_lt .svgzlayerstex .svgztexlayers .svgz+layers+tex .svgz+tex+layers .layers.tex.svgz .tex.layers.svgz +layers+tex.svgz +tex+layers.svgz
OUTPUT_EXTENSIONS for pdf = .pdftex_t .pdf
OUTPUT_EXTENSIONS for eps = .pstex_t .eps
TRANSLATOR_PERL_DEPENDENCIES = XML::Parser Scalar::Util qw(blessed)
TRANSLATOR_FUNCTION =<<EOL {
my ($ext1, $ext2, $ext3, $opt);
if ($ispdfmode) {
$ext1 = '.pdftex_t';
$ext2 = '.pdf';
$ext3 = '.pdf_tex';
$opt = '--export-pdf';
}
else {
$ext1 = '.pstex_t';
$ext2 = '.eps';
$ext3 = '.ps_tex';
$opt = '--export-eps';
}
# Parse the SVG
my $parser = XML::Parser->new(Style=>'Objects', Pkg=>'autolatex');
my $tree = $parser->parsefile("$in");
my $imageinclusions = '';
my $layerIndex = 1;
foreach my $rootElement (@$tree) {
if ($rootElement->{'Kids'}) {
foreach my $kidElement (@{$rootElement->{'Kids'}}) {
my $className = blessed($kidElement);
if ($className eq 'autolatex::g'
&& ($kidElement->{'style'}||'') ne "display:none") {
my $id = $kidElement->{'id'};
my $label = $kidElement->{'inkscape:label'};
my $overlay_spec = $layerIndex;
if ($label && $label =~ /<\s*(.+)\s*>/s) {
$overlay_spec = $1;
}
my $outputbasename = basename($out, $ext1)."_$id";
my $figureFile = File::Spec->catfile(
dirname($out),
"$outputbasename$ext2");
runCommandOrFail(
'inkscape',
'--without-gui',
'--export-area-page',
'--export-id', "$id",
'--export-id-only',
$opt,
"$figureFile",
'--export-latex',
"--file=$in");
my $texFile = File::Spec->catfile(
dirname($out),
"$outputbasename$ext3");
$imageinclusions .= "\\node<$overlay_spec> (X) {\\input{$texFile}};%\n";
$layerIndex++;
}
}
}
}
if (!$imageinclusions) {
printError(_T("No layer in the SVG file: {}"), $in);
}
local *TEXOUT;
open(*TEXOUT, "> $out") or printErr("$out: $!");
print TEXOUT "\%Overlays\n\\bgroup%\n\\begin{tikzpicture}%\n$imageinclusions\\end{tikzpicture}%\n\\egroup%";
close(*TEXOUT);
1;
}
EOL
FILES_TO_CLEAN = $out_*.pdf_tex $out_*.ps_tex $out_*.pdf $out_*.eps
|