X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FSpacing.cpp;h=3290a6013c3b4c9c1cc90d478973e90e24385dc9;hb=28be7d552f62cc02fa86d7f79201d089bfb2d7b5;hp=9589cff1cd75f02bb180b9bede746a3d071728d4;hpb=9383f4c3c6f9cfab2d658701ba66e2b54cd68bea;p=lyx.git diff --git a/src/Spacing.cpp b/src/Spacing.cpp index 9589cff1cd..3290a6013c 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. @@ -15,8 +15,7 @@ #include "support/lstrings.h" #include "support/convert.h" -#include -#include +#include using namespace std; @@ -89,43 +88,59 @@ 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 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::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