Mercurial > hg > octave-nkf
annotate scripts/plot/__fltk_print__.m @ 11305:c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Thu, 02 Dec 2010 18:46:10 -0500 |
parents | a44f979a35ce |
children | f1a4db353da5 |
rev | line source |
---|---|
10727
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
1 ## Copyright (C) 2010 Shai Ayal |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
2 ## |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
4 ## |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
8 ## your option) any later version. |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
9 ## |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
13 ## General Public License for more details. |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
14 ## |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
18 |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10727
diff
changeset
|
20 ## @deftypefn {Function File} {} __fltk_print__ (@var{@dots{}}) |
10727
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
21 ## Undocumented internal function. |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
22 ## @end deftypefn |
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
23 |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
24 function opts = __fltk_print__ (opts) |
10834
05ba991794d4
Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
25 |
11009 | 26 dos_shell = (ispc () && ! isunix ()); |
27 | |
10913
dd6b90f44ae5
Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10864
diff
changeset
|
28 figure (opts.figure) |
dd6b90f44ae5
Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10864
diff
changeset
|
29 drawnow ("expose") |
dd6b90f44ae5
Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10864
diff
changeset
|
30 |
10854
d5a7db05d591
Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10834
diff
changeset
|
31 if (! isempty (opts.fig2dev_binary)) |
11009 | 32 ## fig2dev is prefered for conversion to emf |
10854
d5a7db05d591
Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10834
diff
changeset
|
33 fig2dev_devices = {"pstex", "mf", "emf"}; |
d5a7db05d591
Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10834
diff
changeset
|
34 else |
d5a7db05d591
Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10834
diff
changeset
|
35 fig2dev_devices = {"pstex", "mf"}; |
10834
05ba991794d4
Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
36 endif |
10727
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
37 |
11009 | 38 gl2ps_device = {}; |
39 pipeline = {}; | |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
11009
diff
changeset
|
40 switch (lower (opts.devopt)) |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
41 case {"eps", "eps2", "epsc", "epsc2"} |
11009 | 42 ## format GL2PS_EPS |
43 gl2ps_device = {"eps"}; | |
44 ## FIXME - use epstool to tighten bbox and provide preview. | |
45 pipeline = {opts.epstool_cmd(opts, "-", opts.name)}; | |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
46 case {"epslatex", "pslatex", "pdflatex", "epslatexstandalone", ... |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
47 "pslatexstandalone", "pdflatexstandalone"} |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
48 ## format GL2PS_TEX |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
49 n = find (opts.devopt == "l", 1); |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
50 suffix = opts.devopt(1:n-1); |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
51 dot = find (opts.name == ".", 1, "last"); |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
52 if ((! isempty (dot)) |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
53 && any (strcmpi (opts.name(dot:end), ... |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
54 {".eps", ".ps", ".pdf", ".tex", "."}))) |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
55 name = opts.name(1:dot-1); |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
56 if (dot < numel (opts.name) |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
57 && any (strcmpi (opts.name(dot+1:end), {"eps", "ps", "pdf"}))) |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
58 ## If user provides eps/ps/pdf suffix, use it. |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
59 suffix = opts.name(dot+1:end); |
10861 | 60 endif |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
61 elseif (dot == numel (opts.name)) |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
62 name = opts.name; |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
63 endif |
11009 | 64 gl2ps_device = {sprintf("%snotxt", lower (suffix))}; |
65 gl2ps_device{2} = "tex"; | |
66 if (dos_shell) | |
67 pipeline = {sprintf("copy con %s.%s", name, suffix)}; | |
68 pipeline{2} = sprintf ("copy con %s.tex", name); | |
69 else | |
70 pipeline = {sprintf("cat > %s.%s", name, suffix)}; | |
71 pipeline{2} = sprintf ("cat > %s.tex", name); | |
10854
d5a7db05d591
Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10834
diff
changeset
|
72 endif |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
11009
diff
changeset
|
73 case "tikz" |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
74 ## format GL2PS_PGF |
11009 | 75 gl2ps_device = {"pgf"}; |
76 pipeline = {sprintf("cat > %s", opts.name)}; | |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
11009
diff
changeset
|
77 case "svg" |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
78 ## format GL2PS_SVG |
11009 | 79 gl2ps_device = {"svg"}; |
80 pipeline = {sprintf("cat > %s", opts.name)}; | |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
81 case fig2dev_devices |
11009 | 82 cmd_pstoedit = opts.pstoedit_cmd (opts, "fig"); |
83 cmd_fig2dev = opts.fig2dev_cmd (opts, opts.devopt); | |
84 if (strcmp (opts.devopt, "pstex")) | |
85 [~, ~, ext] = fileparts (opts.name); | |
86 if (any (strcmpi (ext, {".ps", ".tex", "."}))) | |
87 opts.name = opts.name(1:end-numel(ext)); | |
10913
dd6b90f44ae5
Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents:
10864
diff
changeset
|
88 endif |
11009 | 89 opts.name = strcat (opts.name, ".ps"); |
90 cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name); | |
91 gl2ps_device = {"eps"}; | |
92 pipeline = {cmd}; | |
93 cmd_fig2dev = opts.fig2dev_cmd (opts, "pstex_t"); | |
94 gl2ps_device{2} = "eps"; | |
95 pipeline{2} = sprintf ("%s | %s > %s", cmd_pstoedit, | |
96 cmd_fig2dev, strrep(opts.name, ".ps", ".tex")); | |
97 else | |
98 cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name); | |
99 gl2ps_device = {"eps"}; | |
100 pipeline = {cmd}; | |
10834
05ba991794d4
Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
101 endif |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
11009
diff
changeset
|
102 case "aifm" |
11009 | 103 cmd = opts.pstoedit_cmd (opts, "ps2ai"); |
104 gl2ps_device = {"eps"}; | |
105 pipeline = {sprintf("%s > %s", cmd, opts.name)}; | |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
106 case {"dxf", "emf", "fig", "hpgl"} |
11009 | 107 cmd = opts.pstoedit_cmd (opts); |
108 gl2ps_device = {"eps"}; | |
109 pipeline = {sprintf("%s > %s", cmd, opts.name)}; | |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
110 case {"corel", "gif"} |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
111 error ("print:unsupporteddevice", |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
112 "print.m: %s output is not available for the FLTK backend.", |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
113 upper (opts.devopt)) |
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
114 case opts.ghostscript.device |
11009 | 115 opts.ghostscript.source = "-"; |
116 opts.ghostscript.output = opts.name; | |
117 if (opts.send_to_printer) | |
118 opts.unlink(strcmp (opts.unlink, opts.ghostscript.output)) = []; | |
119 opts.ghostscript.output = "-"; | |
120 endif | |
121 [cmd_gs, cmd_cleanup] = __ghostscript__ (opts.ghostscript); | |
122 if (opts.send_to_printer || isempty (opts.name)) | |
123 cmd_lpr = opts.lpr_cmd (opts); | |
124 cmd = sprintf("%s | %s", cmd_gs, cmd_lpr); | |
125 else | |
126 cmd = sprintf("%s", cmd_gs); | |
127 endif | |
128 if (! isempty (cmd_cleanup)) | |
129 gl2ps_device = {"eps"}; | |
130 if (dos_shell) | |
131 pipeline = {sprintf("%s & %s", cmd, cmd_cleanup)}; | |
132 else | |
133 pipeline = {sprintf("%s ; %s", cmd, cmd_cleanup)}; | |
134 endif | |
135 else | |
136 gl2ps_device = {"eps"}; | |
137 pipeline = {cmd}; | |
138 endif | |
139 otherwise | |
140 error (sprintf ("print:no%soutput", opts.devopt), | |
141 "print.m: %s output is not available for GL2PS output.", | |
142 upper (opts.devopt)) | |
10954
ee9d74048827
Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents:
10913
diff
changeset
|
143 endswitch |
10727
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
144 |
11009 | 145 opts.pipeline = pipeline; |
146 | |
147 for n = 1:numel(pipeline) | |
148 if (opts.debug) | |
149 fprintf ("fltk-pipeline: '%s'\n", pipeline{n}) | |
150 endif | |
151 pid = popen (pipeline{n}, "w"); | |
152 if (pid < 0) | |
153 error ("print:popenfailed", "print.m: failed to open pipe."); | |
154 endif | |
155 unwind_protect | |
156 drawnow (gl2ps_device{n} , sprintf ("%d" , pid)); | |
157 waitpid (pid); | |
158 unwind_protect_cleanup | |
159 pclose (pid); | |
160 end_unwind_protect | |
161 endfor | |
162 | |
10727
570f30a48732
split printing between backends
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff
changeset
|
163 endfunction |
10834
05ba991794d4
Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
164 |