]> git.lyx.org Git - lyx.git/blobdiff - src/Spacing.cpp
Provide proper fallback if a bibliography processor is not found
[lyx.git] / src / Spacing.cpp
index 9589cff1cd75f02bb180b9bede746a3d071728d4..9ac8345ab4647077b42a92e1d5b0216c293677dc 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,81 @@ 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 cmdName(Spacing::Space space, bool useSetSpace)
+{
+       static char const * const cmd_names[]
+               = { "SingleSpacing", "OnehalfSpacing", "DoubleSpacing", "SetStretch", ""};
+       string const name = cmd_names[space];
+
+       if (useSetSpace && name == "SetStretch")
+               return "setSpacing";
+
+       return useSetSpace ? name : support::ascii_lowercase(name);
 }
 
+} // namespace
 
-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::writeCmd(bool useSetSpace) const
+{
+       string const name = cmdName(space, useSetSpace);
+       if (space == Other)
+               return "\\" + name + "{" + getValueAsString() + '}';
+       else
+               return name.empty() ? string() : "\\" + 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