* 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.
#include "support/lstrings.h"
#include "support/convert.h"
-#include <sstream>
-#include <string>
+#include <ostream>
+using namespace std;
namespace lyx {
-using std::ostream;
-using std::ostringstream;
-using std::string;
-
-
string const Spacing::spacing_string[]
= {"single", "onehalf", "double", "other"};
}
-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::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() const
+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