X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FSpacing.cpp;h=9ac8345ab4647077b42a92e1d5b0216c293677dc;hb=25f274f2a08674b75cc50e579aa4b2592fd38a18;hp=d2ed1acd80dee85017672f17af7b4eb088d7d4ec;hpb=f630be890494c849981e4fb52ea4740506e92bed;p=lyx.git diff --git a/src/Spacing.cpp b/src/Spacing.cpp index d2ed1acd80..9ac8345ab4 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,18 +15,13 @@ #include "support/lstrings.h" #include "support/convert.h" -#include -#include +#include +using namespace std; namespace lyx { -using std::ostream; -using std::ostringstream; -using std::string; - - string const Spacing::spacing_string[] = {"single", "onehalf", "double", "other"}; @@ -93,43 +88,81 @@ 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 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); +} -string const Spacing::writeEnvirEnd() const +} // namespace + +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::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; 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