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"
18 #include "support/std_sstream.h"
20 using std::ostringstream;
23 LyXGlueLength::LyXGlueLength(LyXLength const & len)
28 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
29 LyXLength const & minus)
30 : len_(len), plus_(plus), minus_(minus)
34 LyXGlueLength::LyXGlueLength(string const & data)
36 isValidGlueLength(data, this);
40 string const LyXGlueLength::asString() const
44 buffer << len_.value();
46 if (plus_.zero() && minus_.zero()) {
47 buffer << unit_name[len_.unit()];
53 if (len_.unit() != plus_.unit())
54 buffer << unit_name[len_.unit()];
55 buffer << '+' << plus_.value();
56 buffer << unit_name[plus_.unit()];
62 if (len_.unit() != minus_.unit())
63 buffer << unit_name[len_.unit()];
64 buffer << '-' << minus_.value();
65 buffer << unit_name[minus_.unit()];
69 // ok, len, plus AND minus
72 if (minus_ == plus_) {
73 if (len_.unit() != minus_.unit())
74 buffer << unit_name[len_.unit()];
75 buffer << "+-" << minus_.value();
76 buffer << unit_name[minus_.unit()];
80 // this is so rare a case, why bother minimising units ?
82 buffer << unit_name[len_.unit()];
83 buffer << '+' << plus_.value() << unit_name[plus_.unit()];
84 buffer << '-' << minus_.value() << unit_name[minus_.unit()];
90 string const LyXGlueLength::asLatexString() const
94 buffer << len_.value() << unit_name[len_.unit()];
97 buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
99 buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
104 LyXLength const & LyXGlueLength::len() const
110 LyXLength const & LyXGlueLength::plus() const
116 LyXLength const & LyXGlueLength::minus() const
122 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
124 return l1.len() == l2.len()
125 && l1.plus() == l2.plus()
126 && l1.minus() == l2.minus();
130 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)