# HG changeset patch # User AndrejLojdl # Date 1375212008 -7200 # Node ID 8ad11cc45df6b5c1794873915d63ccc58da978d8 # Parent 8ce0efb93c60fcd46e6bf1a4bc25bc522f4e1c88 Implemented proof of concept LaTeX markup, through LaTeX interpreter. * txt-eng-ft.h: Included txt-render.h file. * txt-latex.cc: New file, implementing latex_render class. Every method and all it members. Enabling LaTeX markup in Octave. * txt-latex.h: New file, holds declaration of latex_render class. * txt-render.cc New file, implementing dummy_render class and text_render method make_text_render. * txt-render.h: New file, holds declaration of abstract base_text_render class. Here is declaration of wrapper class text_render, which pick rendering class through it method make_text_render. And here is declaration of dummy_render class. diff --git a/libinterp/interp-core/txt-eng-ft.cc b/libinterp/interp-core/txt-eng-ft.cc --- a/libinterp/interp-core/txt-eng-ft.cc +++ b/libinterp/interp-core/txt-eng-ft.cc @@ -10,7 +10,7 @@ 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 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or< FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. diff --git a/libinterp/interp-core/txt-latex.cc b/libinterp/interp-core/txt-latex.cc --- a/libinterp/interp-core/txt-latex.cc +++ b/libinterp/interp-core/txt-latex.cc @@ -78,77 +78,69 @@ cmd = system ("dvips default.dvi -E -o default.eps"); // .eps -> .png - cmd = system ("gs -dEPSCrop -dSAFER -dBATCH -dNOPAUSE -r600 -sDEVICE=ppm -sOutputFile=default.ppm \"default.eps\""); + cmd = system ("gs -dEPSCrop -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=ppm -sOutputFile=default.ppm \"default.eps\""); // 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, height, width), static_cast (0)); + data = uint8NDArray (dim_vector (4, width, height), static_cast (0)); // reading the data, row by row - for(int j=0; j=0; i--) { - for(int i=0; i>data(0,i,j); //red - file>>data(1,i,j); //green - file>>data(2,i,j); //blue - data(3,i,j) = 0; //alpha -> transparent + 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 } } - file.close(); - - // remove PPM file - cmd = remove("default.ppm"); + file.close(); } else exit (EXIT_FAILURE); + + + return data; } Matrix latex_render::get_bbox (void) { + Matrix bounding_box (1, 4, 0.0); std::ifstream file; - std::string comment; - double tmp, scaling = 1.36; - Matrix bounding_box (1, 4, 0.0); - int counter = 0,x,y, cmd; + std::string skip; + int width, height; + + file.open("default.ppm"); - file.open("default.eps"); - char character = 0,string[20]; - std::getline(file,comment); - std::getline(file,comment); - std::getline(file,comment); - std::getline(file,comment); + std::getline(file, skip); + std::getline(file, skip); - // For the first moment, bounding box is set so the fontsize will be 12pt - file>>string; - file>>x; - - file>>y; - file>>tmp; - x=tmp-x; + + file>>width>>height; + + bounding_box(2) = width; + bounding_box(3) = height; - file>>tmp; - y=tmp-y; - bounding_box(0) = 0; - bounding_box(1) = 0; - bounding_box(2) = x*scaling; - bounding_box(3) = y*scaling; file.close(); - - // remove EPS file is no longer needed - cmd = remove ("default.eps"); - + + remove("default.ppm"); + return bounding_box; } diff --git a/libinterp/interpfcn/graphics.cc b/libinterp/interpfcn/graphics.cc --- a/libinterp/interpfcn/graphics.cc +++ b/libinterp/interpfcn/graphics.cc @@ -7140,7 +7140,7 @@ void text::properties::update_font (void) { - +/* #ifdef HAVE_FREETYPE #ifdef HAVE_FONTCONFIG renderer.set_font (get ("fontname").string_value (), @@ -7150,6 +7150,7 @@ #endif renderer.set_color (get_color_rgb ()); #endif +*/ } void @@ -7182,9 +7183,17 @@ string_vector sv = string_prop.all_strings (); + r.set_font (get ("fontname").string_value (), + get ("fontweight").string_value (), + get ("fontangle").string_value (), + get ("fontsize").double_value ()); + + r.set_color (get_color_rgb ()); r.text_to_pixels (sv.join ("\n"), pixels, bbox, halign, valign, get_rotation ()); + + /* The bbox is relative to the text's position. We'll leave it that way, because get_position () does not return valid results when the text is first constructed. diff --git a/libinterp/interpfcn/graphics.in.h b/libinterp/interpfcn/graphics.in.h --- a/libinterp/interpfcn/graphics.in.h +++ b/libinterp/interpfcn/graphics.in.h @@ -4307,10 +4307,12 @@ Matrix get_data_position (void) const; Matrix get_extent_matrix (void) const; const uint8NDArray& get_pixels (void) const { return pixels; } +/* #if HAVE_FREETYPE // freetype renderer, used for calculation of text size text_render renderer; #endif +*/ protected: void init (void)