Move spacing code around (and fix a bug)

* LaTeXFeatures.cpp (getPackages): remove some specific spacing code;
	move listings support to simplefeatures array.

	* src/Spacing.cpp (writeEnvirBegin, writeEnvirEnd): code factorization
	(writePreamble): new method containing former code from LaTeXFeatures;
	use \setSpacing instead of \setSingleSpacing.

	* src/BufferParams.cpp (validate, writeLaTeX): handle spacing here.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22644 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2008-01-22 08:41:45 +00:00
parent 385ae43b39
commit 0df54152bc
4 changed files with 60 additions and 66 deletions

View File

@ -863,6 +863,10 @@ void BufferParams::validate(LaTeXFeatures & features) const
if (use_esint == package_on)
features.require("esint");
// Document-level line spacing
if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
features.require("setspace");
// the bullet shapes are buffer level not paragraph level
// so they are tested here
for (int i = 0; i < 4; ++i) {
@ -1206,6 +1210,9 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
// The optional packages;
docstring lyxpreamble(from_ascii(features.getPackages()));
// Line spacing
lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
// We try to load babel late, in case it interferes
// with other packages. But some packages also need babel to be loaded
// before, e.g. jurabib has to be called after babel.

View File

@ -544,7 +544,8 @@ char const * simplefeatures[] = {
"enumitem",
"endnotes",
"ifthen",
"amsthm"
"amsthm",
"listings"
};
int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
@ -652,30 +653,8 @@ string const LaTeXFeatures::getPackages() const
}
// setspace.sty
if ((isRequired("setspace")
|| ((params_.spacing().getSpace() != Spacing::Single
&& !params_.spacing().isDefault())))
&& !tclass.provides("SetSpace")) {
if (mustProvide("setspace") && !tclass.provides("SetSpace"))
packages << "\\usepackage{setspace}\n";
}
bool const upcase = tclass.provides("SetSpace");
switch (params_.spacing().getSpace()) {
case Spacing::Default:
case Spacing::Single:
// we dont use setspace.sty so dont print anything
//packages += "\\singlespacing\n";
break;
case Spacing::Onehalf:
packages << (upcase ? "\\OnehalfSpacing\n" : "\\onehalfspacing\n");
break;
case Spacing::Double:
packages << (upcase ? "\\DoubleSpacing\n" : "\\doublespacing\n");
break;
case Spacing::Other:
packages << (upcase ? "\\setSingleSpace{" : "\\setstretch{")
<< params_.spacing().getValue() << "}\n";
break;
}
// amssymb.sty
if (mustProvide("amssymb")
@ -724,9 +703,6 @@ string const LaTeXFeatures::getPackages() const
"\\makenomenclature\n";
}
if (mustProvide("listings"))
packages << "\\usepackage{listings}\n";
return packages.str();
}

View File

@ -15,8 +15,7 @@
#include "support/lstrings.h"
#include "support/convert.h"
#include <sstream>
#include <string>
#include <ostream>
using namespace std;
@ -89,50 +88,59 @@ void Spacing::writeFile(ostream & os, bool para) const
}
namespace {
string envName(Spacing::Space space, bool useSetSpace)
{
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::writeEnvirBegin(bool useSetSpace) const
{
switch (space) {
case Default: break; // do nothing
case Single:
return (useSetSpace ? "\\begin{SingleSpace}"
: "\\begin{singlespace}");
case Onehalf:
return (useSetSpace ? "\\begin{OnehalfSpace}"
: "\\begin{onehalfspace}");
case Double:
return (useSetSpace ? "\\begin{DoubleSpace}"
: "\\begin{doublespace}");
case Other:
{
ostringstream ost;
ost << (useSetSpace ? "\\begin{Spacing}{"
: "\\begin{spacing}{" )
<< getValueAsString() << '}';
return ost.str();
}
}
return string();
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
{
switch (space) {
case Default: break; // do nothing
case Single:
return (useSetSpace ? "\\end{SingleSpace}"
: "\\end{singlespace}");
case Onehalf:
return (useSetSpace ? "\\end{OnehalfSpace}"
: "\\end{onehalfspace}");
case Double:
return (useSetSpace ? "\\end{DoubleSpace}"
: "\\end{doublespace}");
case Other:
return (useSetSpace ? "\\end{Spacing}" : "\\end{spacing}") ;
}
return string();
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:
case Single:
// we dont use setspace.sty so dont print anything
//return "\\singlespacing\n";
break;
case Onehalf:
preamble = useSetSpace ? "\\OnehalfSpacing\n"
: "\\onehalfspacing\n";
break;
case Double:
preamble = useSetSpace ? "\\DoubleSpacing\n"
: "\\doublespacing\n";
break;
case Other:
preamble = (useSetSpace ? "\\setSpacing{" : "\\setstretch{")
+ getValueAsString() + "}\n";
break;
}
return preamble;
}
} // namespace lyx

View File

@ -17,8 +17,8 @@
#else
#include "support/strfwd.h"
#include <string>
#include <string>
namespace lyx {
@ -64,6 +64,9 @@ public:
/// useSetSpace is true when using the variant supported by
/// the memoir class.
std::string const writeEnvirEnd(bool useSetSpace) const;
/// useSetSpace is true when using the variant supported by
/// the memoir class.
std::string const writePreamble(bool useSetSpace) const;
private:
///