X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSpacing.cpp;h=ce645398f81e09a8eb821b3c1c349197d11e755b;hb=a900667ea1bb516ac562a6c45e4f3a1e4071b01b;hp=0239a090dbab6500395a6deaa743eed0f4ce6992;hpb=75bfed55079cab6b73fbea6ce4ae3f10d1af3b91;p=lyx.git diff --git a/src/Spacing.cpp b/src/Spacing.cpp index 0239a090db..ce645398f8 100644 --- a/src/Spacing.cpp +++ b/src/Spacing.cpp @@ -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; @@ -99,8 +100,20 @@ 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); @@ -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;