changeset 17414:21f67db6ab1b

Added check method for latex, dvips and GhostScript in latex_render.
author Andrej Lojdl <andrej.lojdl@gmail.com>
date Wed, 11 Sep 2013 20:48:35 +0200
parents 9c7d8c93fb6b
children 1b93b2de3a8c
files libinterp/corefcn/txt-latex.cc libinterp/corefcn/txt-latex.h
diffstat 2 files changed, 53 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/txt-latex.cc
+++ b/libinterp/corefcn/txt-latex.cc
@@ -40,9 +40,6 @@
 #include "dim-vector.h"
 #include "file-ops.h"
 
-#include <ctime>
-#include <iomanip>
-
 
 latex_render::latex_render (void)
 : bbox (1, 4, 0.0),red (0),green (0),blue (0) 
@@ -53,6 +50,43 @@
 {
 }
 
+int
+latex_render::check_programs (void)
+{
+   int cmd, ready = 1; 
+   std::string check_latex, check_dvips, check_ghostscript;
+   
+   check_latex = "latex  --version >/dev/null 2>/dev/null";
+   check_dvips = "dvips  --version >/dev/null 2>/dev/null";
+   check_ghostscript = "gs  --version >/dev/null 2>/dev/null";
+   
+   cmd = system (check_latex.c_str ());
+   
+   if (cmd != 0)
+   {
+      ::error("There's no LaTeX document preparation system installed on this system. Please install it and then try again.");
+      ready = 0;
+   }
+   
+   cmd = system (check_dvips.c_str ());
+   
+   if (cmd != 0)
+   {
+      ::error("There's no dvips converter installed on this system. Please install it and then try again.");
+      ready = 0;
+   }
+   
+   cmd = system (check_ghostscript.c_str ());
+   
+   if (cmd != 0)
+   {
+      ::error("There's no GhostScript program for converting installed on this system. Please install it and then try again.");
+      ready = 0;
+   }
+   
+   return ready;
+}
+
 void 
 latex_render::adapter (const std::string& txt)
 {
@@ -110,7 +144,7 @@
 
       if(status != 0)
         {
-          data = uint8NDArray (dim_vector (4, 2, 2), static_cast<uint8_t> (0));
+          data = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
 
           ::error ("LaTeX converting .tex to .dvi file, failed.");
 
@@ -142,7 +176,7 @@
 
       if(status != 0)
         {
-          data = uint8NDArray (dim_vector (4, 2, 2), static_cast<uint8_t> (0));
+          data = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
 
           ::error ("dvips converting .dvi to .eps file file, failed");
 
@@ -162,7 +196,7 @@
 
       if(status != 0)
         {
-          data = uint8NDArray (dim_vector (4, 2, 2), static_cast<uint8_t> (0));
+          data = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
 
           ::error ("GhostScript converting .eps to .png file, failed");
 
@@ -278,7 +312,7 @@
       if( !directory_path.empty ())         
         status = octave_recursive_rmdir (directory_path);
 
-      data = uint8NDArray (dim_vector (4, 2, 2), static_cast<uint8_t> (0));
+      data = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
 
       if(error_state == 1)
         ::warning ("LaTeX interpreter can't proceed, please try again.");
@@ -319,24 +353,24 @@
                               uint8NDArray& pixels, Matrix& bbox,
                               int halign, int valign, double rotation)
 {
-  time_t start_time = clock();
-
-  adapter (txt);
-  pixels = render();
+  if (check_programs () == 1)
+  {
+     adapter (txt);
+     pixels = render();
+  }
+  else
+  {
+     pixels = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
+  }
 
   if(pixels.ndims () < 3)
     ::warning ("Pixels variable not properly set.");
   else
     {
-
       bbox = Matrix (1, 4, 0.0);
       bbox (2) = pixels.dim2 ();
       bbox (3) = pixels.dim3 ();
     }
-  std::cout.unsetf(std::ios::floatfield);            // floatfield not set
-  std::cout.precision(10);
-  float time1 = (float) (clock() - start_time)/CLOCKS_PER_SEC;
-  std::cout << std::setprecision(7) << "time elapsed " << time1 << " seconds" << std::endl;
 }
 
 Matrix
--- a/libinterp/corefcn/txt-latex.h
+++ b/libinterp/corefcn/txt-latex.h
@@ -50,6 +50,9 @@
 
   Matrix get_extent (text_element *elt, double rotation = 0.0);
   Matrix get_extent (const std::string& txt, double rotation = 0.0);
+  
+  /* method that cheks if there are all required programs installed */
+  int check_programs (void);
 
   /* method making TEX file from text (input string) */ 
   void adapter (const std::string& txt);