1 ## Copyright (C) 2010-2012 Shai Ayal
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} __fltk_print__ (@var{@dots{}})
21 ## Undocumented internal function.
24 function opts = __fltk_print__ (opts)
26 dos_shell = (ispc () && ! isunix ());
32 if (! isempty (opts.fig2dev_binary))
33 ## fig2dev is prefered for conversion to emf
34 fig2dev_devices = {"pstex", "mf", "emf"};
36 fig2dev_devices = {"pstex", "mf"};
41 switch (lower (opts.devopt))
42 case {"eps", "eps2", "epsc", "epsc2"}
44 gl2ps_device = {"eps"};
45 ## FIXME - use epstool to tighten bbox and provide preview.
46 pipeline = {opts.epstool_cmd(opts, "-", opts.name)};
47 case {"epslatex", "pslatex", "pdflatex", "epslatexstandalone", ...
48 "pslatexstandalone", "pdflatexstandalone"}
50 n = find (opts.devopt == "l", 1);
51 suffix = opts.devopt(1:n-1);
52 dot = find (opts.name == ".", 1, "last");
54 && any (strcmpi (opts.name(dot:end), ...
55 {strcat(".", suffix), ".tex", "."})))
56 name = opts.name(1:dot-1);
57 if (dot < numel (opts.name)
58 && any (strcmpi (opts.name(dot+1:end), {"eps", "ps", "pdf"})))
59 ## If user provides eps/ps/pdf suffix, use it.
60 suffix = opts.name(dot+1:end);
63 error ("print:invalid-suffix",
64 "invalid suffix `%s' for device `%s'.",
65 opts.name(dot:end), lower (opts.devopt));
67 gl2ps_device = {sprintf("%snotxt", lower (suffix))};
68 gl2ps_device{2} = "tex";
70 ## FIXME - this will only work on MinGW with the MSYS shell
71 pipeline = {sprintf("cat > %s-inc.%s", name, suffix)};
72 pipeline{2} = sprintf ("cat > %s.tex", name);
74 pipeline = {sprintf("cat > %s-inc.%s", name, suffix)};
75 pipeline{2} = sprintf ("cat > %s.tex", name);
79 gl2ps_device = {"pgf"};
80 pipeline = {sprintf("cat > %s", opts.name)};
83 gl2ps_device = {"svg"};
84 pipeline = {sprintf("cat > %s", opts.name)};
86 cmd_pstoedit = opts.pstoedit_cmd (opts, "fig");
87 cmd_fig2dev = opts.fig2dev_cmd (opts, opts.devopt);
88 if (strcmp (opts.devopt, "pstex"))
89 [~, ~, ext] = fileparts (opts.name);
90 if (any (strcmpi (ext, {".ps", ".tex", "."})))
91 opts.name = opts.name(1:end-numel(ext));
93 opts.name = strcat (opts.name, ".ps");
94 cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name);
95 gl2ps_device = {"eps"};
97 cmd_fig2dev = opts.fig2dev_cmd (opts, "pstex_t");
98 gl2ps_device{2} = "eps";
99 pipeline{2} = sprintf ("%s | %s > %s", cmd_pstoedit,
100 cmd_fig2dev, strrep(opts.name, ".ps", ".tex"));
102 cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name);
103 gl2ps_device = {"eps"};
107 cmd = opts.pstoedit_cmd (opts, "ps2ai");
108 gl2ps_device = {"eps"};
109 pipeline = {sprintf("%s > %s", cmd, opts.name)};
110 case {"dxf", "emf", "fig", "hpgl"}
111 cmd = opts.pstoedit_cmd (opts);
112 gl2ps_device = {"eps"};
113 pipeline = {sprintf("%s > %s", cmd, opts.name)};
114 case {"corel", "gif"}
115 error ("print:unsupporteddevice",
116 "print.m: %s output is not available for the FLTK graphics toolkit",
117 upper (opts.devopt));
118 case opts.ghostscript.device
119 opts.ghostscript.source = "-";
120 opts.ghostscript.output = opts.name;
121 if (opts.send_to_printer)
122 opts.unlink(strcmp (opts.unlink, opts.ghostscript.output)) = [];
123 opts.ghostscript.output = "-";
125 [cmd_gs, cmd_cleanup] = __ghostscript__ (opts.ghostscript);
126 if (opts.send_to_printer || isempty (opts.name))
127 cmd_lpr = opts.lpr_cmd (opts);
128 cmd = sprintf("%s | %s", cmd_gs, cmd_lpr);
130 cmd = sprintf("%s", cmd_gs);
132 if (! isempty (cmd_cleanup))
133 gl2ps_device = {"eps"};
135 pipeline = {sprintf("%s & %s", cmd, cmd_cleanup)};
137 pipeline = {sprintf("%s ; %s", cmd, cmd_cleanup)};
140 gl2ps_device = {"eps"};
144 error (sprintf ("print:no%soutput", opts.devopt),
145 "print.m: %s output is not available for GL2PS output",
146 upper (opts.devopt));
149 opts.pipeline = pipeline;
151 for n = 1:numel(pipeline)
153 fprintf ("fltk-pipeline: '%s'\n", pipeline{n});
155 drawnow (gl2ps_device{n}, strcat('|',pipeline{n}));
158 if (! isempty (strfind (opts.devopt, "standalone")))
159 opts.latex_standalone (opts);