changeset 17119:0f6cfae86e85

Added dimension check for pixels and silenced outside programs. * txt-latex.cc: Outside programs who are invoked through system command are no no longer printing messages to terminal. Code is checking number of pixels dimension. If latex have some errors, user is notified and error message is writen to latex.log file.
author AndrejLojdl <andrej.lojdl@gmail.com>
date Fri, 02 Aug 2013 14:49:44 +0200
parents 527991b748ba
children c43fe083a34b
files libinterp/corefcn/txt-latex.cc
diffstat 1 files changed, 72 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/txt-latex.cc
+++ b/libinterp/corefcn/txt-latex.cc
@@ -27,6 +27,7 @@
 #include"oct.h"
 #include"octave.h"
 #include"parse.h"
+#include"dim-vector.h"
 
 #include <iostream>
 #include <fstream>
@@ -51,9 +52,9 @@
 
   file.open ("default.tex");
   /* Adding LaTeX configuration lines to this file */
-  file << "\\documentclass[fleqn]{article} \n\\usepackage{amsmath} \n\\usepackage{color} \n\\pagestyle{empty}	\n\\begin{document} \n\t\\normalsize \n\t\t\\begin{displaymath}\n\t\t\t";
+  file << "\\documentclass[fleqn]{article} \n\\usepackage{amsmath} \n\\usepackage{color} \n\\pagestyle{empty}	\n\\begin{document} \n\t\\normalsize \n\t\t";
   file << txt;
-  file << "\n\t\t\\end{displaymath} \n\\end{document}";
+  file << "\n\\end{document}";
   file.close();	
 }
 
@@ -69,51 +70,75 @@
   // Checking if command processor is available //
   if(system( NULL ))
     {
-      /* Probably we want to delete files after they are no longer needed - checking if user have all programs will be done soewhere else */
+      // .tex -> .dvi
+      cmd = system ("latex default.tex > latex.log");
+
+      // checking if there is error inside latex.log file
+      file.open("latex.log");
 
-      // .tex -> .dvi
-      cmd = system ("latex default.tex");
+      for(int i=0; i<22; i++)
+        {
+          std::getline(file,comment);
+        }
 
-      // .dvi -> .eps
-      cmd = system ("dvips default.dvi -E -o default.eps");
+      file>>skip;
 
-      // .eps -> .png 
-      cmd = system ("gs -dEPSCrop -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=ppm -sOutputFile=default.ppm \"default.eps\"");
+      if(skip!='!')
+        {
+
+          file.close();
+
+          // .dvi -> .eps
+          cmd = system ("dvips default.dvi -E -o default.eps -q");
 
-      // removing temporary files 
-      cmd = remove ("default.tex");
-      cmd = remove ("default.dvi");
-      cmd = remove ("default.log");
-      cmd = remove ("default.aux");
-      cmd = remove ("default.eps");
+          // .eps -> .ppm
+          cmd = system ("gs -dEPSCrop -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=ppm -sOutputFile=default.ppm \"default.eps\" > ghostscript.log");
+
+          // removing temporary files 
+          cmd = remove ("default.tex");
+          cmd = remove ("default.dvi");
+          cmd = remove ("default.log");
+          cmd = remove ("default.aux");
+          cmd = remove ("default.eps");
 
-      // read data from PPM file to Array for OpenGL rendering
-      file.open("default.ppm");
-      file>>magic_number>>skip;
-      std::getline(file, comment);
-      file>>width>>height;
-      data = uint8NDArray (dim_vector (4, width, height), static_cast<uint8_t> (0));
+          // read data from PPM file to Array for OpenGL rendering
+          file.open("default.ppm");
+          file>>magic_number>>skip;
+          std::getline(file, comment);
+          file>>width>>height;
+          data = uint8NDArray (dim_vector (4, width, height), static_cast<uint8_t> (0));
+
+          // reading the data, row by row 
+          for(int i=height-1; i>=0; i--)
+            {
+              for(int j=0; j<width; j++)
+                {
+                  int r,g,b;
 
-      // reading the data, row by row 
-      for(int i=height-1; i>=0; i--)
+                  file >> r >> g >> b;
+                  data(0,j,i) = r; //red
+                  data(1,j,i) = g; //green
+                  data(2,j,i) = b; //blue
+                  data(3,j,i) = 255;   //alpha -> transparent
+                }
+            }
+          file.close();
+          cmd = remove ("default.ppm");
+          cmd = remove ("latex.log");
+          cmd = remove ("ghostscript.log");
+        }
+      else
         {
-          for(int j=0; j<width; j++)
-            {
-              int r,g,b;
-              
-              file >> r >> g >> b;
-              data(0,j,i) = r; //red
-              data(1,j,i) = g; //green
-              data(2,j,i) = b; //blue
-              data(3,j,i) = 255;   //alpha -> transparent
-            }
+          std::cout<<"There is some problem with your string. For more information take a look at latex.log file in your working directory. \n";
+          file.close();
         }
-      file.close();
     }
   else
-    exit (EXIT_FAILURE); 
-  
-  
+    {
+      std::cout<<"Command processor is not ready, try again."<<std::endl;
+      exit (EXIT_FAILURE); 
+    }  
+
   return data; 
 }
 
@@ -132,10 +157,16 @@
 {
   adapter (txt);
   pixels = render();
-  
-  bbox = Matrix (1, 4, 0.0);
-  bbox(2) = pixels.dim2();
-  bbox(3) = pixels.dim3();	
+
+  if(pixels.ndims () < 3)
+    std::cout<<"Pixels variable not properly set. \n";
+  else
+    {
+
+      bbox = Matrix (1, 4, 0.0);
+      bbox(2) = pixels.dim2();
+      bbox(3) = pixels.dim3();
+    }
 }
 
 Matrix