summaryrefslogtreecommitdiff
path: root/support/autolatex/translators/svg2pdf+layers_inkscape.transdef
diff options
context:
space:
mode:
Diffstat (limited to 'support/autolatex/translators/svg2pdf+layers_inkscape.transdef')
-rw-r--r--support/autolatex/translators/svg2pdf+layers_inkscape.transdef108
1 files changed, 108 insertions, 0 deletions
diff --git a/support/autolatex/translators/svg2pdf+layers_inkscape.transdef b/support/autolatex/translators/svg2pdf+layers_inkscape.transdef
new file mode 100644
index 0000000000..b18d19d761
--- /dev/null
+++ b/support/autolatex/translators/svg2pdf+layers_inkscape.transdef
@@ -0,0 +1,108 @@
+# autolatex - svg2pdf+layers_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 = .svgl .svg_l .svglayers .svg+layers .layers.svg +layers.svg .svgzl .svgz_l .svgzlayers .svgz+layers .layers.svgz +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, $opt);
+ if ($ispdfmode) {
+ $ext1 = '.pdftex_t';
+ $ext2 = '.pdf';
+ $opt = '--export-pdf';
+ }
+ else {
+ $ext1 = '.pstex_t';
+ $ext2 = '.eps';
+ $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'}) {
+ my $width = $rootElement->{'width'} || 0;
+ # Clamp the value to avoid LaTex failures
+ if ($width<=0) {
+ $width = 100;
+ }
+ elsif ($width>1000) {
+ $width = 1000;
+ }
+ 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'};
+ printDbgFor(3, formatText(_T("Found layer: id={}, label={}"), @{toUTF8($id, $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");
+ printDbgFor(4, formatText(_T("Overlay spec: <{}>"), @{toUTF8($overlay_spec)}));
+ printDbgFor(4, formatText(_T("Output: {}"), $figureFile));
+
+ runCommandOrFail(
+ 'inkscape',
+ '--without-gui',
+ '--export-id', "$id",
+ '--export-id-only',
+ '--export-area-page',
+ $opt,
+ "$figureFile",
+ "--file=$in");
+
+ $imageinclusions .= "\\node<$overlay_spec> (X) {\\includegraphics[width=${width}em]{$outputbasename}};%\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 $out_*.eps
+