2003-08-23 00:17:00 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Spacing.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
2000-07-24 13:53:19 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "Spacing.h"
|
2005-01-06 13:48:13 +00:00
|
|
|
#include "support/lstrings.h"
|
2005-01-06 16:39:35 +00:00
|
|
|
#include "support/convert.h"
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2008-01-22 08:41:45 +00:00
|
|
|
#include <ostream>
|
2004-02-13 07:30:59 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2005-01-06 13:48:13 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2001-11-09 13:44:48 +00:00
|
|
|
string const Spacing::spacing_string[]
|
|
|
|
= {"single", "onehalf", "double", "other"};
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2005-01-06 13:48:13 +00:00
|
|
|
|
|
|
|
string const Spacing::getValueAsString() const
|
2000-03-28 02:18:55 +00:00
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (space) {
|
2000-04-11 22:55:29 +00:00
|
|
|
case Default: // nothing special should happen with this...
|
2005-01-06 13:48:13 +00:00
|
|
|
case Single: return "1.0";
|
|
|
|
case Onehalf: return "1.25";
|
|
|
|
case Double: return "1.667";
|
2000-03-28 02:18:55 +00:00
|
|
|
case Other: return value;
|
|
|
|
}
|
2005-01-06 13:48:13 +00:00
|
|
|
return "1.0";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Spacing::getValue() const
|
|
|
|
{
|
2005-01-27 21:05:44 +00:00
|
|
|
return convert<double>(getValueAsString());
|
2000-03-28 02:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
void Spacing::set(Spacing::Space sp, double val)
|
2000-03-28 02:18:55 +00:00
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
set(sp, convert<string>(val));
|
2000-03-28 02:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
void Spacing::set(Spacing::Space sp, string const & val)
|
2000-03-28 02:18:55 +00:00
|
|
|
{
|
2005-01-06 13:48:13 +00:00
|
|
|
space = sp;
|
|
|
|
if (sp == Other) {
|
2005-01-27 21:05:44 +00:00
|
|
|
switch (int(convert<double>(val) * 1000 + 0.5)) {
|
2005-01-06 15:40:49 +00:00
|
|
|
case 1000:
|
|
|
|
space = Single;
|
2005-01-06 13:48:13 +00:00
|
|
|
break;
|
2005-01-06 15:40:49 +00:00
|
|
|
case 1250:
|
|
|
|
space = Onehalf;
|
2005-01-06 13:48:13 +00:00
|
|
|
break;
|
2005-01-06 15:40:49 +00:00
|
|
|
case 1667:
|
|
|
|
space = Double;
|
2005-01-06 13:48:13 +00:00
|
|
|
break;
|
2005-01-06 15:40:49 +00:00
|
|
|
default:
|
|
|
|
value = val;
|
2005-01-06 13:48:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-03-28 02:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
void Spacing::writeFile(ostream & os, bool para) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-04-11 22:55:29 +00:00
|
|
|
if (space == Default) return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
string cmd = para ? "\\paragraph_spacing " : "\\spacing ";
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (getSpace() == Spacing::Other) {
|
2000-04-11 22:55:29 +00:00
|
|
|
os << cmd << spacing_string[getSpace()]
|
2005-01-06 13:48:13 +00:00
|
|
|
<< ' ' << getValueAsString() << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
2004-08-16 11:27:51 +00:00
|
|
|
os << cmd << spacing_string[getSpace()] << "\n";
|
2002-03-21 17:27:08 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-04-19 01:42:55 +00:00
|
|
|
|
|
|
|
|
2008-01-22 08:41:45 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-01-14 14:53:29 +00:00
|
|
|
string const Spacing::writeEnvirBegin(bool useSetSpace) const
|
2000-04-19 01:42:55 +00:00
|
|
|
{
|
2008-01-22 08:41:45 +00:00
|
|
|
string const name = envName(space, useSetSpace);
|
|
|
|
if (space == Other)
|
|
|
|
return "\\begin{" + name + "}{" + getValueAsString() + '}';
|
|
|
|
else
|
|
|
|
return name.empty() ? string() : "\\begin{" + name + '}';
|
2000-04-19 01:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-14 14:53:29 +00:00
|
|
|
string const Spacing::writeEnvirEnd(bool useSetSpace) const
|
2000-04-19 01:42:55 +00:00
|
|
|
{
|
2008-01-22 08:41:45 +00:00
|
|
|
string const name = envName(space, useSetSpace);
|
|
|
|
return name.empty() ? string() : "\\end{" + name + '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const Spacing::writePreamble(bool useSetSpace) const
|
|
|
|
{
|
|
|
|
string preamble;
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (space) {
|
2008-01-22 08:41:45 +00:00
|
|
|
case Default:
|
2000-04-19 01:42:55 +00:00
|
|
|
case Single:
|
2008-01-22 08:41:45 +00:00
|
|
|
// we dont use setspace.sty so dont print anything
|
|
|
|
//return "\\singlespacing\n";
|
|
|
|
break;
|
2000-04-19 01:42:55 +00:00
|
|
|
case Onehalf:
|
2008-01-22 08:41:45 +00:00
|
|
|
preamble = useSetSpace ? "\\OnehalfSpacing\n"
|
|
|
|
: "\\onehalfspacing\n";
|
|
|
|
break;
|
2000-04-19 01:42:55 +00:00
|
|
|
case Double:
|
2008-01-22 08:41:45 +00:00
|
|
|
preamble = useSetSpace ? "\\DoubleSpacing\n"
|
|
|
|
: "\\doublespacing\n";
|
|
|
|
break;
|
2000-04-19 01:42:55 +00:00
|
|
|
case Other:
|
2008-01-22 08:41:45 +00:00
|
|
|
preamble = (useSetSpace ? "\\setSpacing{" : "\\setstretch{")
|
|
|
|
+ getValueAsString() + "}\n";
|
|
|
|
break;
|
2000-04-19 01:42:55 +00:00
|
|
|
}
|
2008-01-22 08:41:45 +00:00
|
|
|
return preamble;
|
2000-04-19 01:42:55 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|