1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "lyxgluelength.h"
18 #include "lengthcommon.h"
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()];
48 return STRCONV(buffer.str());
53 if (len_.unit() != plus_.unit())
54 buffer << unit_name[len_.unit()];
55 buffer << "+" << plus_.value();
56 buffer << unit_name[plus_.unit()];
57 return STRCONV(buffer.str());
62 if (len_.unit() != minus_.unit())
63 buffer << unit_name[len_.unit()];
64 buffer << "-" << minus_.value();
65 buffer << unit_name[minus_.unit()];
66 return STRCONV(buffer.str());
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()];
77 return STRCONV(buffer.str());
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()];
86 return STRCONV(buffer.str());
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()];
100 return STRCONV(buffer.str());
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)