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"
21 LyXGlueLength::LyXGlueLength(LyXLength const & len)
26 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
27 LyXLength const & minus)
28 : len_(len), plus_(plus), minus_(minus)
32 LyXGlueLength::LyXGlueLength(string const & data)
34 isValidGlueLength(data, this);
38 string const LyXGlueLength::asString() const
42 buffer << len_.value();
44 if (plus_.zero() && minus_.zero()) {
45 buffer << unit_name[len_.unit()];
46 return STRCONV(buffer.str());
51 if (len_.unit() != plus_.unit())
52 buffer << unit_name[len_.unit()];
53 buffer << '+' << plus_.value();
54 buffer << unit_name[plus_.unit()];
55 return STRCONV(buffer.str());
60 if (len_.unit() != minus_.unit())
61 buffer << unit_name[len_.unit()];
62 buffer << '-' << minus_.value();
63 buffer << unit_name[minus_.unit()];
64 return STRCONV(buffer.str());
67 // ok, len, plus AND minus
70 if (minus_ == plus_) {
71 if (len_.unit() != minus_.unit())
72 buffer << unit_name[len_.unit()];
73 buffer << "+-" << minus_.value();
74 buffer << unit_name[minus_.unit()];
75 return STRCONV(buffer.str());
78 // this is so rare a case, why bother minimising units ?
80 buffer << unit_name[len_.unit()];
81 buffer << '+' << plus_.value() << unit_name[plus_.unit()];
82 buffer << '-' << minus_.value() << unit_name[minus_.unit()];
84 return STRCONV(buffer.str());
88 string const LyXGlueLength::asLatexString() const
92 buffer << len_.value() << unit_name[len_.unit()];
95 buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
97 buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
98 return STRCONV(buffer.str());
102 LyXLength const & LyXGlueLength::len() const
108 LyXLength const & LyXGlueLength::plus() const
114 LyXLength const & LyXGlueLength::minus() const
120 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
122 return l1.len() == l2.len()
123 && l1.plus() == l2.plus()
124 && l1.minus() == l2.minus();
128 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)