X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FSpacing.cpp;h=ce645398f81e09a8eb821b3c1c349197d11e755b;hb=124e0fc2be2446f7182cba0e5b54961dc1cfab91;hp=2b8a326dc08f423cb8000d29b5f416e5afeb0513;hpb=0df54152bc6115ad813d48fe4e73cc82ede1bce3;p=lyx.git diff --git a/src/Spacing.cpp b/src/Spacing.cpp index 2b8a326dc0..ce645398f8 100644 --- a/src/Spacing.cpp +++ b/src/Spacing.cpp @@ -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. @@ -12,8 +12,9 @@ #include #include "Spacing.h" -#include "support/lstrings.h" #include "support/convert.h" +#include "support/lstrings.h" +#include "support/lyxlib.h" #include @@ -55,7 +56,7 @@ void Spacing::set(Spacing::Space sp, string const & val) { space = sp; if (sp == Other) { - switch (int(convert(val) * 1000 + 0.5)) { + switch (support::iround(convert(val) * 1000)) { case 1000: space = Single; break; @@ -90,7 +91,7 @@ void Spacing::writeFile(ostream & os, bool para) const 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", ""}; @@ -99,14 +100,26 @@ string envName(Spacing::Space space, bool useSetSpace) 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 + '}'; } @@ -118,6 +131,16 @@ string const Spacing::writeEnvirEnd(bool useSetSpace) const } +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; @@ -128,11 +151,11 @@ string const Spacing::writePreamble(bool useSetSpace) const //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: