changeset 10861:2f70e7098cbe

__print_parse_opts__.m: .
author Ben Abbott <bpabbott@mac.com>
date Thu, 05 Aug 2010 19:53:36 -0400
parents 3a5f5c99cc39
children 337db4e1342d
files scripts/ChangeLog scripts/plot/__fltk_print__.m scripts/plot/__print_parse_opts__.m
diffstat 3 files changed, 72 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,5 +1,8 @@
 2010-08-05  Ben Abbott <bpabbott@mac.com>
 
+	* plot/__print_parse_opts__.m, plot/__fltk_print__.m: Add epslatex,
+	pslatex, and pdflatex output for fltk backend. Use the gs png16m device
+	instead of png256.
 	* plot/print.m: Modify texinfo. Add unwind_protect block.
 
 2010-08-01 Marco Caliari <marco.caliari@univr.it>
--- a/scripts/plot/__fltk_print__.m
+++ b/scripts/plot/__fltk_print__.m
@@ -38,14 +38,35 @@
     if (opts.tight_flag)
       __tight_eps_bbox__ (opts, opts.name);
     endif
-  case {"epslatex", "epslatexstandalone", "pslatex"}
-    # FIXME - format GL2PS_TEX is not implemented
-    drawnow ("epslatex", opts.name);
-    if (opts.tight_flag)
-      __tight_eps_bbox__ (opts, opts.name);
+  case {"epslatex", "pslatex", "pdflatex", "epslatexstandalone", ...
+        "pslatexstandalone", "pdflatexstandalone"}
+    ## format GL2PS_TEX
+    ## FIXME - rotated text do not align properly.
+    n = find (opts.devopt == "l", 1);
+    suffix = opts.devopt(1:n-1);
+    dot = find (opts.name == ".", 1, "last");
+    if ((! isempty (dot))
+        && any (strcmpi (opts.name(dot:end), {".eps", ".ps", ".pdf", ".tex", "."})))
+      name = opts.name(1:dot-1);
+      if (dot < numel (opts.name)
+          && any (strcmpi (opts.name(dot+1:end), {"eps", "ps", "pdf"})))
+        ## If user provides eps/ps/pdf suffix, use it.
+        suffix = opts.name(dot+1:end);
+      endif
+    elseif (dot == numel (opts.name))
+      name = opts.name;
+    endif
+    drawnow (strcat (lower (suffix), "notxt"), strcat (name, ".", suffix));
+    drawnow ("tex", strcat (name, ".", suffix, ".tex"));
+    movefile (strcat (name, ".", suffix, ".tex"), strcat (name, ".tex"));
+    if (opts.tight_flag && strncmpi (opts.devopt, "eps", 3))
+      __tight_eps_bbox__ (opts, strcat (opts.name, ".eps"));
+    endif
+    if (! isempty (strfind (opts.devopt, "standalone")))
+      __standalone__ (strcat (name, ".tex"));
     endif
   case {"tikz"}
-    ## FIXME - format GL2PS_PGF if not implemented
+    ## format GL2PS_PGF
     drawnow ("pgf", opts.name);
   case {"ps", "ps2", "psc", "psc2", "pdf"}
     opts.ghostscript.source = strcat (tmpnam (), ".eps");
@@ -61,14 +82,14 @@
       __tight_eps_bbox__ (opts, opts.ghostscript.source);
     endif
   case {"svg"}
-    ## FIXME - format GL2PS_SVG if not implemented
+    ## format GL2PS_SVG
     drawnow ("svg", opts.name);
   case {"jpeg", "pbm", "pbmraw", "pcx24b", "pcx256", "pcx16", ...
         "pgm", "pgmraw", "png", "ppm", "ppmraw", "pdfwrite", ...
         "tiff", "tiffn"}
     switch opts.devopt
     case "png"
-      opts.ghostscript.device = "png256";
+      opts.ghostscript.device = "png16m";
     case {"tiff", "tiffn"}
       opts.ghostscript.device = "tiff24nc";
     otherwise
@@ -167,4 +188,38 @@
   endif
 endfunction
 
+function __standalone__ (latexfile)
+  prepend = {"\\documentclass{minimal}";
+             "\\usepackage{epsfig,color}";
+             "\\begin{document}";
+             "\\centering"};
+  postpend = {"\\end{document}"};
+  fid = fopen (latexfile, "r");
+  if (fid >= 0)
+    latex = fscanf (fid, "%c", Inf);
+    status = fclose (fid);
+    if (status != 0)
+      error ("print:errorclosingfile",
+             "print.m: error closing file '%s'", latexfile)
+    endif
+  else
+    error ("print:erroropeningfile",
+           "print.m: error opening file '%s'", latexfile)
+  endif
+  fid = fopen (latexfile, "w");
+  if (fid >= 0)
+    fprintf (fid, "%s\n", prepend{:});
+    fprintf (fid, "%s", latex);
+    fprintf (fid, "%s\n", postpend{:});
+    status = fclose (fid);
+    if (status != 0)
+      error ("print:errorclosingfile",
+             "print.m: error closing file '%s'", latexfile)
+    endif
+  else
+    error ("print:erroropeningfile",
+           "print.m: error opening file '%s'", latexfile)
+  endif
+endfunction
 
+
--- a/scripts/plot/__print_parse_opts__.m
+++ b/scripts/plot/__print_parse_opts__.m
@@ -138,7 +138,7 @@
       arg_st.orientation = get (arg_st.figure, "paperorientation");
     else
       ## Allows tests to be run without error.
-      arg_st.orientation = get (0, "portrait");
+      arg_st.orientation = "portrait";
     endif
   endif
 
@@ -208,18 +208,20 @@
               "svg", "hpgl", "ps", "ps2", "psc", ...
               "psc2", "eps", "eps2", "epsc", "epsc2", ...
               "emf", "pdf", "pslatex", "epslatex", "epslatexstandalone", ...
+              "pslatexstandalone", "pdflatexstandalone", ...
               "pstex", "tiff", "tiffn" "tikz", "pcxmono", ...
               "pcx24b", "pcx256", "pcx16", "pgm", "pgmraw", ...
-              "ppm", "ppmraw"};
+              "ppm", "ppmraw", "pdflatex"};
 
   suffixes = {"ai", "cdr", "fig", "png", "jpg", ...
               "gif", "pbm", "pbm", "dxf", "mf", ...
               "svg", "hpgl", "ps", "ps", "ps", ...
               "ps", "eps", "eps", "eps", "eps", ...
               "emf", "pdf", "tex", "tex", "tex", ...
+              "tex", "tex", ...
               "tex", "tiff", "tiff", "tikz", "pcx", ...
               "pcx", "pcx", "pcx", "pgm", "pgm", ...
-              "ppm", "ppm"};
+              "ppm", "ppm", "tex"};
 
   match = strcmpi (dev_list, arg_st.devopt);
   if (any (match))
@@ -279,7 +281,7 @@
 %! endfor
 
 %!test
-%! opts = __print_parse_opts__ ("test.pdf", "-SX640,Y480");
+%! opts = __print_parse_opts__ ("test.pdf", "-S640,480");
 %! assert (opts.canvas_size, [307.2, 230.4], 0.1);
 
 %!test