]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Fix for crash/segfault introduced with [244de5d2/lyxgit], thanks Guillame.
[lyx.git] / src / BufferParams.cpp
index 09ec43467b2d87fc444b802c62714e61cd59d7b0..9ef1fdbb95579cc552d27ffde206c84cc638d3e8 100644 (file)
 #include "ColorSet.h"
 #include "Converter.h"
 #include "Encoding.h"
-#include "HSpace.h"
 #include "IndicesList.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
 #include "LaTeXFonts.h"
+#include "Length.h"
 #include "ModuleList.h"
 #include "Font.h"
 #include "Lexer.h"
@@ -338,6 +338,7 @@ public:
        IndicesList indiceslist;
        Spacing spacing;
        Length parindent;
+       Length mathindent;
        /** This is the amount of space used for paragraph_separation "skip",
         * and for detached paragraphs in "indented" documents.
         */
@@ -384,7 +385,6 @@ BufferParams::BufferParams()
        makeDocumentClass();
        paragraph_separation = ParagraphIndentSeparation;
        is_math_indent = false;
-       math_indentation = "default";
        quotes_style = InsetQuotesParams::EnglishQuotes;
        dynamic_quotes = false;
        fontsize = "default";
@@ -628,6 +628,18 @@ PDFOptions const & BufferParams::pdfoptions() const
 }
 
 
+Length const & BufferParams::getMathIndent() const
+{
+       return pimpl_->mathindent;
+}
+
+
+void BufferParams::setMathIndent(Length const & indent)
+{
+       pimpl_->mathindent = indent;
+}
+
+
 Length const & BufferParams::getParIndent() const
 {
        return pimpl_->parindent;
@@ -822,7 +834,12 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                lex >> parsep;
                paragraph_separation = parseptranslator().find(parsep);
        } else if (token == "\\paragraph_indentation") {
-               lex >> pimpl_->parindent;
+               lex.next();
+               string parindent = lex.getString();
+               if (parindent == "default")
+                       pimpl_->parindent = Length();
+               else
+                       pimpl_->parindent = Length(parindent);
        } else if (token == "\\defskip") {
                lex.next();
                string const defskip = lex.getString();
@@ -833,7 +850,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
        } else if (token == "\\is_math_indent") {
                lex >> is_math_indent;
        } else if (token == "\\math_indentation") {
-               lex >> math_indentation;
+               lex.next();
+               pimpl_->mathindent = Length(lex.getString());
        } else if (token == "\\quotes_style") {
                string qstyle;
                lex >> qstyle;
@@ -1327,12 +1345,13 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
           << "\n\\paragraph_separation "
           << string_paragraph_separation[paragraph_separation];
        if (!paragraph_separation)
-               os << "\n\\paragraph_indentation " << Lexer::quoteString(pimpl_->parindent.asString());
+               os << "\n\\paragraph_indentation "
+                  << (getParIndent().empty() ? "default" : getParIndent().asString());
        else
                os << "\n\\defskip " << getDefSkip().asLyXCommand();
        os << "\n\\is_math_indent " << is_math_indent;
-       if (is_math_indent && math_indentation != "default")
-               os << "\n\\math_indentation " << math_indentation;
+       if (is_math_indent && !getMathIndent().empty())
+               os << "\n\\math_indentation " << getMathIndent().asString();
        os << "\n\\quotes_style "
           << string_quotes_style[quotes_style]
           << "\n\\dynamic_quotes " << dynamic_quotes
@@ -1944,9 +1963,9 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        if (is_math_indent) {
                // when formula indentation
                // only output something when it is not the default
-               if (math_indentation != "default") {
+               if (!getMathIndent().empty()) {
                        os << "\\setlength{\\mathindent}{"
-                          << from_utf8(math_indentation)
+                          << from_utf8(getMathIndent().asString())
                           << "}\n";
                }
        }