2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
2000-07-24 13:53:19 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2000-07-24 13:53:19 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-07-24 13:53:19 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
#include "Lsstream.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "Spacing.h"
|
2000-04-11 22:55:29 +00:00
|
|
|
#include "LString.h"
|
2000-03-28 02:18:55 +00:00
|
|
|
|
1999-12-07 10:49:58 +00:00
|
|
|
using std::ios;
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
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
|
|
|
|
|
|
|
float Spacing::getValue() 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...
|
2000-03-28 02:18:55 +00:00
|
|
|
case Single: return 1.0;
|
|
|
|
case Onehalf: return 1.25;
|
|
|
|
case Double: return 1.667;
|
|
|
|
case Other: return value;
|
|
|
|
}
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Spacing::set(Spacing::Space sp, float val)
|
|
|
|
{
|
|
|
|
space = sp;
|
|
|
|
if (sp == Other) {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (int(val * 1000 + 0.5)) {
|
2000-03-28 02:18:55 +00:00
|
|
|
case 1000: space = Single; break;
|
|
|
|
case 1250: space = Onehalf; break;
|
|
|
|
case 1667: space = Double; break;
|
|
|
|
default: value = val; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2001-08-18 10:54:33 +00:00
|
|
|
float fval = 0.0;
|
2001-06-29 11:54:39 +00:00
|
|
|
istringstream istr(val.c_str());
|
2000-03-28 02:18:55 +00:00
|
|
|
istr >> fval;
|
|
|
|
set(sp, fval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
1999-12-07 00:44:53 +00:00
|
|
|
os.setf(ios::showpoint|ios::fixed);
|
|
|
|
os.precision(2);
|
2000-04-11 22:55:29 +00:00
|
|
|
os << cmd << spacing_string[getSpace()]
|
2002-11-27 10:30:28 +00:00
|
|
|
<< ' ' << getValue() << " \n";
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
2000-04-11 22:55:29 +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}{"
|
2002-11-27 10:30:28 +00:00
|
|
|
<< getValue() << '}';
|
2002-11-04 02:12:42 +00:00
|
|
|
return STRCONV(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();
|
|
|
|
}
|