comparison scripts/plot/__print_parse_opts__.m @ 10854:d5a7db05d591

Add PS and PDF output for the fltk backend.
author Ben Abbott <bpabbott@mac.com>
date Wed, 04 Aug 2010 20:32:49 -0400
parents 05ba991794d4
children 2f70e7098cbe
comparison
equal deleted inserted replaced
10853:c3813056f94f 10854:d5a7db05d591
24 ## loop until the return key is pressed. 24 ## loop until the return key is pressed.
25 ## @end deftypefn 25 ## @end deftypefn
26 26
27 function arg_st = __print_parse_opts__ (varargin) 27 function arg_st = __print_parse_opts__ (varargin)
28 28
29 ## FIXME - change to numeric values: `canvas_size', `resolution', `fontsize'
30 arg_st.append_to_file = false; 29 arg_st.append_to_file = false;
31 arg_st.canvas_size = ""; 30 arg_st.canvas_size = [];
32 arg_st.debug = false; 31 arg_st.debug = false;
33 arg_st.debug_file = "octave-print-commands.log"; 32 arg_st.debug_file = "octave-print-commands.log";
34 arg_st.devopt = ""; 33 arg_st.devopt = "";
35 arg_st.figure = get (0, "currentfigure"); 34 arg_st.figure = get (0, "currentfigure");
36 arg_st.fig2dev_binary = __find_binary__ ("fig2dev"); 35 arg_st.fig2dev_binary = __find_binary__ ("fig2dev");
37 arg_st.fontsize = ""; 36 arg_st.fontsize = "";
38 arg_st.font = ""; 37 arg_st.font = "";
39 arg_st.force_solid = 0; # 0=default, -1=dashed, +1=solid 38 arg_st.force_solid = 0; # 0=default, -1=dashed, +1=solid
40 arg_st.ghostscript_binary = __ghostscript_binary__ (); 39 arg_st.ghostscript.binary = __ghostscript_binary__ ();
41 arg_st.ghostscript_device = ""; # gs converts eps/ps to this format/printer-language 40 arg_st.ghostscript.device = "";
42 arg_st.ghostscript_output = ""; # gs converts arg_st.name to arg_st.ghostscript_output 41 arg_st.ghostscript.output = "";
42 arg_st.ghostscript.papersize = "";
43 arg_st.ghostscript.pageoffset = [];
44 arg_st.ghostscript.debug = false;
45 arg_st.ghostscript.epscrop = false;
46 arg_st.ghostscript.resolution = 150;
47 arg_st.orientation = "";
43 arg_st.pstoedit_binary = __find_binary__ ("pstoedit"); 48 arg_st.pstoedit_binary = __find_binary__ ("pstoedit");
44 arg_st.name = ""; # This is the file produced by the backend 49 arg_st.name = "";
45 arg_st.orientation = "";
46 arg_st.printer = ""; 50 arg_st.printer = "";
47 arg_st.resolution = num2str (get (0, "screenpixelsperinch"));
48 arg_st.special_flag = "textnormal"; 51 arg_st.special_flag = "textnormal";
49 arg_st.tight_flag = false; 52 arg_st.tight_flag = false;
50 arg_st.use_color = 0; # 0=default, -1=mono, +1=color 53 arg_st.use_color = 0; # 0=default, -1=mono, +1=color
51 arg_st.send_to_printer = false; 54 arg_st.send_to_printer = false;
52 55
71 arg_st.use_color = -1; 74 arg_st.use_color = -1;
72 elseif (strcmp (arg, "-solid")) 75 elseif (strcmp (arg, "-solid"))
73 arg_st.force_solid = 1; 76 arg_st.force_solid = 1;
74 elseif (strcmp (arg, "-dashed")) 77 elseif (strcmp (arg, "-dashed"))
75 arg_st.force_solid = -1; 78 arg_st.force_solid = -1;
76 elseif (strcmp (arg, "-portrait")) 79 elseif (strncmp (arg, "-portrait", numel (arg)))
77 arg_st.orientation = "portrait"; 80 arg_st.orientation = "portrait";
78 elseif (strcmp (arg, "-landscape")) 81 elseif (strncmp (arg, "-landscape", numel (arg)))
79 arg_st.orientation = "landscape"; 82 arg_st.orientation = "landscape";
80 elseif (strcmp (arg, "-tight")) 83 elseif (strcmp (arg, "-tight"))
81 arg_st.tight_flag = true; 84 arg_st.tight_flag = true;
82 elseif (strcmp (arg, "-textspecial")) 85 elseif (strcmp (arg, "-textspecial"))
83 arg_st.special_flag = "textspecial"; 86 arg_st.special_flag = "textspecial";
84 elseif (strncmp (arg, "-debug", 6)) 87 elseif (strncmp (arg, "-debug", 6))
85 arg_st.debug = true; 88 arg_st.debug = true;
89 arg_st.ghostscript.debug = true;
86 if (length (arg) > 7) 90 if (length (arg) > 7)
87 arg_st.debug_file = arg(8:end); 91 arg_st.debug_file = arg(8:end);
88 endif 92 endif
89 elseif (length (arg) > 2 && arg(1:2) == "-d") 93 elseif (length (arg) > 2 && arg(1:2) == "-d")
90 arg_st.devopt = tolower (arg(3:end)); 94 arg_st.devopt = tolower (arg(3:end));
91 elseif (length (arg) > 2 && arg(1:2) == "-P") 95 elseif (length (arg) > 2 && arg(1:2) == "-P")
92 arg_st.printer = arg; 96 arg_st.printer = arg;
93 elseif ((length (arg) > 2) && arg(1:2) == "-G") 97 elseif ((length (arg) > 2) && arg(1:2) == "-G")
94 arg_st.ghostscript_binary = arg(3:end); 98 arg_st.ghostscript.binary = arg(3:end);
95 if (exist (arg_st.ghostscript_binary, "file") != 2) 99 if (exist (arg_st.ghostscript.binary, "file") != 2)
96 arg_st.ghostscript_binary = file_in_path (EXEC_PATH, arg_st.ghostscript_binary); 100 arg_st.ghostscript.binary = file_in_path (EXEC_PATH, arg_st.ghostscript.binary);
97 endif 101 endif
98 if (isempty (arg_st.ghostscript_binary)) 102 if (isempty (arg_st.ghostscript.binary))
99 error ("print: Ghostscript binary ""%s"" could not be located", arg(3:end)) 103 error ("print: Ghostscript binary ""%s"" could not be located", arg(3:end))
100 endif 104 endif
101 elseif (length (arg) > 2 && arg(1:2) == "-F") 105 elseif (length (arg) > 2 && arg(1:2) == "-F")
102 idx = rindex (arg, ":"); 106 idx = rindex (arg, ":");
103 if (idx) 107 if (idx)
104 arg_st.font = arg(3:idx-1); 108 arg_st.font = arg(3:idx-1);
105 arg_st.fontsize = arg(idx+1:length(arg)); 109 arg_st.fontsize = str2num (arg(idx+1:end));
106 else 110 else
107 arg_st.font = arg(3:length(arg)); 111 arg_st.font = arg(3:end);
108 endif 112 endif
109 elseif (length (arg) > 2 && arg(1:2) == "-S") 113 elseif (length (arg) > 2 && arg(1:2) == "-S")
110 arg_st.canvas_size = arg(3:length(arg)); 114 arg_st.canvas_size = str2num (arg(3:end));
111 elseif (length (arg) > 2 && arg(1:2) == "-r") 115 elseif (length (arg) > 2 && arg(1:2) == "-r")
112 arg_st.resolution = arg(3:length(arg)); 116 arg_st.ghostscript.resolution = arg(3:end);
113 elseif (length (arg) > 2 && arg(1:2) == "-f") 117 elseif (length (arg) > 2 && arg(1:2) == "-f")
114 arg_st.figure = str2num (arg(3:end)); 118 arg_st.figure = str2num (arg(3:end));
115 elseif (length (arg) >= 1 && arg(1) == "-") 119 elseif (length (arg) >= 1 && arg(1) == "-")
116 error ("print: unknown option `%s'", arg); 120 error ("print: unknown option `%s'", arg);
117 elseif (length (arg) > 0) 121 elseif (length (arg) > 0)
122 else 126 else
123 error ("print: expecting inputs to be character string options or a figure handle"); 127 error ("print: expecting inputs to be character string options or a figure handle");
124 endif 128 endif
125 endfor 129 endfor
126 130
131 if (arg_st.ghostscript.resolution == 0)
132 ## Do as Matlab does.
133 arg_st.ghostscript.resolution = num2str (get (0, "screenpixelsperinch"));
134 endif
135
127 if (isempty (arg_st.orientation)) 136 if (isempty (arg_st.orientation))
128 if (isfigure (arg_st.figure)) 137 if (isfigure (arg_st.figure))
129 arg_st.orientation = get (arg_st.figure, "paperorientation"); 138 arg_st.orientation = get (arg_st.figure, "paperorientation");
130 else 139 else
131 ## Allows tests to be run without error. 140 ## Allows tests to be run without error.
132 arg_st.orientation = get (0, "defaultfigurepaperorientation"); 141 arg_st.orientation = get (0, "portrait");
133 endif 142 endif
134 endif 143 endif
135 144
136 if (isempty (arg_st.ghostscript_binary)) 145 if (isempty (arg_st.ghostscript.binary))
137 arg_st.ghostscript_binary = __ghostscript_binary__ (); 146 arg_st.ghostscript.binary = __ghostscript_binary__ ();
138 endif 147 endif
139 148
140 dot = rindex (arg_st.name, "."); 149 dot = rindex (arg_st.name, ".");
141 if (isempty (arg_st.devopt)) 150 if (isempty (arg_st.devopt))
142 if (dot == 0) 151 if (dot == 0)
144 else 153 else
145 arg_st.devopt = tolower (arg_st.name(dot+1:end)); 154 arg_st.devopt = tolower (arg_st.name(dot+1:end));
146 endif 155 endif
147 endif 156 endif
148 157
149 if (any (strcmp ({"ps", "ps2", "eps", "eps2"}, arg_st.devopt)) 158 if ((any (strcmp ({"ps", "ps2", "eps", "eps2"}, arg_st.devopt))
150 || (! isempty (strfind (arg_st.devopt, "tex")) && arg_st.use_color == 0)) 159 || (! isempty (strfind (arg_st.devopt, "tex")))) && arg_st.use_color == 0)
151 ## Mono is the default for ps, eps, and the tex/latex, devices 160 ## Mono is the default for ps, eps, and the tex/latex, devices
152 arg_st.use_color = -1; 161 arg_st.use_color = -1;
153 elseif (arg_st.use_color == 0) 162 elseif (arg_st.use_color == 0)
154 arg_st.use_color = 1; 163 arg_st.use_color = 1;
155 endif 164 endif
156 165
157 if (arg_st.append_to_file) 166 if (arg_st.append_to_file)
158 if (any (strcmpi (arg_st.devopt, {"ps", "ps2", "psc", "psc2", "pdf"}))) 167 if (isempty (arg_st.name))
168 arg_st.append_to_file = false;
169 elseif (any (strcmpi (arg_st.devopt, {"eps", "eps2", "epsc", "epsc2", ...
170 "ps", "ps2", "psc", "psc2", "pdf"})))
159 have_ghostscript = ! isempty (__ghostscript_binary__ ()); 171 have_ghostscript = ! isempty (__ghostscript_binary__ ());
160 if (have_ghostscript) 172 if (have_ghostscript)
161 file_exists = ((numel (dir (arg_st.name)) == 1) && (! isdir (arg_st.name))); 173 file_exists = ((numel (dir (arg_st.name)) == 1) && (! isdir (arg_st.name)));
162 if (! file_exists) 174 if (! file_exists)
163 arg_st.append_to_file = false; 175 arg_st.append_to_file = false;
164 end 176 end
165 end 177 else
178 arg_st.append_to_file = false;
179 warning ("print.m: appended output requires ghostscript to be installed.")
180 endif
166 else 181 else
167 warning ("print.m: appended output is not supported for device '%s'", arg_st.devopt) 182 warning ("print.m: appended output is not supported for device '%s'", arg_st.devopt)
168 arg_st.append_to_file = false; 183 arg_st.append_to_file = false;
169 endif 184 endif
170 endif 185 endif
187 elseif (strcmp (arg_st.devopt, "jpg")) 202 elseif (strcmp (arg_st.devopt, "jpg"))
188 arg_st.devopt = "jpeg"; 203 arg_st.devopt = "jpeg";
189 endif 204 endif
190 205
191 dev_list = {"aifm", "corel", "fig", "png", "jpeg", ... 206 dev_list = {"aifm", "corel", "fig", "png", "jpeg", ...
192 "gif", "pbm", "dxf", "mf", "svg", "hpgl", ... 207 "gif", "pbm", "pbmraw", "dxf", "mf", ...
193 "ps", "ps2", "psc", "psc2", "eps", "eps2", ... 208 "svg", "hpgl", "ps", "ps2", "psc", ...
194 "epsc", "epsc2", "emf", "pdf", "pslatex", ... 209 "psc2", "eps", "eps2", "epsc", "epsc2", ...
195 "epslatex", "epslatexstandalone", "pstex", "tikz"}; 210 "emf", "pdf", "pslatex", "epslatex", "epslatexstandalone", ...
211 "pstex", "tiff", "tiffn" "tikz", "pcxmono", ...
212 "pcx24b", "pcx256", "pcx16", "pgm", "pgmraw", ...
213 "ppm", "ppmraw"};
196 214
197 suffixes = {"ai", "cdr", "fig", "png", "jpg", ... 215 suffixes = {"ai", "cdr", "fig", "png", "jpg", ...
198 "gif", "pbm", "dxf", "mf", "svg", "hpgl", ... 216 "gif", "pbm", "pbm", "dxf", "mf", ...
199 "ps", "ps", "ps", "ps", "eps", "eps", ... 217 "svg", "hpgl", "ps", "ps", "ps", ...
200 "eps", "eps", "emf", "pdf", "tex", ... 218 "ps", "eps", "eps", "eps", "eps", ...
201 "tex", "tex", "tex", "tikz"}; 219 "emf", "pdf", "tex", "tex", "tex", ...
220 "tex", "tiff", "tiff", "tikz", "pcx", ...
221 "pcx", "pcx", "pcx", "pgm", "pgm", ...
222 "ppm", "ppm"};
202 223
203 match = strcmpi (dev_list, arg_st.devopt); 224 match = strcmpi (dev_list, arg_st.devopt);
204 if (any (match)) 225 if (any (match))
205 default_suffix = suffixes {match}; 226 default_suffix = suffixes {match};
206 else 227 else
218 arg_st.unlink{end+1} = arg_st.name; 239 arg_st.unlink{end+1} = arg_st.name;
219 endif 240 endif
220 endif 241 endif
221 242
222 if (all (! strcmp (arg_st.devopt, dev_list))) 243 if (all (! strcmp (arg_st.devopt, dev_list)))
223 arg_st.ghostscript_device = arg_st.devopt; 244 arg_st.ghostscript.device = arg_st.devopt;
224 arg_st.ghostscript_output = arg_st.name; 245 arg_st.ghostscript.output = arg_st.name;
225 ## FIXME - This will not work correctly if GS is used to produce a print 246 endif
226 ## stream that is saved to a file and not sent to the printer. 247
227 if (arg_st.send_to_printer) 248 if (isempty (arg_st.canvas_size))
228 arg_st.devopt = "psc"; 249 if (isfigure (arg_st.figure))
229 arg_st.name = strcat (tmpnam (), ".ps"); 250 [arg_st.ghostscript.papersize, paperposition] = gs_papersize (arg_st.figure,
230 arg_st.unlink{end+1} = arg_st.name; 251 arg_st.orientation);
231 else 252 else
232 ## Assume the user desires only the figuure. This is useful for producing 253 ## allows tests to be run
233 ## pdf figures for pdflatex 254 arg_st.ghostscript.papersize = "letter";
234 ## octave:#> print -f1 -dpdfwrite figure1.pdf 255 paperposition = [0.25, 2.50, 8.00, 6.00] * 72;
235 arg_st.devopt = "epsc"; 256 endif
236 arg_st.name = strcat (tmpnam (), ".eps"); 257 arg_st.canvas_size = paperposition(3:4);
237 arg_st.unlink{end+1} = arg_st.name; 258 arg_st.ghostscript.pageoffset = paperposition(1:2);
238 endif
239 endif
240
241 if (any (strncmp (arg_st.devopt(1:2), {"ps", "pdf"}, 2)))
242 arg_st.paperoutput = true;
243 else 259 else
244 arg_st.paperoutput = false; 260 ## Canvas size in points.
245 endif 261 arg_st.canvas_size = arg_st.canvas_size * 72 / arg_st.ghostscript.resolution;
246 262 arg_st.ghostscript.papersize = arg_st.canvas_size;
247 if (arg_st.debug) 263 arg_st.ghostscript.epscrop = true;
248 disp ("Printing options"); 264 arg_st.ghostscript.pageoffset = [0, 0];
249 disp (arg_st) 265 endif
250 endif 266
251 endfunction 267 endfunction
252 268
253 %!test 269 %!test
254 %! opts = __print_parse_opts__ (); 270 %! opts = __print_parse_opts__ ();
255 %! assert (opts.devopt, "psc"); 271 %! assert (opts.devopt, "psc");
256 %! assert (opts.use_color, 1); 272 %! assert (opts.use_color, 1);
257 %! assert (opts.send_to_printer, true); 273 %! assert (opts.send_to_printer, true);
258 %! assert (opts.paperoutput, true);
259 %! assert (opts.name, opts.unlink{1}) 274 %! assert (opts.name, opts.unlink{1})
275 %! assert (opts.canvas_size, [576, 432]);
276 %! assert (opts.ghostscript.device, "")
260 %! for n = 1:numel(opts.unlink) 277 %! for n = 1:numel(opts.unlink)
261 %! unlink (opts.unlink{n}); 278 %! unlink (opts.unlink{n});
262 %! endfor 279 %! endfor
280
281 %!test
282 %! opts = __print_parse_opts__ ("test.pdf", "-SX640,Y480");
283 %! assert (opts.canvas_size, [307.2, 230.4], 0.1);
263 284
264 %!test 285 %!test
265 %! opts = __print_parse_opts__ ("-dpsc", "-append"); 286 %! opts = __print_parse_opts__ ("-dpsc", "-append");
266 %! assert (opts.devopt, "psc"); 287 %! assert (opts.devopt, "psc");
267 %! assert (opts.name(end+(-2:0)), ".ps"); 288 %! assert (opts.name(end+(-2:0)), ".ps");
268 %! assert (opts.send_to_printer, true); 289 %! assert (opts.send_to_printer, true);
269 %! assert (opts.use_color, 1); 290 %! assert (opts.use_color, 1);
270 %! assert (opts.append_to_file, false); 291 %! assert (opts.append_to_file, false);
271 %! assert (opts.paperoutput, true); 292 %! assert (opts.ghostscript.device, "")
272 %! for n = 1:numel(opts.unlink) 293 %! for n = 1:numel(opts.unlink)
273 %! unlink (opts.unlink{n}); 294 %! unlink (opts.unlink{n});
274 %! endfor 295 %! endfor
275 296
276 %!test 297 %!test
277 %! opts = __print_parse_opts__ ("-deps", "-tight"); 298 %! opts = __print_parse_opts__ ("-deps", "-tight");
278 %! assert (opts.name, opts.unlink{1}) 299 %! assert (opts.name, opts.unlink{1})
279 %! assert (opts.tight_flag, true); 300 %! assert (opts.tight_flag, true);
280 %! assert (opts.paperoutput, false)
281 %! assert (opts.send_to_printer, true); 301 %! assert (opts.send_to_printer, true);
282 %! assert (opts.use_color, -1); 302 %! assert (opts.use_color, -1);
303 %! assert (opts.ghostscript.device, "")
283 %! for n = 1:numel(opts.unlink) 304 %! for n = 1:numel(opts.unlink)
284 %! unlink (opts.unlink{n}); 305 %! unlink (opts.unlink{n});
285 %! endfor 306 %! endfor
286 307
287 %!test 308 %!test
288 %! opts = __print_parse_opts__ ("-djpg", "foobar", "-mono"); 309 %! opts = __print_parse_opts__ ("-djpg", "foobar", "-mono");
289 %! assert (opts.devopt, "jpeg") 310 %! assert (opts.devopt, "jpeg")
290 %! assert (opts.name, "foobar.jpg") 311 %! assert (opts.name, "foobar.jpg")
291 %! assert (opts.ghostscript_device, "") 312 %! assert (opts.ghostscript.device, "")
292 %! assert (opts.send_to_printer, false); 313 %! assert (opts.send_to_printer, false);
293 %! assert (opts.printer, ""); 314 %! assert (opts.printer, "");
294 %! assert (opts.paperoutput, false)
295 %! assert (opts.use_color, -1); 315 %! assert (opts.use_color, -1);
316 %! assert (opts.ghostscript.device, "")
296 317
297 %!test 318 %!test
298 %! opts = __print_parse_opts__ ("-ddeskjet", "foobar", "-mono", "-Pmyprinter"); 319 %! opts = __print_parse_opts__ ("-ddeskjet", "foobar", "-mono", "-Pmyprinter");
299 %! assert (opts.ghostscript_output, "foobar.deskjet") 320 %! assert (opts.ghostscript.output, "foobar.deskjet")
300 %! assert (opts.ghostscript_device, "deskjet") 321 %! assert (opts.ghostscript.device, "deskjet")
301 %! assert (opts.devopt, "psc") 322 %! assert (opts.devopt, "deskjet")
302 %! assert (opts.send_to_printer, true); 323 %! assert (opts.send_to_printer, true);
303 %! assert (opts.printer, "-Pmyprinter"); 324 %! assert (opts.printer, "-Pmyprinter");
304 %! assert (opts.paperoutput, true)
305 %! assert (opts.use_color, -1); 325 %! assert (opts.use_color, -1);
306 326
307 %!test 327 %!test
308 %! opts = __print_parse_opts__ ("-f5", "-dljet3"); 328 %! opts = __print_parse_opts__ ("-f5", "-dljet3");
309 %! assert (opts.name, opts.unlink{2}) 329 %! assert (opts.name, opts.unlink{1})
310 %! assert (opts.ghostscript_output, opts.unlink{1}) 330 %! assert (opts.ghostscript.output, opts.unlink{1})
311 %! assert (strfind (opts.ghostscript_output, ".ljet3")) 331 %! assert (opts.ghostscript.device, "ljet3")
312 %! assert (strfind (opts.name, ".ps")) 332 %! assert (strfind (opts.ghostscript.output, ".ljet3"))
313 %! assert (opts.devopt, "psc") 333 %! assert (opts.devopt, "ljet3")
314 %! assert (opts.send_to_printer, true); 334 %! assert (opts.send_to_printer, true);
315 %! assert (opts.paperoutput, true)
316 %! assert (opts.figure, 5) 335 %! assert (opts.figure, 5)
317 %! for n = 1:numel(opts.unlink) 336 %! for n = 1:numel(opts.unlink)
318 %! unlink (opts.unlink{n}); 337 %! unlink (opts.unlink{n});
319 %! endfor 338 %! endfor
320 339
391 410
392 bin = data.(binary).bin; 411 bin = data.(binary).bin;
393 412
394 endfunction 413 endfunction
395 414
396 415 function [papersize, paperposition] = gs_papersize (hfig, paperorientation)
416 persistent papertypes papersizes
417
418 if (isempty (papertypes))
419 papertypes = {"usletter", "uslegal", "a0", "a1", ...
420 "a2", "a3", "a4", "a5", ...
421 "b0", "b1", "b2", "b3", ...
422 "b4", "b5", "arch-a", "arch-b", ...
423 "arch-c", "arch-d", "arch-e", "a", ...
424 "b", "c", "d", "e", ...
425 "tabloid"};
426 papersizes = [ 8.5, 11.0; 8.5, 14.0; 33.1, 46.8; 23.4, 33.1;
427 16.5, 23.4; 11.7, 16.5; 8.3, 11.7; 5.8, 8.3;
428 39.4, 55.7; 27.8, 39.4; 19.7, 27.8; 13.9, 19.7;
429 9.8, 13.9; 6.9, 9.8; 9.0, 12.0; 12.0, 18.0;
430 18.0, 24.0; 24.0, 36.0; 36.0, 48.0; 8.5, 11.0;
431 11.0, 17.0; 18.0, 24.0; 24.0, 36.0; 36.0, 48.0;
432 11.0, 17.0] * 72;
433 endif
434
435 papertype = get (hfig, "papertype");
436 paperunits = get (hfig, "paperunits");
437 paperposition = get (hfig, "paperposition");
438 if (strcmp (papertype, "<custom>"))
439 papersize = get (hfig, "papersize");
440 papersize = convert2points (papersize , paperunits);
441 else
442 papersize = papersizes (strcmp (papertypes, papertype), :);
443 endif
444
445 if (strcmp (paperunits, "normalized"))
446 paperposition = paperposition .* papersize([1,2,1,2]);
447 else
448 paperposition = convert2points (paperposition, paperunits);
449 endif
450
451 ## FIXME - This will be obsoleted by listeners for paper properties.
452 ## Papersize is tall when portrait,and wide when landscape.
453 if ((papersize(1) > papersize(2) && strcmpi (paperorientation, "portrait"))
454 || (papersize(1) < papersize(2) && strcmpi (paperorientation, "landscape")))
455 papersize = papersize ([2,1]);
456 paperposition = paperposition([2,1,4,3]);
457 endif
458
459 if ((! strcmp (papertype, "<custom>")) && (strcmp (paperorientation, "portrait")))
460 ## For portrait use the ghostscript name
461 papersize = papertype;
462 papersize(papersize=="-") = "";
463 papersize = strrep (papersize, "us", "");
464 switch papersize
465 case "a"
466 papersize = "letter";
467 case {"b", "tabloid"}
468 papersize = "11x17";
469 case {"c", "d", "e"}
470 papersize = strcat ("arch", papersize);
471 endswitch
472 if (strncmp (papersize, "arch", 4))
473 papersize(end) = upper (papersize(end));
474 endif
475 endif
476
477 endfunction
478
479 function value = convert2points (value, units)
480 switch units
481 case {"inches"}
482 value = value * 72;
483 case {"centimeters"}
484 value = value * 72 / 25.4;
485 case {"normalized"}
486 error ("print:customnormalized",
487 "print.m: papersize=='<custom>' and paperunits='normalized' may not be combined.")
488 endswitch
489 endfunction
490