annotate scripts/plot/private/__ghostscript__.m @ 14868:5d3a684236b0

maint: Use Octave coding conventions for cuddling parentheses in scripts directory * lin2mu.m, loadaudio.m, wavread.m, accumarray.m, bicubic.m, celldisp.m, colon.m, cplxpair.m, dblquad.m, divergence.m, genvarname.m, gradient.m, int2str.m, interp1.m, interp1q.m, interp2.m, interpn.m, loadobj.m, nthargout.m, __isequal__.m, __splinen__.m, quadgk.m, quadl.m, quadv.m, rat.m, rot90.m, rotdim.m, saveobj.m, subsindex.m, triplequad.m, delaunay3.m, griddata.m, inpolygon.m, tsearchn.m, voronoi.m, get_first_help_sentence.m, which.m, gray2ind.m, pink.m, dlmwrite.m, strread.m, textread.m, textscan.m, housh.m, ishermitian.m, issymmetric.m, krylov.m, logm.m, null.m, rref.m, compare_versions.m, copyfile.m, dump_prefs.m, edit.m, fileparts.m, getappdata.m, isappdata.m, movefile.m, orderfields.m, parseparams.m, __xzip__.m, rmappdata.m, setappdata.m, swapbytes.m, unpack.m, ver.m, fminbnd.m, fminunc.m, fsolve.m, glpk.m, lsqnonneg.m, qp.m, sqp.m, configure_make.m, copy_files.m, describe.m, get_description.m, get_forge_pkg.m, install.m, installed_packages.m, is_architecture_dependent.m, load_package_dirs.m, print_package_description.m, rebuild.m, repackage.m, save_order.m, shell.m, allchild.m, ancestor.m, area.m, axes.m, axis.m, clabel.m, close.m, colorbar.m, comet.m, comet3.m, contour.m, cylinder.m, ezmesh.m, ezsurf.m, findobj.m, fplot.m, hist.m, isocolors.m, isonormals.m, isosurface.m, isprop.m, legend.m, mesh.m, meshz.m, pareto.m, pcolor.m, peaks.m, plot3.m, plotmatrix.m, plotyy.m, polar.m, print.m, __add_datasource__.m, __add_default_menu__.m, __axes_limits__.m, __bar__.m, __clabel__.m, __contour__.m, __errcomm__.m, __errplot__.m, __ezplot__.m, __file_filter__.m, __fltk_print__.m, __ghostscript__.m, __gnuplot_print__.m, __go_draw_axes__.m, __go_draw_figure__.m, __interp_cube__.m, __marching_cube__.m, __patch__.m, __pie__.m, __plt__.m, __print_parse_opts__.m, __quiver__.m, __scatter__.m, __stem__.m, __tight_eps_bbox__.m, __uigetdir_fltk__.m, __uigetfile_fltk__.m, __uiputfile_fltk__.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m, scatter.m, semilogy.m, shading.m, slice.m, subplot.m, surface.m, surfl.m, surfnorm.m, text.m, uigetfile.m, uiputfile.m, whitebg.m, deconv.m, mkpp.m, pchip.m, polyaffine.m, polyder.m, polygcd.m, polyout.m, polyval.m, ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, splinefit.m, addpref.m, getpref.m, setpref.m, ismember.m, setxor.m, arch_fit.m, arch_rnd.m, arch_test.m, autoreg_matrix.m, diffpara.m, fftconv.m, filter2.m, hanning.m, hurst.m, periodogram.m, triangle_sw.m, sinc.m, spectral_xdf.m, spencer.m, stft.m, synthesis.m, unwrap.m, yulewalker.m, bicgstab.m, gmres.m, pcg.m, pcr.m, __sprand_impl__.m, speye.m, spfun.m, sprandn.m, spstats.m, svds.m, treelayout.m, treeplot.m, bessel.m, factor.m, legendre.m, perms.m, primes.m, magic.m, toeplitz.m, corr.m, cov.m, mean.m, median.m, mode.m, qqplot.m, quantile.m, ranks.m, zscore.m, logistic_regression_likelihood.m, bartlett_test.m, chisquare_test_homogeneity.m, chisquare_test_independence.m, kolmogorov_smirnov_test.m, run_test.m, u_test.m, wilcoxon_test.m, z_test.m, z_test_2.m, bin2dec.m, dec2base.m, mat2str.m, strcat.m, strchr.m, strjust.m, strtok.m, substr.m, untabify.m, assert.m, demo.m, example.m, fail.m, speed.m, test.m, now.m: Use Octave coding conventions for cuddling parentheses in scripts directory.
author Rik <octave@nomad.inbox5.com>
date Tue, 17 Jul 2012 07:08:39 -0700
parents 460a3c6d8bf1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 12931
diff changeset
1 ## Copyright (C) 2010-2012 Ben Abbott
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
2 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
3 ## This file is part of Octave.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
4 ##
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
6 ## under the terms of the GNU General Public License as published by
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
8 ## your option) any later version.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
9 ##
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
13 ## General Public License for more details.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11014
diff changeset
14 ##
10834
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
18
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
19 ## -*- texinfo -*-
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
20 ## @deftypefn {Function File} {} __ghostscript__ (@var{@dots{}})
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
21 ## Undocumented internal function.
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
22 ## @end deftypefn
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
23
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
24 ## Author: Ben Abbott <bpabbott@mac.com>
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
25 ## Created: 2010-07-26
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
26
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
27 function [gs_cmd, cleanup_cmd] = __ghostscript__ (varargin);
10834
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
28
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
29 opts.binary = "";
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
30 opts.source = "-";
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
31 opts.output = "-";
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
32 opts.device = "";
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
33 opts.epscrop = false;
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
34 opts.antialiasing = false;
14774
0d6dae0f6bc2 Allow setting of ghostscript TextAlphaBits and GraphicsAlphaBits.
John Hunt <huntj@gmx.us>
parents: 14768
diff changeset
35 opts.antialiasing_textalphabits = 4;,
0d6dae0f6bc2 Allow setting of ghostscript TextAlphaBits and GraphicsAlphaBits.
John Hunt <huntj@gmx.us>
parents: 14768
diff changeset
36 opts.antialiasing_graphicsalphabits = 4;
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
37 opts.resolution = 150;
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
38 opts.papersize = "";
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
39 opts.pageoffset = [0 0];
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
40 opts.debug = false;
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
41 opts.level = [];
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
42 opts.prepend = "";
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
43
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
44 offsetfile = "";
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
45 offset_ps = {};
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
46 cleanup_cmd = "";
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
47
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
48 args = varargin;
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12460
diff changeset
49 n = find (cellfun ("isclass", args, "struct"));
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
50 if (! isempty (n))
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
51 f = fieldnames (args{n});
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
52 for m = 1:numel (f)
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
53 opts.(f{m}) = args{n}.(f{m});
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
54 endfor
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
55 args(n) = [];
10834
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
56 endif
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
57 for n = 1:2:numel (args)
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
58 opts.(args{n}) = args{n+1};
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
59 endfor
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
60
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
61 if (isempty (opts.papersize))
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
62 format_for_printer = false;
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
63 else
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
64 format_for_printer = true;
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
65 endif
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
66
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
67 gs_opts = sprintf ("-dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s", opts.device);
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
68
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
69 if (! isempty (opts.level) && ismember (opts.level, [1, 2, 3]))
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
70 gs_opts = sprintf ("%s -dLanguageLevel=%d", gs_opts, round (opts.level));
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
71 endif
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
72
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
73 if (opts.antialiasing && isempty (strfind (opts.device, "write")))
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
74 ## Apply anti-aliasing to all bitmap formats/devices
14774
0d6dae0f6bc2 Allow setting of ghostscript TextAlphaBits and GraphicsAlphaBits.
John Hunt <huntj@gmx.us>
parents: 14768
diff changeset
75 gs_opts = sprintf ("%s -dTextAlphaBits=%d -dGraphicsAlphaBits=%d",
0d6dae0f6bc2 Allow setting of ghostscript TextAlphaBits and GraphicsAlphaBits.
John Hunt <huntj@gmx.us>
parents: 14768
diff changeset
76 gs_opts, opts.antialiasing_textalphabits,
0d6dae0f6bc2 Allow setting of ghostscript TextAlphaBits and GraphicsAlphaBits.
John Hunt <huntj@gmx.us>
parents: 14768
diff changeset
77 opts.antialiasing_graphicsalphabits);
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
78 gs_opts = sprintf ("%s -r%dx%d", gs_opts, [1, 1] * opts.resolution);
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
79 elseif (any (strcmp (opts.device, {"pswrite", "ps2write", "pdfwrite"})))
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
80 gs_opts = sprintf ("%s -dEmbedAllFonts=true", gs_opts);
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
81 if (strcmp (opts.device, "pdfwrite"))
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
82 ## Optimize for loading
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
83 gs_opts = sprintf ("%s -dOptimize=true", gs_opts);
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
84 endif
10834
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
85 endif
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
86
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
87 if (opts.epscrop)
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
88 ## papersize is specified by the eps bbox
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
89 gs_opts = sprintf ("%s -dEPSCrop", gs_opts);
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
90 endif
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
91 if (format_for_printer)
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
92 if (ischar (opts.papersize))
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
93 gs_opts = sprintf ("%s -sPAPERSIZE=%s", gs_opts, opts.papersize);
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
94 elseif (isnumeric (opts.papersize) && numel (opts.papersize) == 2)
10954
ee9d74048827 Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents: 10919
diff changeset
95 gs_opts = sprintf ("%s -dDEVICEWIDTHPOINTS=%d -dDEVICEHEIGHTPOINTS=%d",
ee9d74048827 Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents: 10919
diff changeset
96 gs_opts, opts.papersize);
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
97 if (opts.papersize(1) > opts.papersize(2))
10954
ee9d74048827 Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents: 10919
diff changeset
98 ## Lanscape mode: This option will result in automatic rotation of the
ee9d74048827 Consolidate gs code into print.m.
Ben Abbott <bpabbott@mac.com>
parents: 10919
diff changeset
99 ## document page if the requested page size matches one
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
100 ## of the default page sizes
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
101 gs_opts = sprintf ("%s -dNORANGEPAGESIZE", gs_opts);
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
102 endif
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
103 else
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11588
diff changeset
104 error ("print:badpapersize", "__ghostscript__.m: invalid 'papersize'");
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
105 endif
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
106 gs_opts = sprintf ("%s -dFIXEDMEDIA", gs_opts);
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
107 ## "pageoffset" is relative to the coordinates, not the BBox LLHC.
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
108 str = sprintf ("%s [%d %d] %s", "<< /Margins [0 0] /.HWMargins [0 0 0 0] /PageOffset",
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
109 opts.pageoffset, ">> setpagedevice");
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
110 offset_ps = {"%!PS-Adobe-3.0", str, "%%EOF"};
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
111 if (isfield (opts, "offsetfile"))
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
112 offsetfile = opts.offsetfile;
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
113 cleanup_cmd = "";
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
114 else
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
115 offsetfile = strcat (tmpnam (), ".ps");
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
116 cleanup_cmd = sprintf ("rm %s", offsetfile);
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
117 endif
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
118 unwind_protect
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
119 fid = fopen (offsetfile, "w");
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
120 if (fid == -1)
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14774
diff changeset
121 error ("print:fopenfailed", "__ghostscript__.m: fopen () failed");
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
122 endif
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11588
diff changeset
123 fprintf (fid, "%s\n", offset_ps{:});
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
124 unwind_protect_cleanup
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
125 status = fclose (fid);
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
126 if (status == -1)
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14774
diff changeset
127 error ("print:fclosefailed", "__ghostscript__.m: fclose () failed");
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
128 endif
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10854
diff changeset
129 end_unwind_protect
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
130 if (opts.debug)
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11588
diff changeset
131 fprintf ("---- begin %s ----\n", offsetfile);
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11588
diff changeset
132 fprintf ("%s\n", offset_ps{:});
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11588
diff changeset
133 fprintf ("----- end %s -----\n", offsetfile);
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
134 endif
10834
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
135 endif
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
136
12460
952e52dda82e Improve warnings when shell utilties needed for printing are missing.
Ben Abbott <bpabbott@mac.com>
parents: 11589
diff changeset
137 if (isempty (opts.binary))
952e52dda82e Improve warnings when shell utilties needed for printing are missing.
Ben Abbott <bpabbott@mac.com>
parents: 11589
diff changeset
138 error ("print:no_ghostscript", "__ghostscript__.m: ghostscript is required.");
952e52dda82e Improve warnings when shell utilties needed for printing are missing.
Ben Abbott <bpabbott@mac.com>
parents: 11589
diff changeset
139 elseif (isempty (opts.output))
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
140 cmd = sprintf ("%s %s", opts.binary, gs_opts);
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
141 else
14768
1c7956c661a8 Support spaces into the path to ghostscript.
Fabio Rossi <rossi.f@inwind.it>
parents: 14138
diff changeset
142 cmd = sprintf ("%s %s -sOutputFile=\"%s\"", opts.binary, gs_opts, opts.output);
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
143 endif
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
144 if (! isempty (opts.prepend)
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
145 && any (strcmpi (opts.device, {"pswrite", "ps2write", "pdfwrite"})))
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
146 ## FIXME - Fonts get may be mangled when appending ps/ps2.
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
147 ## See "How to concatenate several PS files" at the link,
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
148 ## http://en.wikibooks.org/wiki/PostScript_FAQ
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
149 cmd = sprintf ("%s %s", cmd, opts.prepend);
11014
92bb25c0da9e When appending, delete temporary files at the end of the ghostscript pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 11009
diff changeset
150 if (isempty (cleanup_cmd))
92bb25c0da9e When appending, delete temporary files at the end of the ghostscript pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 11009
diff changeset
151 cleanup_cmd = sprintf ("rm %s", opts.prepend);
92bb25c0da9e When appending, delete temporary files at the end of the ghostscript pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 11009
diff changeset
152 else
92bb25c0da9e When appending, delete temporary files at the end of the ghostscript pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 11009
diff changeset
153 cleanup_cmd = sprintf ("%s ; rm %s", cleanup_cmd, opts.prepend);
92bb25c0da9e When appending, delete temporary files at the end of the ghostscript pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 11009
diff changeset
154 endif
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
155 endif
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
156 if (! isempty (offsetfile) && format_for_printer)
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
157 cmd = sprintf ("%s %s", cmd, offsetfile);
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
158 endif
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
159 if (! isempty (opts.source))
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
160 cmd = sprintf ("%s %s", cmd, opts.source);
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
161 endif
10834
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
162
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
163 if (opts.debug)
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
164 fprintf ("Ghostscript command: '%s'\n", cmd);
10834
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
165 endif
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
166
11009
064aaf82222f Print via a pipeline.
Ben Abbott <bpabbott@mac.com>
parents: 10954
diff changeset
167 gs_cmd = cmd;
10834
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
168
05ba991794d4 Improvements for fltk printing.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
169 endfunction
10854
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
170
d5a7db05d591 Add PS and PDF output for the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10834
diff changeset
171