]> git.lyx.org Git - lyx.git/blobdiff - src/Spacing.cpp
Account for old versions of Pygments
[lyx.git] / src / Spacing.cpp
index 9589cff1cd75f02bb180b9bede746a3d071728d4..3290a6013c3b4c9c1cc90d478973e90e24385dc9 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Jean-Marc Lasgouttes
  *
  * Full author contact details are available in file CREDITS.
@@ -15,8 +15,7 @@
 #include "support/lstrings.h"
 #include "support/convert.h"
 
-#include <sstream>
-#include <string>
+#include <ostream>
 
 using namespace std;
 
@@ -89,43 +88,59 @@ void Spacing::writeFile(ostream & os, bool para) const
 }
 
 
-string const Spacing::writeEnvirBegin() const
+namespace {
+
+string envName(Spacing::Space space, bool useSetSpace) 
 {
-       switch (space) {
-       case Default: break; // do nothing
-       case Single:
-               return "\\begin{singlespace}";
-       case Onehalf:
-               return "\\begin{onehalfspace}";
-       case Double:
-               return "\\begin{doublespace}";
-       case Other:
-       {
-               ostringstream ost;
-               ost << "\\begin{spacing}{"
-                   << getValueAsString() << '}';
-               return ost.str();
-       }
-       }
-       return string();
+       static char const * const env_names[]
+               = { "SingleSpace", "OnehalfSpace", "DoubleSpace", "Spacing", ""};
+       string const name = env_names[space];
+
+       return useSetSpace ? name : support::ascii_lowercase(name);
 }
 
+}
 
-string const Spacing::writeEnvirEnd() const
+string const Spacing::writeEnvirBegin(bool useSetSpace) const
 {
+       string const name = envName(space, useSetSpace);
+       if (space == Other) 
+               return "\\begin{" + name + "}{" + getValueAsString() + '}';
+       else 
+               return name.empty() ? string() : "\\begin{" + name + '}';
+}
+
+
+string const Spacing::writeEnvirEnd(bool useSetSpace) const
+{
+       string const name = envName(space, useSetSpace);
+       return name.empty() ? string() : "\\end{" + name + '}';
+}
+
+
+string const Spacing::writePreamble(bool useSetSpace) const
+{
+       string preamble;
        switch (space) {
-       case Default: break; // do nothing
+       case Default:
        case Single:
-               return "\\end{singlespace}";
+               // we dont use setspace.sty so dont print anything
+               //return "\\singlespacing\n";
+               break;
        case Onehalf:
-               return "\\end{onehalfspace}";
+               preamble = useSetSpace ? "\\OnehalfSpacing\n" 
+                       : "\\onehalfspacing\n";
+               break;
        case Double:
-               return "\\end{doublespace}";
+               preamble = useSetSpace ? "\\DoubleSpacing\n" 
+                       : "\\doublespacing\n";
+               break;
        case Other:
-               return "\\end{spacing}";
+               preamble = (useSetSpace ? "\\setSpacing{" : "\\setstretch{")
+                       + getValueAsString() + "}\n";
+               break;
        }
-       return string();
+       return preamble;
 }
 
-
 } // namespace lyx