* 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 <config.h>
#include "Spacing.h"
-#include "support/lstrings.h"
#include "support/convert.h"
+#include "support/lstrings.h"
+#include "support/lyxlib.h"
#include <ostream>
{
space = sp;
if (sp == Other) {
- switch (int(convert<double>(val) * 1000 + 0.5)) {
+ switch (support::iround(convert<double>(val) * 1000)) {
case 1000:
space = Single;
break;
namespace {
-string envName(Spacing::Space space, bool useSetSpace)
+string envName(Spacing::Space space, bool useSetSpace)
{
static char const * const env_names[]
= { "SingleSpace", "OnehalfSpace", "DoubleSpace", "Spacing", ""};
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::writeEnvirBegin(bool useSetSpace) const
{
string const name = envName(space, useSetSpace);
- if (space == Other)
+ if (space == Other)
return "\\begin{" + name + "}{" + getValueAsString() + '}';
- else
+ else
return name.empty() ? string() : "\\begin{" + 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;
//return "\\singlespacing\n";
break;
case Onehalf:
- preamble = useSetSpace ? "\\OnehalfSpacing\n"
+ preamble = useSetSpace ? "\\OnehalfSpacing\n"
: "\\onehalfspacing\n";
break;
case Double:
- preamble = useSetSpace ? "\\DoubleSpacing\n"
+ preamble = useSetSpace ? "\\DoubleSpacing\n"
: "\\doublespacing\n";
break;
case Other: