changeset 12404:6001e10ce152 release-3-4-x

Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
author David Bateman <dbateman@free.fr>
date Sun, 06 Feb 2011 23:25:31 +0100
parents 581f65bcc1a4
children 80666cb91c4c
files scripts/ChangeLog scripts/plot/legend.m src/ls-mat5.cc src/txt-eng.h
diffstat 4 files changed, 113 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,8 @@
+2011-02-05  David Bateman  <dbateman@free.fr>
+
+	* plot/legend.m: Add padding to legend positions. Fix for outerposition
+	for southeastoutside and southwestoutside.
+
 2011-02-06  Ben Abbott  <bpabbott@mac.com>
 
 	* plot/legend.m: Align legends to plot box, add demo. Bug 32373.
--- a/scripts/plot/legend.m
+++ b/scripts/plot/legend.m
@@ -553,7 +553,8 @@
           case "north"
             if (outside)
               lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
-                      ca_outpos(2) + ca_outpos(4) - lpos(4), lpos(3), lpos(4)];
+                      ca_outpos(2) + ca_outpos(4) - lpos(4) - ypad, lpos(3), ...
+                      lpos(4)];
 
               new_pos = [ca_pos(1), ca_pos(2), ca_pos(3), ca_pos(4) - lpos(4)];
               new_outpos = [ca_outpos(1), ca_outpos(2), ca_outpos(3), ...
@@ -564,8 +565,8 @@
             endif
           case "south"
             if (outside)
-              lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ca_outpos(2), ...
-                      lpos(3), lpos(4)];
+              lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
+                      ca_outpos(2) + ypad, lpos(3), lpos(4)];
               new_pos = [ca_pos(1), ca_pos(2) + lpos(4), ca_pos(3), ...
                          ca_pos(4) - lpos(4)];
               new_outpos = [ca_outpos(1), ca_outpos(2) + lpos(4), ...
@@ -576,7 +577,7 @@
             endif
           case "east"
             if (outside)
-              lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3), ...
+              lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - ypad, ...
                       ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, lpos(3), lpos(4)];
               new_pos = [ca_pos(1), ca_pos(2), ca_pos(3) - lpos(3), ca_pos(4)];
               new_outpos = [ca_outpos(1), ca_outpos(2), ...
@@ -587,7 +588,8 @@
             endif
           case "west"
             if (outside)
-              lpos = [ca_outpos(1), ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, ...
+              lpos = [ca_outpos(1) + ypad, ...
+                      ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, ...
                       lpos(3), lpos(4)];
               new_pos = [ca_pos(1) + lpos(3), ca_pos(2), ...
                          ca_pos(3) - lpos(3), ca_pos(4)];
@@ -599,7 +601,7 @@
             endif
           case "northeast"
             if (outside)
-              lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3), ...
+              lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - ypad, ...
                       ca_pos(2) + ca_pos(4) - lpos(4), lpos(3), lpos(4)];
               new_pos = [ca_pos(1), ca_pos(2), ca_pos(3) - lpos(3), ca_pos(4)];
               new_outpos = [ca_outpos(1), ca_outpos(2), ...
@@ -610,7 +612,7 @@
             endif
           case "northwest"
             if (outside)
-              lpos = [ca_outpos(1), ca_pos(2) + ca_pos(4) - lpos(4), ...
+              lpos = [ca_outpos(1) + ypad , ca_pos(2) + ca_pos(4) - lpos(4), ...
                       lpos(3), lpos(4)];
               new_pos = [ca_pos(1) + lpos(3), ca_pos(2), ...
                          ca_pos(3) - lpos(3), ca_pos(4)];
@@ -622,23 +624,23 @@
             endif
           case "southeast"
             if (outside)
-              lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3), ca_pos(2), ...
-                      lpos(3), lpos(4)];
+              lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - ypad, ...
+                      ca_pos(2), lpos(3), lpos(4)];
               new_pos = [ca_pos(1), ca_pos(2), ...
                          ca_pos(3) - lpos(3), ca_pos(4)];
-              new_outpos = [ca_outpos(1), ca_outpos(2) + lpos(4), ...
-                            ca_outpos(3) - lpos(3), ca_outpos(4) - lpos(4)];
+              new_outpos = [ca_outpos(1), ca_outpos(2), ...
+                            ca_outpos(3) - lpos(3), ca_outpos(4)];
             else
               lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - ypad, ...
                       ca_pos(2) + ypad, lpos(3), lpos(4)];
             endif
           case "southwest"
             if (outside)
-              lpos = [ca_outpos(1), ca_pos(2), lpos(3), lpos(4)];
+              lpos = [ca_outpos(1) + ypad, ca_pos(2), lpos(3), lpos(4)];
               new_pos = [ca_pos(1) + lpos(3), ca_pos(2), ...
                          ca_pos(3) - lpos(3), ca_pos(4)];
-              new_outpos = [ca_outpos(1) + lpos(3), ca_outpos(2) + lpos(4), ...
-                            ca_outpos(3) - lpos(3), ca_outpos(4) - lpos(4)];
+              new_outpos = [ca_outpos(1) + lpos(3), ca_outpos(2), ...
+                            ca_outpos(3) - lpos(3), ca_outpos(4)];
             else
               lpos = [ca_pos(1) + ypad, ca_pos(2) + ypad, lpos(3), lpos(4)];
             endif
--- a/src/ls-mat5.cc
+++ b/src/ls-mat5.cc
@@ -525,6 +525,8 @@
       OCTAVE_LOCAL_BUFFER (char, inbuf, element_length);
       is.read (inbuf, element_length);
 
+      std::cerr << "len: " << element_length << "\n";
+
       // We uncompress the first 8 bytes of the header to get the buffer length
       // This will fail with an error Z_MEM_ERROR
       uLongf destLen = 8;
@@ -537,61 +539,75 @@
           if (swap)
             swap_bytes<4> (tmp, 2);
 
-          destLen = tmp[1] + 8;
+          destLen = tmp[1] + 32;
           std::string outbuf (destLen, ' ');
 
-          // FIXME -- find a way to avoid casting away const here!
-
-          int err = uncompress (reinterpret_cast<Bytef *> (const_cast<char *> (outbuf.c_str ())),
-                                &destLen, reinterpret_cast<Bytef *> (inbuf),
-                                element_length);
-
-          if (err != Z_OK)
+          // Try reading the compressed file with 8 different lengthes
+          // to account for the zero padding that are added to matlab
+          // files
+          for (int k = 0; k < 8; k++)
             {
-              std::string msg;
-              switch (err)
+              // FIXME -- find a way to avoid casting away const here!
+              int err = uncompress (reinterpret_cast<Bytef *> 
+                                    (const_cast<char *> (outbuf.c_str ())),
+                                    &destLen, reinterpret_cast<Bytef *> (inbuf),
+                                    element_length - k);
+
+              if (err != Z_OK)
                 {
-                case Z_STREAM_END:
-                  msg = "stream end";
-                  break;
-
-                case Z_NEED_DICT:
-                  msg = "need dict";
-                  break;
-
-                case Z_ERRNO:
-                  msg = "errno case";
-                  break;
-
-                case Z_STREAM_ERROR:
-                  msg = "stream error";
-                  break;
-
-                case Z_DATA_ERROR:
-                  msg = "data error";
-                  break;
-
-                case Z_MEM_ERROR:
-                  msg = "mem error";
-                  break;
-
-                case Z_BUF_ERROR:
-                  msg = "buf error";
-                  break;
-
-                case Z_VERSION_ERROR:
-                  msg = "version error";
+                  std::string msg;
+                  switch (err)
+                    {
+                    case Z_STREAM_END:
+                      msg = "stream end";
+                      break;
+
+                    case Z_NEED_DICT:
+                      msg = "need dict";
+                      break;
+
+                    case Z_ERRNO:
+                      msg = "errno case";
+                      break;
+
+                    case Z_STREAM_ERROR:
+                      msg = "stream error";
+                      break;
+
+                    case Z_DATA_ERROR:
+                      if (k != 7)
+                        {
+                          std::cerr << "k = " << k << "\n";
+                          continue;
+                        }
+                      else
+                        msg = "data error";
+                      break;
+
+                    case Z_MEM_ERROR:
+                      msg = "mem error";
+                      break;
+
+                    case Z_BUF_ERROR:
+                      msg = "buf error";
+                      break;
+
+                    case Z_VERSION_ERROR:
+                      msg = "version error";
+                      break;
+                    }
+
+                  error ("load: error uncompressing data element (%s from zlib)",
+                         msg.c_str ());
                   break;
                 }
-
-              error ("load: error uncompressing data element (%s from zlib)",
-                     msg.c_str ());
-            }
-          else
-            {
-              std::istringstream gz_is (outbuf);
-              retval = read_mat5_binary_element (gz_is, filename,
+              else
+                {
+                  std::istringstream gz_is (outbuf);
+                  retval = read_mat5_binary_element (gz_is, filename,
                                                  swap, global, tc);
+                  break;
+                }
             }
         }
       else
--- a/src/txt-eng.h
+++ b/src/txt-eng.h
@@ -190,4 +190,32 @@
     }
 };
 
+class
+OCTINTERP_API
+text_parser_tex : public text_parser
+{
+public:
+  text_parser_tex (void) : text_parser () { }
+
+  ~text_parser_tex (void) { }
+
+  // FIXME: is it possible to use reference counting to manage the
+  // memory for the object returned by the text parser?  That would be
+  // preferable to having to know when and where to delete the object it
+  // creates...
+
+  text_element* parse (const std::string& s);
+
+ private:
+  text_element_list lst;
+  mutable size_t anchor;
+  
+  std::string getargument(const std::string& s, size_t start) const;
+  
+  size_t matchbrace(const std::string& s, size_t start) const;
+  
+
+
+};
+
 #endif