Mercurial > hg > octave-max
comparison scripts/plot/private/__ghostscript__.m @ 10913:dd6b90f44ae5
Unify gnuplot printing with the fltk backend.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Fri, 27 Aug 2010 06:39:36 -0400 |
parents | d5a7db05d591 |
children | 2a3279d11794 |
comparison
equal
deleted
inserted
replaced
10912:9abc67b4bd4f | 10913:dd6b90f44ae5 |
---|---|
32 opts.antialiasing = false; | 32 opts.antialiasing = false; |
33 opts.resolution = 150; | 33 opts.resolution = 150; |
34 opts.papersize = ""; | 34 opts.papersize = ""; |
35 opts.pageoffset = [0 0]; | 35 opts.pageoffset = [0 0]; |
36 opts.debug = false; | 36 opts.debug = false; |
37 opts.level = []; | |
37 | 38 |
38 offsetfile = ""; | 39 offsetfile = ""; |
39 | 40 |
40 args = varargin; | 41 args = varargin; |
41 n = find (cellfun (@isstruct, args)); | 42 n = find (cellfun (@isstruct, args)); |
49 for n = 1:2:numel(args) | 50 for n = 1:2:numel(args) |
50 opts.(args{n}) = args{n+1}; | 51 opts.(args{n}) = args{n+1}; |
51 endfor | 52 endfor |
52 | 53 |
53 gs_opts = sprintf ("-dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s", opts.device); | 54 gs_opts = sprintf ("-dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s", opts.device); |
55 | |
56 if (! isempty (opts.level) && ismember (opts.level, [1, 2, 3])) | |
57 gs_opts = sprintf ("%s -dLanguageLevel=%d", gs_opts, round (opts.level)); | |
58 endif | |
59 | |
54 if (opts.antialiasing) | 60 if (opts.antialiasing) |
55 gs_opts = sprintf ("%s -dTextAlphaBits=4 -dGraphicsAlphaBits=4", gs_opts); | 61 gs_opts = sprintf ("%s -dTextAlphaBits=4 -dGraphicsAlphaBits=4", gs_opts); |
56 gs_opts = sprintf ("%s -r%dx%d", gs_opts, [1, 1] * opts.resolution); | 62 gs_opts = sprintf ("%s -r%dx%d", gs_opts, [1, 1] * opts.resolution); |
57 elseif (any (strcmp (opts.device, {"pswrite", "ps2write", "pdfwrite"}))) | 63 elseif (any (strcmp (opts.device, {"pswrite", "ps2write", "pdfwrite"}))) |
58 gs_opts = sprintf ("%s -dEmbedAllFonts=true", gs_opts); | 64 gs_opts = sprintf ("%s -dEmbedAllFonts=true", gs_opts); |
78 else | 84 else |
79 error ("print:badpapersize", "__ghostscript__.m: invalid 'papersize'") | 85 error ("print:badpapersize", "__ghostscript__.m: invalid 'papersize'") |
80 endif | 86 endif |
81 gs_opts = sprintf ("%s -dFIXEDMEDIA", gs_opts); | 87 gs_opts = sprintf ("%s -dFIXEDMEDIA", gs_opts); |
82 offsetfile = strcat (tmpnam (), ".ps"); | 88 offsetfile = strcat (tmpnam (), ".ps"); |
83 fid = fopen (offsetfile, "w"); | 89 unwind_protect |
84 if (fid == -1) | 90 fid = fopen (offsetfile, "w"); |
85 error ("print:fopenfailed", "__ghostscript__.m: fopen() failed."); | 91 onCleanup (@() unlink (offsetfile)); |
86 endif | 92 if (fid == -1) |
87 fprintf (fid, "%s\n", "%!PS-Adobe-3.0") | 93 error ("print:fopenfailed", "__ghostscript__.m: fopen() failed."); |
88 fprintf (fid, "%s [%d %d] %s\n", "<< /Margins [0 0] /.HWMargins [0 0 0 0] /PageOffset", | 94 endif |
89 opts.pageoffset, ">> setpagedevice"); | 95 fprintf (fid, "%s\n", "%!PS-Adobe-3.0") |
90 fprintf (fid, "%%EOF"); | 96 ## "pageoffset" is relative to the coordinates, not the BBox LLHC. |
91 status = fclose (fid); | 97 fprintf (fid, "%s [%d %d] %s\n", "<< /Margins [0 0] /.HWMargins [0 0 0 0] /PageOffset", |
92 if (status == -1) | 98 opts.pageoffset, ">> setpagedevice"); |
93 error ("print:fclosefailed", "__ghostscript__.m: fclose() failed."); | 99 fprintf (fid, "%%EOF"); |
94 endif | 100 unwind_protect_cleanup |
101 status = fclose (fid); | |
102 if (status == -1) | |
103 error ("print:fclosefailed", "__ghostscript__.m: fclose() failed."); | |
104 endif | |
105 end_unwind_protect | |
95 if (opts.debug) | 106 if (opts.debug) |
96 [~,output] = system (sprintf ("cat %s", offsetfile)); | 107 [~,output] = system (sprintf ("cat %s", offsetfile)); |
97 fprintf ("---- begin %s ----\n", offsetfile) | 108 fprintf ("---- begin %s ----\n", offsetfile) |
98 disp (output) | 109 disp (output) |
99 fprintf ("----- end %s -----\n", offsetfile) | 110 fprintf ("----- end %s -----\n", offsetfile) |
110 | 121 |
111 [status, output] = system (cmd); | 122 [status, output] = system (cmd); |
112 | 123 |
113 if (status != 0) | 124 if (status != 0) |
114 warning ("print:ghostscripterror", | 125 warning ("print:ghostscripterror", |
115 "print.m: ghostscript failed to convert output to file '%s'.", opts.output) | 126 "print.m: %s, '%s'.", output, opts.output) |
116 endif | 127 endif |
117 | 128 |
118 endfunction | 129 endfunction |
119 | 130 |
120 | 131 |