# HG changeset patch # User Andrej Lojdl # Date 1378925315 -7200 # Node ID 21f67db6ab1b1a83d0aa42397d4cd184285d76d7 # Parent 9c7d8c93fb6ba762b29fd2b64634d2c819b0f398 Added check method for latex, dvips and GhostScript in latex_render. diff --git a/libinterp/corefcn/txt-latex.cc b/libinterp/corefcn/txt-latex.cc --- 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 -#include - 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 (0)); + data = uint8NDArray (dim_vector (4, 10, 10), static_cast (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 (0)); + data = uint8NDArray (dim_vector (4, 10, 10), static_cast (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 (0)); + data = uint8NDArray (dim_vector (4, 10, 10), static_cast (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 (0)); + data = uint8NDArray (dim_vector (4, 10, 10), static_cast (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 (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 diff --git a/libinterp/corefcn/txt-latex.h b/libinterp/corefcn/txt-latex.h --- 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);