2 * \file lyxgluelength.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Matthias Ettrich
10 * Full author contact details are available in file CREDITS.
15 #include "lyxgluelength.h"
16 #include "lengthcommon.h"
23 using std::ostringstream;
27 LyXGlueLength::LyXGlueLength(LyXLength const & len)
32 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
33 LyXLength const & minus)
34 : len_(len), plus_(plus), minus_(minus)
38 LyXGlueLength::LyXGlueLength(string const & data)
40 isValidGlueLength(data, this);
44 string const LyXGlueLength::asString() const
48 buffer << len_.value();
50 if (plus_.zero() && minus_.zero()) {
51 buffer << unit_name[len_.unit()];
57 if (len_.unit() != plus_.unit())
58 buffer << unit_name[len_.unit()];
59 buffer << '+' << plus_.value();
60 buffer << unit_name[plus_.unit()];
66 if (len_.unit() != minus_.unit())
67 buffer << unit_name[len_.unit()];
68 buffer << '-' << minus_.value();
69 buffer << unit_name[minus_.unit()];
73 // ok, len, plus AND minus
76 if (minus_ == plus_) {
77 if (len_.unit() != minus_.unit())
78 buffer << unit_name[len_.unit()];
79 buffer << "+-" << minus_.value();
80 buffer << unit_name[minus_.unit()];
84 // this is so rare a case, why bother minimising units ?
86 buffer << unit_name[len_.unit()];
87 buffer << '+' << plus_.value() << unit_name[plus_.unit()];
88 buffer << '-' << minus_.value() << unit_name[minus_.unit()];
94 string const LyXGlueLength::asLatexString() const
98 buffer << len_.value() << unit_name[len_.unit()];
101 buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
103 buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
108 LyXLength const & LyXGlueLength::len() const
114 LyXLength const & LyXGlueLength::plus() const
120 LyXLength const & LyXGlueLength::minus() const
126 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
128 return l1.len() == l2.len()
129 && l1.plus() == l2.plus()
130 && l1.minus() == l2.minus();
134 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)