]> git.lyx.org Git - lyx.git/blobdiff - src/VSpace.cpp
Fix some issues with textmode. We'll let SetMode() handle as much of
[lyx.git] / src / VSpace.cpp
index 45379fd85dce898d3fca4cdd9340d17699d4ba3f..19f6af41a1f638d282263e6f6be1ef01ccdf19a3 100644 (file)
 #include "support/convert.h"
 #include "support/lstrings.h"
 
+#include "support/lassert.h"
+
+#include <cstring>
+
 using namespace std;
 using namespace lyx::support;
 
+
 namespace lyx {
 
 namespace {
 
 /// used to return numeric values in parsing vspace
 double number[4] = { 0, 0, 0, 0 };
+
 /// used to return unit types in parsing vspace
-Length::UNIT unit[4] = { Length::UNIT_NONE,
-                           Length::UNIT_NONE,
-                           Length::UNIT_NONE,
-                           Length::UNIT_NONE };
+Length::UNIT unit[4] = {
+       Length::UNIT_NONE,
+       Length::UNIT_NONE,
+       Length::UNIT_NONE,
+       Length::UNIT_NONE
+};
 
 /// the current position in the number array
 int number_index;
@@ -44,16 +52,14 @@ int number_index;
 int unit_index;
 
 /// skip n characters of input
-inline
-void lyx_advance(string & data, string::size_type n)
+inline void lyx_advance(string & data, size_t n)
 {
        data.erase(0, n);
 }
 
 
 /// return true when the input is at the end
-inline
-bool isEndOfData(string const & data)
+inline bool isEndOfData(string const & data)
 {
        return ltrim(data).empty();
 }
@@ -98,7 +104,7 @@ char nextToken(string & data)
                return '-';
        }
 
-       string::size_type i = data.find_first_not_of("0123456789.");
+       size_t i = data.find_first_not_of("0123456789.");
 
        if (i != 0) {
                if (number_index > 3)
@@ -110,8 +116,9 @@ char nextToken(string & data)
                if (i == string::npos) {
                        buffer = data;
                        i = data.size() + 1;
-               } else
+               } else {
                        buffer = data.substr(0, i);
+               }
 
                lyx_advance(data, i);
 
@@ -134,8 +141,9 @@ char nextToken(string & data)
                if (i == string::npos) {
                        buffer = data;
                        i = data.size() + 1;
-               } else
+               } else {
                        buffer = data.substr(0, i);
+               }
 
                // possibly we have "mmplus" string or similar
                if (buffer.size() > 5 &&
@@ -256,7 +264,7 @@ bool isValidGlueLength(string const & data, GlueLength * result)
 
        // search "pattern" in "table"
        table_index = 0;
-       while (compare(pattern, table[table_index].pattern)) {
+       while (strcmp(pattern, table[table_index].pattern)) {
                ++table_index;
                if (!*table[table_index].pattern)
                        return false;
@@ -321,7 +329,7 @@ bool isValidLength(string const & data, Length * result)
        pattern[pattern_index] = '\0';
 
        // only the most basic pattern is accepted here
-       if (compare(pattern, "nu") != 0)
+       if (strcmp(pattern, "nu") != 0)
                return false;
 
        // It _was_ a correct length string.
@@ -366,7 +374,7 @@ VSpace::VSpace(string const & data)
 
        string input = rtrim(data);
 
-       string::size_type const length = input.length();
+       size_t const length = input.length();
 
        if (length > 1 && input[length - 1] == '*') {
                keep_ = true;
@@ -450,7 +458,7 @@ string const VSpace::asLatexCommand(BufferParams const & params) const
                        : "\\vspace{" + len_.asLatexString() + '}';
 
        default:
-               BOOST_ASSERT(false);
+               LASSERT(false, /**/);
                return string();
        }
 }
@@ -485,6 +493,24 @@ docstring const VSpace::asGUIName() const
 }
 
 
+string VSpace::asHTMLLength() const 
+{
+       string result;
+       switch (kind_) {
+               case DEFSKIP:   result = "2ex"; break;
+               case SMALLSKIP: result = "1ex"; break;
+               case MEDSKIP:   result = "3ex"; break;
+               case BIGSKIP:   result = "5ex"; break;
+               case LENGTH: {
+                       Length tmp = len_.len();
+                       if (tmp.value() > 0)
+                               result = tmp.asHTMLString();
+               }
+               case VFILL:     break;
+       }
+       return result;
+}
+
 int VSpace::inPixels(BufferView const & bv) const
 {
        // Height of a normal line in pixels (zoom factor considered)
@@ -514,7 +540,7 @@ int VSpace::inPixels(BufferView const & bv) const
                return len_.len().inPixels(bv.workWidth());
 
        default:
-               BOOST_ASSERT(false);
+               LASSERT(false, /**/);
                return 0;
        }
 }