changeset 17431:71b6f8a81e80

Changed the red, blue and green variables with one color variable as in ft_render.
author Andrej Lojdl <andrej.lojdl@gmail.com>
date Thu, 12 Sep 2013 21:57:09 +0200
parents 1b93b2de3a8c
children 499fc170bca3
files libinterp/corefcn/txt-latex.cc libinterp/corefcn/txt-latex.h
diffstat 2 files changed, 27 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/txt-latex.cc
+++ b/libinterp/corefcn/txt-latex.cc
@@ -42,7 +42,7 @@
 
 
 latex_render::latex_render (void)
-: bbox (1, 4, 0.0),red (0),green (0),blue (0) 
+: bbox (1, 4, 0.0), color (dim_vector (1, 3), 0) 
 {
 }
 
@@ -144,7 +144,7 @@
 
       if(status != 0)
         {
-          data = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
+          data = uint8NDArray (dim_vector (4, 1, 1), static_cast<uint8_t> (0));
 
           ::error ("LaTeX converting .tex to .dvi file, failed.");
 
@@ -176,7 +176,7 @@
 
       if(status != 0)
         {
-          data = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
+          data = uint8NDArray (dim_vector (4, 1, 1), static_cast<uint8_t> (0));
 
           ::error ("dvips converting .dvi to .eps file file, failed");
 
@@ -196,7 +196,7 @@
 
       if(status != 0)
         {
-          data = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
+          data = uint8NDArray (dim_vector (4, 1, 1), static_cast<uint8_t> (0));
 
           ::error ("GhostScript converting .eps to .png file, failed");
 
@@ -286,9 +286,9 @@
               /* If the color of text is black we can change it, if not we render the original color. */
               if(ptr[0] < 50 && ptr[1] < 50 && ptr[2] < 50 )
                 {
-                  data(0, j, i) = red;
-                  data(1, j, i) = green;
-                  data(2, j, i) = blue;
+                  data(0, j, i) = color(0);
+                  data(1, j, i) = color(1);
+                  data(2, j, i) = color(2);
                   data(3, j, i) = ptr[3];
                 }
               else
@@ -312,7 +312,7 @@
       if( !directory_path.empty ())         
         status = octave_recursive_rmdir (directory_path);
 
-      data = uint8NDArray (dim_vector (4, 10, 10), static_cast<uint8_t> (0));
+      data = uint8NDArray (dim_vector (4, 1, 1), static_cast<uint8_t> (0));
 
       if(error_state == 1)
         ::warning ("LaTeX interpreter can't proceed, please try again.");
@@ -339,9 +339,9 @@
 {
   if (c.numel () == 3)
     {
-      red = static_cast<uint8_t> (c (0) * 255);
-      green = static_cast<uint8_t> (c (1) * 255);
-      blue = static_cast<uint8_t> (c (2) * 255);
+      color(0) = static_cast<uint8_t> (c (0) * 255);
+      color(1) = static_cast<uint8_t> (c (1) * 255);
+      color(2) = static_cast<uint8_t> (c (2) * 255);
     }
   else
     ::warning ("latex_render::set_color: invalid color");
@@ -370,6 +370,21 @@
       bbox = Matrix (1, 4, 0.0);
       bbox (2) = pixels.dim2 ();
       bbox (3) = pixels.dim3 ();
+      
+      switch (halign)
+      {
+        default: bbox(0) = 0; break;
+        case 1: bbox(0) = -bbox(2)/2; break;
+        case 2: bbox(0) = -bbox(2); break;
+      }
+      switch (valign)
+      {
+        default: bbox(1) = 0; break;
+        case 1: bbox(1) = -bbox(3)/2; break;
+        case 2: bbox(1) = -bbox(3); break;
+        case 3: break;
+        case 4: bbox(1) = -bbox(3)-bbox(1); break;
+      }
     }
 }
 
--- a/libinterp/corefcn/txt-latex.h
+++ b/libinterp/corefcn/txt-latex.h
@@ -65,7 +65,7 @@
   std::string font_name,directory_path;
   Matrix bbox;
   uint8NDArray pixels;
-  uint8_t red, green, blue;
+  uint8NDArray color;
 
 };
 #endif