2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
2000-03-28 02:18:55 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
/// how can I put this inside of Spacing (class)
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
char const * const spacing_string[] = {"single", "onehalf", "double", "other"};
|
|
|
|
|
|
|
|
} // namespace anon
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
float Spacing::getValue() const
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
float fval;
|
2000-11-06 15:47:22 +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;
|
|
|
|
|
|
|
|
string cmd = para ? "\\paragraph_spacing " : "\\spacing ";
|
|
|
|
|
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()]
|
1999-12-07 00:44:53 +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";
|
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}{"
|
|
|
|
<< getValue() << "}";
|
|
|
|
return ost.str().c_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();
|
|
|
|
}
|