2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lyxgluelength.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-12-02 23:47:06 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Matthias Ettrich
|
|
|
|
|
* \author John Levon
|
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.
|
|
|
|
|
*/
|
2001-12-02 23:47:06 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "lyxgluelength.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
|
#include "lengthcommon.h"
|
2001-12-02 23:47:06 +00:00
|
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
2001-12-02 23:47:06 +00:00
|
|
|
|
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
|
|
|
|
|
2001-12-02 23:47:06 +00:00
|
|
|
|
|
|
|
|
|
LyXGlueLength::LyXGlueLength(LyXLength const & len)
|
|
|
|
|
: len_(len)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
|
|
|
|
|
LyXLength const & minus)
|
|
|
|
|
: len_(len), plus_(plus), minus_(minus)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXGlueLength::LyXGlueLength(string const & data)
|
|
|
|
|
{
|
|
|
|
|
isValidGlueLength(data, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const LyXGlueLength::asString() const
|
|
|
|
|
{
|
|
|
|
|
ostringstream buffer;
|
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
buffer << len_.value();
|
|
|
|
|
|
|
|
|
|
if (plus_.zero() && minus_.zero()) {
|
|
|
|
|
buffer << unit_name[len_.unit()];
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(buffer.str());
|
2002-08-09 00:42:12 +00:00
|
|
|
|
}
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
// just len and plus
|
|
|
|
|
if (minus_.zero()) {
|
|
|
|
|
if (len_.unit() != plus_.unit())
|
|
|
|
|
buffer << unit_name[len_.unit()];
|
2002-11-27 10:30:28 +00:00
|
|
|
|
buffer << '+' << plus_.value();
|
2002-08-09 00:42:12 +00:00
|
|
|
|
buffer << unit_name[plus_.unit()];
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(buffer.str());
|
2002-08-09 00:42:12 +00:00
|
|
|
|
}
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
// just len and minus
|
|
|
|
|
if (plus_.zero()) {
|
|
|
|
|
if (len_.unit() != minus_.unit())
|
|
|
|
|
buffer << unit_name[len_.unit()];
|
2002-11-27 10:30:28 +00:00
|
|
|
|
buffer << '-' << minus_.value();
|
2002-08-09 00:42:12 +00:00
|
|
|
|
buffer << unit_name[minus_.unit()];
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(buffer.str());
|
2002-08-09 00:42:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok, len, plus AND minus
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
// len+-
|
|
|
|
|
if (minus_ == plus_) {
|
|
|
|
|
if (len_.unit() != minus_.unit())
|
|
|
|
|
buffer << unit_name[len_.unit()];
|
|
|
|
|
buffer << "+-" << minus_.value();
|
|
|
|
|
buffer << unit_name[minus_.unit()];
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(buffer.str());
|
2002-08-09 00:42:12 +00:00
|
|
|
|
}
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
// this is so rare a case, why bother minimising units ?
|
|
|
|
|
|
|
|
|
|
buffer << unit_name[len_.unit()];
|
2002-11-27 10:30:28 +00:00
|
|
|
|
buffer << '+' << plus_.value() << unit_name[plus_.unit()];
|
|
|
|
|
buffer << '-' << minus_.value() << unit_name[minus_.unit()];
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
|
|
|
|
return STRCONV(buffer.str());
|
2001-12-02 23:47:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const LyXGlueLength::asLatexString() const
|
|
|
|
|
{
|
|
|
|
|
ostringstream buffer;
|
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
buffer << len_.value() << unit_name[len_.unit()];
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
|
if (!plus_.zero())
|
2002-08-09 00:42:12 +00:00
|
|
|
|
buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
|
|
|
|
|
if (!minus_.zero())
|
|
|
|
|
buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(buffer.str());
|
2001-12-02 23:47:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXLength const & LyXGlueLength::len() const
|
|
|
|
|
{
|
|
|
|
|
return len_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXLength const & LyXGlueLength::plus() const
|
|
|
|
|
{
|
|
|
|
|
return plus_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXLength const & LyXGlueLength::minus() const
|
|
|
|
|
{
|
|
|
|
|
return minus_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
|
|
|
|
|
{
|
|
|
|
|
return l1.len() == l2.len()
|
2002-03-21 17:27:08 +00:00
|
|
|
|
&& l1.plus() == l2.plus()
|
|
|
|
|
&& l1.minus() == l2.minus();
|
2001-12-02 23:47:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)
|
|
|
|
|
{
|
|
|
|
|
return !(l1 == l2);
|
|
|
|
|
}
|