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
46 if (len_.unit() == plus_.unit() && len_.unit() == minus_.unit())
47 if (plus_.value() == minus_.value())
48 buffer << len_.value() << "+-"
49 << plus_.value() << unit_name[len_.unit()];
51 buffer << len_.value()
52 << '+' << plus_.value()
53 << '-' << minus_.value()
54 << unit_name[len_.unit()];
56 if (plus_.unit() == minus_.unit()
57 && plus_.value() == minus_.value())
58 buffer << len_.value() << unit_name[len_.unit()]
59 << "+-" << plus_.value()
60 << unit_name[plus_.unit()];
63 buffer << len_.value() << unit_name[len_.unit()]
64 << '+' << plus_.value()
65 << unit_name[plus_.unit()]
66 << '-' << minus_.value()
67 << unit_name[minus_.unit()];
69 if (len_.unit() == plus_.unit())
70 buffer << len_.value() << '+' << plus_.value()
71 << unit_name[len_.unit()];
73 buffer << len_.value() << unit_name[len_.unit()]
74 << '+' << plus_.value()
75 << unit_name[plus_.unit()];
79 if (len_.unit() == minus_.unit())
80 buffer << len_.value() << '-' << minus_.value()
81 << unit_name[len_.unit()];
84 buffer << len_.value() << unit_name[len_.unit()]
85 << '-' << minus_.value()
86 << unit_name[minus_.unit()];
88 buffer << len_.value() << unit_name[len_.unit()];
90 return buffer.str().c_str();
94 string const LyXGlueLength::asLatexString() const
100 buffer << len_.value() << unit_name[len_.unit()]
102 << plus_.value() << unit_name[plus_.unit()]
104 << minus_.value() << unit_name[minus_.unit()];
106 buffer << len_.value() << unit_name[len_.unit()]
108 << plus_.value() << unit_name[plus_.unit()];
111 buffer << len_.value() << unit_name[len_.unit()]
113 << minus_.value() << unit_name[minus_.unit()];
115 buffer << len_.value() << unit_name[len_.unit()];
117 return buffer.str().c_str();
121 LyXLength const & LyXGlueLength::len() const
127 LyXLength const & LyXGlueLength::plus() const
133 LyXLength const & LyXGlueLength::minus() const
139 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
141 return l1.len() == l2.len()
142 && l1.plus() == l2.plus()
143 && l1.minus() == l2.minus();
147 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)