2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file Spacing.C
|
|
|
|
|
* 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
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \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
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
2005-01-06 13:48:13 +00:00
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const Spacing::writeEnvirBegin() const
|
2000-04-19 01:42:55 +00:00
|
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (space) {
|
2000-04-19 01:42:55 +00:00
|
|
|
|
case Default: break; // do nothing
|
|
|
|
|
case Single:
|
|
|
|
|
return "\\begin{singlespace}";
|
|
|
|
|
case Onehalf:
|
|
|
|
|
return "\\begin{onehalfspace}";
|
|
|
|
|
case Double:
|
|
|
|
|
return "\\begin{doublespace}";
|
|
|
|
|
case Other:
|
2000-09-14 17:53:12 +00:00
|
|
|
|
{
|
2000-04-19 01:42:55 +00:00
|
|
|
|
ostringstream ost;
|
|
|
|
|
ost << "\\begin{spacing}{"
|
2005-01-06 13:48:13 +00:00
|
|
|
|
<< getValueAsString() << '}';
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return ost.str();
|
2000-09-14 17:53:12 +00:00
|
|
|
|
}
|
2000-04-19 01:42:55 +00:00
|
|
|
|
}
|
|
|
|
|
return string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const Spacing::writeEnvirEnd() const
|
2000-04-19 01:42:55 +00:00
|
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (space) {
|
2000-04-19 01:42:55 +00:00
|
|
|
|
case Default: break; // do nothing
|
|
|
|
|
case Single:
|
|
|
|
|
return "\\end{singlespace}";
|
|
|
|
|
case Onehalf:
|
|
|
|
|
return "\\end{onehalfspace}";
|
|
|
|
|
case Double:
|
|
|
|
|
return "\\end{doublespace}";
|
|
|
|
|
case Other:
|
|
|
|
|
return "\\end{spacing}";
|
|
|
|
|
}
|
|
|
|
|
return string();
|
|
|
|
|
}
|