changeset 5362:ef053d682e42

[project @ 2005-05-23 19:21:54 by jwe]
author jwe
date Mon, 23 May 2005 19:21:54 +0000
parents 0ac38aea9f76
children 37f62a7778c2
files scripts/plot/print.m
diffstat 1 files changed, 78 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/print.m	Mon May 23 19:08:36 2005 +0000
+++ b/scripts/plot/print.m	Mon May 23 19:21:54 2005 +0000
@@ -1,16 +1,22 @@
+## Copyright (C) 1999 Daniel Heiserer
 ## Copyright (C) 2001 Laurent Mazet
 ##
-## This program is free software; it is distributed in the hope that it
-## will be useful, but WITHOUT ANY WARRANTY; without even the implied
-## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-## the GNU General Public License for more details.
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
 ## You should have received a copy of the GNU General Public License
-## along with this file; see the file COPYING.  If not, write to the
-## Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-## 02111-1307, USA.
-##
-## Copyright (C) 1999 Daniel Heiserer
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} print (@var{filename}, @var{options})
@@ -84,51 +90,18 @@
 ## @end table
 ##
 ## The filename and options can be given in any order.
-##
-## If you are using Octave 2.1.x or above, command("print") will change 
-## print from a function to a command, so instead of typing
-##    print("-FTimes-Roman:14", "-dashed", "-depsc", "out.ps")
-## you can type
-##    print -FTimes-Roman:14 -dashed -depsc out.ps
-##
-## See also: orient, command
 ## @end deftypefn
 
 ## Author: Daniel Heiserer <Daniel.heiserer@physik.tu-muenchen.de>
-## 2001-03-23  Laurent Mazet <mazet@crm.mot.com>
-##     * simplified interface: guess the device from the extension
-##     * font support
-## 2001-03-25  Paul Kienzle <pkienzle@kienzle.powernet.co.uk>
-##     * add unwind_protect
-##     * use tmpnam to generate temporary name
-##     * move "set term" before "set output" as required by gnuplot
-##     * more options, and flexible options
-## 2001-03-29  Laurent Mazet <mazet@crm.mot.com>
-##     * add solid and dashed options
-##     * change PBMplus device
-##     * add Corel device
-##     * take care of the default terminal settings to restore them.
-##     * add color, mono, dashed and solid support for printing and convert.
-##     * add orientation for printing.
-##     * create a .ps for printing (avoid some filtering problems).
-##     * default printing is mono, default convert is color.
-##     * add font size support.
-## 2001-03-30  Laurent Mazet <mazet@crm.mot.com>
-##     * correct correl into corel
-##     * delete a irrelevant test
-##     * check for convert before choosing the ouput device
-## 2001-03-31  Paul Kienzle <pkienzle@kienzle.powernet.co.uk>
-##     * use -Ffontname:size instead of -F"fontname size"
-##     * add font size support to fig option
-##     * update documentation
-## 2003-10-01  Laurent Mazet <mazet@crm.mot.com>
-##     * clean documentation
+## Adapted-By: jwe
 
-function print(varargin)
+## PKG_ADD: mark_as_command print
+
+function print (varargin)
 
   ## take care of the settings we had before
-  origterm = gget("terminal");
-  origout = gget("output");
+  origterm = gget ("terminal");
+  origout = gget ("output");
   ## End of line trmination for __gnuplot_raw__ command strings.
   endl = ";\n";
   _automatic_replot = automatic_replot;
@@ -143,26 +116,26 @@
   
   va_arg_cnt = 1;
 
-  for i=1:nargin
+  for i = 1:nargin
     arg = nth (varargin, va_arg_cnt++);
-    if isstr(arg)
-      if strcmp(arg, "-color")
+    if (isstr (arg))
+      if (strcmp (arg, "-color"))
 	use_color = 1;
-      elseif strcmp(arg, "-mono")
+      elseif (strcmp (arg, "-mono"))
 	use_color = -1;
-      elseif strcmp(arg, "-solid")
+      elseif (strcmp (arg, "-solid"))
         force_solid = 1;
-      elseif strcmp(arg, "-dashed")
+      elseif (strcmp (arg, "-dashed"))
         force_solid = -1;
-      elseif strcmp(arg, "-portrait")
+      elseif (strcmp (arg, "-portrait"))
 	orientation = "portrait";
-      elseif strcmp(arg, "-landscape")
+      elseif (strcmp (arg, "-landscape"))
 	orientation = "landscape";
-      elseif length(arg) > 2 && arg(1:2) == "-d"
+      elseif (length (arg) > 2 && arg(1:2) == "-d")
 	devopt = arg(3:length(arg));
-      elseif length(arg) > 2 && arg(1:2) == "-P"
+      elseif (length (arg) > 2 && arg(1:2) == "-P")
 	printer = arg;
-      elseif length(arg) > 2 && arg(1:2) == "-F"
+      elseif (length (arg) > 2 && arg(1:2) == "-F")
 	idx = rindex(arg, ":");
 	if (idx)
 	  font = arg(3:idx-1);
@@ -170,19 +143,19 @@
 	else
 	  font = arg(3:length(arg));
 	endif
-      elseif length(arg) >= 1 && arg(1) == "-"
-	error([ "print: unknown option ", arg ]);
-      elseif length(arg) > 0
+      elseif (length (arg) >= 1 && arg(1) == "-")
+	error ("print: unknown option `%s'", arg);
+      elseif (length (arg) > 0)
 	name = arg;
       endif
     else
-      error("print: expects string options");
+      error ("print: expects string options");
     endif
   endfor
 
-  doprint = isempty(name);
-  if doprint
-    if isempty(devopt)
+  doprint = isempty (name);
+  if (doprint)
+    if (isempty (devopt))
       printname = [ tmpnam, ".ps" ]; 
     else
       printname = [ tmpnam, ".", devopt ];
@@ -190,20 +163,20 @@
     name = printname;
   endif
 
-  if isempty(devopt)
-    dot = rindex(name, ".");
+  if (isempty (devopt))
+    dot = rindex (name, ".");
     if (dot == 0) 
       error ("print: no format specified");
     else
-      dev = tolower(name(dot+1:length(name)));
+      dev = tolower (name(dot+1:end));
     endif
   else
     dev = devopt;
   endif
 
-  if strcmp(dev, "ill")
+  if (strcmp (dev, "ill"))
     dev = "aifm";
-  elseif strcmp(dev, "cdr")
+  elseif (strcmp (dev, "cdr"))
     dev = "corel";
   endif
 
@@ -211,8 +184,8 @@
   dev_list = [" aifm corel fig png pbm dxf mf hpgl", ...
 	      " ps ps2 psc psc2 eps eps2 epsc epsc2 " ];
   convertname = "";
-  if isempty(findstr(dev_list , [ " ", dev, " " ]))
-    if !isempty(devopt)
+  if (isempty (findstr (dev_list , [ " ", dev, " " ]))
+    if (! isempty (devopt))
       convertname = [ devopt ":" name ];
     else
       convertname = name;
@@ -224,47 +197,47 @@
   unwind_protect
     automatic_replot = 0;
 
-    if strcmp(dev, "ps") || strcmp(dev, "ps2") ...
-	  || strcmp(dev, "psc")  || strcmp(dev, "psc2") ...
-	  || strcmp(dev, "epsc") || strcmp(dev, "epsc2") ... 
-	  || strcmp(dev, "eps")  || strcmp(dev, "eps2")
+    if (strcmp (dev, "ps") || strcmp (dev, "ps2") ...
+	|| strcmp (dev, "psc")  || strcmp (dev, "psc2")
+	|| strcmp (dev, "epsc") || strcmp (dev, "epsc2")
+	|| strcmp (dev, "eps")  || strcmp (dev, "eps2"))
       ## Various postscript options
-      ## FIXME: Do we need this? DAS
+      ## XXX FIXME XXX -- Do we need this? DAS
       ##__gnuplot_set__ term postscript
       terminal_default = gget ("terminal");
       
-      if dev(1) == "e"
+      if (dev(1) == "e")
 	options = "eps ";
       else
 	options = [ orientation, " " ];
       endif
       options = [ options, "enhanced " ];
       
-      if any( dev == "c" ) || use_color > 0
-        if force_solid < 0
+      if (any (dev == "c") || use_color > 0)
+        if (force_solid < 0)
 	  options = [ options, "color dashed " ];
 	else
           options = [ options, "color solid " ];
         endif
       else
-        if force_solid > 0
+        if (force_solid > 0)
 	  options = [ options, "mono solid " ];
 	else
 	  options = [ options, "mono dashed " ];
         endif
       endif
 
-      if !isempty(font)
+      if (! isempty (font))
 	options = [ options, "\"", font, "\" " ];
       endif
-      if !isempty(fontsize)
+      if (! isempty (fontsize))
 	options = [ options, " ", fontsize ];
       endif
 
       __gnuplot_raw__ (["set term postscript ", options, endl]);
 
 
-    elseif strcmp(dev, "aifm") || strcmp(dev, "corel")
+    elseif (strcmp (dev, "aifm") || strcmp (dev, "corel"))
       ## Adobe Illustrator, CorelDraw
       ## FIXME: Do we need it? DAS
       ## eval(sprintf ("__gnuplot_set__ term %s", dev));
@@ -274,16 +247,16 @@
       else
 	options = " mono";
       endif
-      if !isempty(font)
+      if (! isempty (font))
 	options = [ options, " \"" , font, "\"" ];
       endif
-      if !isempty(fontsize)
+      if (! isempty (fontsize))
 	options = [ options, " ", fontsize ];
       endif
 
       __gnuplot_raw__ (["set term ", dev, " ", options, endl]);
 
-    elseif strcmp(dev, "fig")
+    elseif (strcmp (dev, "fig"))
       ## XFig
       ## FIXME: Do we need it? DAS
       ## __gnuplot_set__ term fig
@@ -294,26 +267,24 @@
       else
 	options = " mono";
       endif
-      if !isempty(fontsize)
+      if (! isempty (fontsize))
 	options = [ options, " fontsize ", fontsize ];
       endif
       __gnuplot_raw__ (["set term fig ", options, endl]);
 
-    elseif strcmp(dev, "png") || strcmp(dev, "pbm")
+    elseif (strcmp (dev, "png") || strcmp (dev, "pbm"))
       ## Portable network graphics, PBMplus
       ## FIXME: Do we need it? DAS
       ## eval(sprintf ("__gnuplot_set__ term %s", dev));
       terminal_default = gget ("terminal");
 
-      ## FIXME
-      ## New PNG interface takes color as "xRRGGBB" where x is the literal character
-      ## 'x' and 'RRGGBB' are the red, green and blue components in hex.
-      ## For now we just ignore it and use default. 
-      ## The png terminal now is so rich with options, that one perhaps
-      ## has to write a separate printpng.m function.
+      ## XXX FIXME XXX -- New PNG interface takes color as "xRRGGBB"
+      ## where x is the literal character 'x' and 'RRGGBB' are the red,
+      ## green and blue components in hex.  For now we just ignore it
+      ## and use default.  The png terminal now is so rich with options,
+      ## that one perhaps has to write a separate printpng.m function.
       ## DAS
 
-      ##
       ## if (use_color >= 0)
       ##	eval (sprintf ("__gnuplot_set__ term %s color medium", dev));
       ##else
@@ -322,11 +293,10 @@
       
       __gnuplot_raw__ ("set term png large;\n")
  
-    elseif strcmp(dev,"dxf") || strcmp(dev,"mf") || strcmp(dev, "hpgl")
+    elseif (strcmp (dev, "dxf") || strcmp (dev, "mf") || strcmp (dev, "hpgl"))
       ## AutoCad DXF, METAFONT, HPGL
       __gnuplot_raw__ (["set terminal ", dev, endl]);
-            
-    endif;
+    endif
     
     ## Gnuplot expects " around output file name
 
@@ -336,15 +306,14 @@
   unwind_protect_cleanup
 
     ## Restore init state
-    if ! isempty (terminal_default)
+    if (! isempty (terminal_default))
       __gnuplot_raw__ (["set terminal ", terminal_default, endl]);
     endif
     __gnuplot_raw__ (["set terminal ", origterm, endl]);
-    if isempty (origout)
+    if (isempty (origout))
       __gnuplot_raw__ ("set output;\n")
     else
     ## Gnuplot expects " around output file name
-
       __gnuplot_raw__ (["set output \"", origout, "\"", endl]);
     end
     __gnuplot_replot__
@@ -353,7 +322,7 @@
 
   end_unwind_protect
 
-  if !isempty(convertname)
+  if (! isempty (convertname))
     command = [ "convert '", name, "' '", convertname, "'" ];
     [output, errcode] = system (command);
     unlink (name);
@@ -361,11 +330,12 @@
       error ("print: could not convert");
     endif
   endif
-  ## FIXME: This looks like a dirty, Unix-specific hack
+
+  ## XXX FIXME XXX -- This looks like a dirty, Unix-specific hack.
   ## DAS
-  if doprint
-    system(sprintf ("lpr %s '%s'", printer, printname));
-    unlink(printname);
+  if (doprint)
+    system (sprintf ("lpr %s '%s'", printer, printname));
+    unlink (printname);
   endif
   
 endfunction