5362
|
1 ## Copyright (C) 1999 Daniel Heiserer |
5361
|
2 ## Copyright (C) 2001 Laurent Mazet |
|
3 ## |
5362
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 2, or (at your option) |
|
9 ## any later version. |
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
5361
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
5362
|
17 ## along with Octave; see the file COPYING. If not, write to the Free |
|
18 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 ## 02110-1301, USA. |
5361
|
20 |
|
21 ## -*- texinfo -*- |
|
22 ## @deftypefn {Function File} {} print (@var{filename}, @var{options}) |
|
23 ## |
|
24 ## Print a graph, or save it to a file |
|
25 ## |
|
26 ## @var{filename} defines the file name of the output file. If no |
|
27 ## filename is specified, output is sent to the printer. |
|
28 ## |
|
29 ## @var{options}: |
|
30 ## @table @code |
|
31 ## @item -P@var{printer} |
|
32 ## Set the @var{printer} name to which the graph is sent if no |
|
33 ## @var{filename} is specified. |
|
34 ## @item -color |
|
35 ## @itemx -mono |
|
36 ## Monochrome or colour lines. |
|
37 ## @item -solid |
|
38 ## @itemx -dashed |
|
39 ## Solid or dashed lines. |
|
40 ## @item -portrait |
|
41 ## @itemx -landscape |
|
42 ## Plot orientation, as returned by "orient". |
|
43 ## @item -d@var{device} |
|
44 ## Output device, where @var{device} is one of: |
|
45 ## @table @code |
|
46 ## @item ps |
|
47 ## @itemx ps2 |
|
48 ## @itemx psc |
|
49 ## @itemx psc2 |
|
50 ## Postscript (level 1 and 2, mono and color) |
|
51 ## @item eps |
|
52 ## @itemx eps2 |
|
53 ## @itemx epsc |
|
54 ## @itemx epsc2 |
|
55 ## Encapsulated postscript (level 1 and 2, mono and color) |
|
56 ## @item ill |
|
57 ## @itemx aifm |
|
58 ## Adobe Illustrator |
|
59 ## @item cdr |
|
60 ## @itemx corel |
|
61 ## CorelDraw |
|
62 ## @item hpgl |
|
63 ## HP plotter language |
|
64 ## @item fig |
|
65 ## XFig |
|
66 ## @item dxf |
|
67 ## AutoCAD |
|
68 ## @item mf |
|
69 ## Metafont |
|
70 ## @item png |
|
71 ## Portable network graphics |
|
72 ## @item pbm |
|
73 ## PBMplus |
5794
|
74 ## @item emf |
|
75 ## Microsoft Enhanced Metafile |
5361
|
76 ## @end table |
|
77 ## |
|
78 ## Other devices are supported by "convert" from ImageMagick. Type |
|
79 ## system("convert") to see what formats are available. |
|
80 ## |
|
81 ## If the device is omitted, it is inferred from the file extension, |
|
82 ## or if there is no filename it is sent to the printer as postscript. |
|
83 ## |
|
84 ## @item -F@var{fontname} |
|
85 ## @itemx -F@var{fontname}:@var{size} |
|
86 ## @itemx -F:@var{size} |
|
87 ## @var{fontname} set the postscript font (for use with postscript, |
|
88 ## aifm, corel and fig). By default, 'Helvetica' is set for PS/Aifm, |
|
89 ## and 'SwitzerlandLight' for Corel. It can also be 'Times-Roman'. |
|
90 ## @var{size} is given in points. @var{fontname} is ignored for the |
|
91 ## fig device. |
|
92 ## @end table |
|
93 ## |
|
94 ## The filename and options can be given in any order. |
|
95 ## @end deftypefn |
|
96 |
|
97 ## Author: Daniel Heiserer <Daniel.heiserer@physik.tu-muenchen.de> |
5362
|
98 ## Adapted-By: jwe |
5361
|
99 |
5362
|
100 ## PKG_ADD: mark_as_command print |
|
101 |
|
102 function print (varargin) |
5361
|
103 |
5365
|
104 orientation = orient (); |
5361
|
105 use_color = 0; # 0=default, -1=mono, +1=color |
|
106 force_solid = 0; # 0=default, -1=dashed, +1=solid |
5363
|
107 fontsize = ""; |
|
108 font = ""; |
|
109 name = ""; |
|
110 devopt = ""; |
|
111 printer = ""; |
5361
|
112 |
5362
|
113 for i = 1:nargin |
5363
|
114 arg = varargin{i}; |
5443
|
115 if (ischar (arg)) |
5362
|
116 if (strcmp (arg, "-color")) |
5361
|
117 use_color = 1; |
5362
|
118 elseif (strcmp (arg, "-mono")) |
5361
|
119 use_color = -1; |
5362
|
120 elseif (strcmp (arg, "-solid")) |
5361
|
121 force_solid = 1; |
5362
|
122 elseif (strcmp (arg, "-dashed")) |
5361
|
123 force_solid = -1; |
5362
|
124 elseif (strcmp (arg, "-portrait")) |
5361
|
125 orientation = "portrait"; |
5362
|
126 elseif (strcmp (arg, "-landscape")) |
5361
|
127 orientation = "landscape"; |
5362
|
128 elseif (length (arg) > 2 && arg(1:2) == "-d") |
5361
|
129 devopt = arg(3:length(arg)); |
5362
|
130 elseif (length (arg) > 2 && arg(1:2) == "-P") |
5361
|
131 printer = arg; |
5362
|
132 elseif (length (arg) > 2 && arg(1:2) == "-F") |
5361
|
133 idx = rindex(arg, ":"); |
|
134 if (idx) |
|
135 font = arg(3:idx-1); |
|
136 fontsize = arg(idx+1:length(arg)); |
|
137 else |
|
138 font = arg(3:length(arg)); |
|
139 endif |
5362
|
140 elseif (length (arg) >= 1 && arg(1) == "-") |
|
141 error ("print: unknown option `%s'", arg); |
|
142 elseif (length (arg) > 0) |
5361
|
143 name = arg; |
|
144 endif |
|
145 else |
5362
|
146 error ("print: expects string options"); |
5361
|
147 endif |
|
148 endfor |
|
149 |
5362
|
150 doprint = isempty (name); |
|
151 if (doprint) |
|
152 if (isempty (devopt)) |
5363
|
153 printname = strcat (tmpnam, ".ps"); |
5361
|
154 else |
5363
|
155 printname = strcat (tmpnam, ".", devopt); |
5361
|
156 endif |
|
157 name = printname; |
|
158 endif |
|
159 |
5362
|
160 if (isempty (devopt)) |
|
161 dot = rindex (name, "."); |
5363
|
162 if (dot == 0) |
5361
|
163 error ("print: no format specified"); |
|
164 else |
5362
|
165 dev = tolower (name(dot+1:end)); |
5361
|
166 endif |
|
167 else |
|
168 dev = devopt; |
|
169 endif |
|
170 |
6727
|
171 if (strcmp (dev, "tex")) |
|
172 dev = "epslatex"; |
|
173 ## gnuplot 4.0 wants ".eps" in the output name |
|
174 if (compare_versions (__gnuplot_version__, "4.2", "<")) |
|
175 name = strcat (name(1:dot), "eps"); |
|
176 endif |
|
177 elseif (strcmp (dev, "ill")) |
5361
|
178 dev = "aifm"; |
5362
|
179 elseif (strcmp (dev, "cdr")) |
5361
|
180 dev = "corel"; |
|
181 endif |
|
182 |
|
183 ## check if we have to use convert |
6727
|
184 dev_list = {"aifm", "corel", "fig", "png", "pbm", "dxf", "mf", ... |
|
185 "hpgl", "ps", "ps2", "psc", "psc2", "eps", "eps2", ... |
|
186 "epsc", "epsc2", "emf", "pstex", "pslatex", ... |
|
187 "epslatex", "epslatexstandalone"}; |
5361
|
188 convertname = ""; |
6272
|
189 [idx, errmsg] = cellidx (dev_list, dev); |
5363
|
190 if (! idx) |
5362
|
191 if (! isempty (devopt)) |
5363
|
192 convertname = strcat (devopt, ":", name); |
5361
|
193 else |
|
194 convertname = name; |
|
195 endif |
|
196 dev = "epsc"; |
5363
|
197 name = strcat (tmpnam, ".eps"); |
5361
|
198 endif |
5363
|
199 |
6179
|
200 if (strcmp (dev, "ps") || strcmp (dev, "ps2") ... |
|
201 || strcmp (dev, "psc") || strcmp (dev, "psc2") |
|
202 || strcmp (dev, "epsc") || strcmp (dev, "epsc2") |
6727
|
203 || strcmp (dev, "eps") || strcmp (dev, "eps2") |
|
204 || strcmp (dev, "pstex")|| strcmp (dev, "pslatex") |
|
205 || strcmp (dev, "epslatex") || strcmp (dev, "epslatexstandalone")) |
|
206 |
6179
|
207 ## Various postscript options |
6727
|
208 if (strcmp (dev, "pstex")|| strcmp (dev, "pslatex") |
|
209 || strcmp (dev, "epslatex")) |
|
210 termn = dev; |
|
211 options = ""; |
|
212 elseif (strcmp (dev, "epslatexstandalone")) |
|
213 if (compare_versions (__gnuplot_version__, "4.2", ">=")) |
|
214 termn = "epslatex"; |
|
215 options = "standalone "; |
|
216 else |
|
217 error ("print: epslatexstandalone needs gnuplot 4.2 or higher"); |
|
218 endif |
6179
|
219 else |
6727
|
220 if (dev(1) == "e") |
|
221 options = "eps "; |
|
222 else |
|
223 options = strcat (orientation, " "); |
|
224 endif |
|
225 options = strcat (options, "enhanced "); |
|
226 termn = "postscript"; |
6179
|
227 endif |
6727
|
228 |
6179
|
229 if (any (dev == "c") || use_color > 0) |
|
230 if (force_solid < 0) |
|
231 options = strcat (options, "color dashed "); |
5361
|
232 else |
6179
|
233 options = strcat (options, "color solid "); |
5361
|
234 endif |
6179
|
235 else |
|
236 if (force_solid > 0) |
|
237 options = strcat (options, "mono solid "); |
5625
|
238 else |
6179
|
239 options = strcat (options, "mono dashed "); |
5625
|
240 endif |
6179
|
241 endif |
6178
|
242 |
6179
|
243 if (! isempty (font)) |
|
244 options = strcat (options, "\"", font, "\" "); |
|
245 endif |
|
246 if (! isempty (fontsize)) |
|
247 options = strcat (options, " ", fontsize); |
|
248 endif |
6727
|
249 |
|
250 new_terminal = strcat (termn, " ", options); |
|
251 |
6179
|
252 elseif (strcmp (dev, "aifm") || strcmp (dev, "corel")) |
|
253 ## Adobe Illustrator, CorelDraw |
|
254 if (use_color >= 0) |
|
255 options = " color"; |
|
256 else |
|
257 options = " mono"; |
|
258 endif |
|
259 if (! isempty (font)) |
|
260 options = strcat (options, " \"", font, "\""); |
|
261 endif |
|
262 if (! isempty (fontsize)) |
|
263 options = strcat (options, " ", fontsize); |
5362
|
264 endif |
5363
|
265 |
6179
|
266 new_terminal = strcat (dev, " ", options); |
5361
|
267 |
6179
|
268 elseif (strcmp (dev, "fig")) |
|
269 ## XFig |
|
270 options = orientation; |
|
271 if (use_color >= 0) |
|
272 options = " color"; |
|
273 else |
|
274 options = " mono"; |
|
275 endif |
|
276 if (! isempty (fontsize)) |
|
277 options = strcat (options, " fontsize ", fontsize); |
|
278 endif |
6178
|
279 |
6179
|
280 new_terminal = strcat ("fig ", options); |
5363
|
281 |
6179
|
282 elseif (strcmp (dev, "emf")) |
|
283 ## Enhanced Metafile format |
|
284 options = " "; |
|
285 if (use_color >= 0) |
|
286 options = " color"; |
|
287 else |
|
288 options = " mono"; |
|
289 endif |
|
290 if (force_solid >= 0) |
|
291 options = strcat (options, " solid"); |
|
292 endif |
|
293 if (! isempty (font)) |
|
294 options = strcat (options, " \"", font, "\""); |
|
295 endif |
|
296 if (! isempty (fontsize)) |
|
297 options = strcat (options, " ", fontsize); |
|
298 endif |
|
299 |
|
300 new_terminal = strcat ("emf ", options); |
5361
|
301 |
6179
|
302 elseif (strcmp (dev, "png") || strcmp (dev, "pbm")) |
|
303 ## Portable network graphics, PBMplus |
|
304 |
|
305 ## FIXME -- New PNG interface takes color as "xRRGGBB" |
|
306 ## where x is the literal character 'x' and 'RRGGBB' are the red, |
|
307 ## green and blue components in hex. For now we just ignore it |
|
308 ## and use default. The png terminal now is so rich with options, |
|
309 ## that one perhaps has to write a separate printpng.m function. |
|
310 ## DAS |
5361
|
311 |
6179
|
312 ## if (use_color >= 0) |
|
313 ## eval (sprintf ("__gnuplot_set__ term %s color medium", dev)); |
|
314 ##else |
|
315 ##eval (sprintf ("__gnuplot_set__ term %s mono medium", dev)); |
|
316 ##endif |
6178
|
317 |
6179
|
318 new_terminal = "png large"; |
|
319 |
|
320 elseif (strcmp (dev, "dxf") || strcmp (dev, "mf") || strcmp (dev, "hpgl")) |
|
321 ## AutoCad DXF, METAFONT, HPGL |
|
322 new_terminal = dev; |
|
323 endif |
|
324 |
6257
|
325 drawnow (new_terminal, name); |
5361
|
326 |
5362
|
327 if (! isempty (convertname)) |
5363
|
328 command = sprintf ("convert '%s' '%s'", name, convertname); |
5659
|
329 [errcode, output] = system (command); |
5361
|
330 unlink (name); |
|
331 if (errcode) |
|
332 error ("print: could not convert"); |
|
333 endif |
|
334 endif |
5362
|
335 |
5775
|
336 ## FIXME -- This looks like a dirty, Unix-specific hack. |
5361
|
337 ## DAS |
5362
|
338 if (doprint) |
|
339 system (sprintf ("lpr %s '%s'", printer, printname)); |
|
340 unlink (printname); |
5361
|
341 endif |
5363
|
342 |
5361
|
343 endfunction |