1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SSTREAM
|
|
|
|
#include <sstream>
|
|
|
|
using std::istringstream;
|
2000-04-19 01:42:55 +00:00
|
|
|
using std::ostringstream;
|
2000-03-28 02:18:55 +00:00
|
|
|
#else
|
|
|
|
#include <strstream>
|
|
|
|
#endif
|
|
|
|
|
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)
|
|
|
|
static
|
1999-12-07 00:44:53 +00:00
|
|
|
char const * spacing_string[] = {"single", "onehalf", "double", "other"};
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
float Spacing::getValue() const
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
switch(int(val * 1000 + 0.5)) {
|
|
|
|
case 1000: space = Single; break;
|
|
|
|
case 1250: space = Onehalf; break;
|
|
|
|
case 1667: space = Double; break;
|
|
|
|
default: value = val; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Spacing::set(Spacing::Space sp, char const * val)
|
|
|
|
{
|
|
|
|
float fval;
|
|
|
|
#ifdef HAVE_SSTREAM
|
|
|
|
istringstream istr(val);
|
|
|
|
#else
|
|
|
|
istrstream istr(val);
|
|
|
|
#endif
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
string Spacing::writeEnvirBegin() const
|
|
|
|
{
|
|
|
|
switch(space) {
|
|
|
|
case Default: break; // do nothing
|
|
|
|
case Single:
|
|
|
|
return "\\begin{singlespace}";
|
|
|
|
case Onehalf:
|
|
|
|
return "\\begin{onehalfspace}";
|
|
|
|
case Double:
|
|
|
|
return "\\begin{doublespace}";
|
|
|
|
case Other:
|
|
|
|
#ifdef HAVE_SSTREAM
|
|
|
|
ostringstream ost;
|
|
|
|
ost << "\\begin{spacing}{"
|
|
|
|
<< getValue() << "}";
|
|
|
|
return ost.str().c_str();
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
char tmp[512];
|
|
|
|
ostrstream ost(tmp, 512);
|
|
|
|
ost << "\\begin{spacing}{"
|
|
|
|
<< getValue() << "}";
|
|
|
|
return ost.str();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string Spacing::writeEnvirEnd() const
|
|
|
|
{
|
|
|
|
switch(space) {
|
|
|
|
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();
|
|
|
|
}
|