]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/private/__fltk_print__.m
update packages
[CreaPhase.git] / octave_packages / m / plot / private / __fltk_print__.m
1 ## Copyright (C) 2010-2012 Shai Ayal
2 ##
3 ## This file is part of Octave.
4 ##
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.
9 ##
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.
14 ##
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/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} __fltk_print__ (@var{@dots{}})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 function opts = __fltk_print__ (opts)
25
26   dos_shell = (ispc () && ! isunix ());
27
28   figure (opts.figure);
29   drawnow ("expose");
30   __fltk_redraw__ ();
31
32   if (! isempty (opts.fig2dev_binary))
33     ## fig2dev is prefered for conversion to emf
34     fig2dev_devices = {"pstex", "mf", "emf"};
35   else
36     fig2dev_devices = {"pstex", "mf"};
37   endif
38
39   gl2ps_device = {};
40   pipeline = {};
41   switch (lower (opts.devopt))
42   case {"eps", "eps2", "epsc", "epsc2"}
43     ## format GL2PS_EPS
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"}
49     ## format GL2PS_TEX
50     n = find (opts.devopt == "l", 1);
51     suffix = opts.devopt(1:n-1);
52     dot = find (opts.name == ".", 1, "last");
53     if ((! isempty (dot))
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);
61       endif
62     else
63       error ("print:invalid-suffix", 
64              "invalid suffix `%s' for device `%s'.",
65              opts.name(dot:end), lower (opts.devopt));
66     endif
67     gl2ps_device = {sprintf("%snotxt", lower (suffix))};
68     gl2ps_device{2} = "tex";
69     if (dos_shell)
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);
73     else
74       pipeline = {sprintf("cat > %s-inc.%s", name, suffix)};
75       pipeline{2} = sprintf ("cat > %s.tex", name);
76     endif
77   case "tikz"
78     ## format GL2PS_PGF
79     gl2ps_device = {"pgf"};
80     pipeline = {sprintf("cat > %s", opts.name)};
81   case "svg"
82     ## format GL2PS_SVG
83     gl2ps_device = {"svg"};
84     pipeline = {sprintf("cat > %s", opts.name)};
85   case fig2dev_devices
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));
92       endif
93       opts.name = strcat (opts.name, ".ps");
94       cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name);
95       gl2ps_device = {"eps"};
96       pipeline = {cmd};
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"));
101     else
102       cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name);
103       gl2ps_device = {"eps"};
104       pipeline = {cmd};
105     endif
106   case "aifm"
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 = "-";
124     endif
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);
129     else
130       cmd = sprintf("%s", cmd_gs);
131     endif
132     if (! isempty (cmd_cleanup))
133       gl2ps_device = {"eps"};
134       if (dos_shell)
135         pipeline = {sprintf("%s & %s", cmd, cmd_cleanup)};
136       else
137         pipeline = {sprintf("%s ; %s", cmd, cmd_cleanup)};
138       endif
139     else
140       gl2ps_device = {"eps"};
141       pipeline = {cmd};
142     endif
143   otherwise
144     error (sprintf ("print:no%soutput", opts.devopt),
145            "print.m: %s output is not available for GL2PS output",
146            upper (opts.devopt));
147   endswitch
148
149   opts.pipeline = pipeline;
150
151   for n = 1:numel(pipeline)
152     if (opts.debug)
153       fprintf ("fltk-pipeline: '%s'\n", pipeline{n});
154     endif
155     drawnow (gl2ps_device{n}, strcat('|',pipeline{n}));
156   endfor
157
158   if (! isempty (strfind (opts.devopt, "standalone")))
159     opts.latex_standalone (opts);
160   endif
161
162 endfunction
163