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 * ====================================================== */
13 #include "lyxgluelength.h"
14 #include "lengthcommon.h"
19 LyXGlueLength::LyXGlueLength(LyXLength const & len)
24 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
25 LyXLength const & minus)
26 : len_(len), plus_(plus), minus_(minus)
30 LyXGlueLength::LyXGlueLength(string const & data)
32 isValidGlueLength(data, this);
36 string const LyXGlueLength::asString() const
40 buffer << len_.value();
42 if (plus_.zero() && minus_.zero()) {
43 buffer << unit_name[len_.unit()];
44 return STRCONV(buffer.str());
49 if (len_.unit() != plus_.unit())
50 buffer << unit_name[len_.unit()];
51 buffer << '+' << plus_.value();
52 buffer << unit_name[plus_.unit()];
53 return STRCONV(buffer.str());
58 if (len_.unit() != minus_.unit())
59 buffer << unit_name[len_.unit()];
60 buffer << '-' << minus_.value();
61 buffer << unit_name[minus_.unit()];
62 return STRCONV(buffer.str());
65 // ok, len, plus AND minus
68 if (minus_ == plus_) {
69 if (len_.unit() != minus_.unit())
70 buffer << unit_name[len_.unit()];
71 buffer << "+-" << minus_.value();
72 buffer << unit_name[minus_.unit()];
73 return STRCONV(buffer.str());
76 // this is so rare a case, why bother minimising units ?
78 buffer << unit_name[len_.unit()];
79 buffer << '+' << plus_.value() << unit_name[plus_.unit()];
80 buffer << '-' << minus_.value() << unit_name[minus_.unit()];
82 return STRCONV(buffer.str());
86 string const LyXGlueLength::asLatexString() const
90 buffer << len_.value() << unit_name[len_.unit()];
93 buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
95 buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
96 return STRCONV(buffer.str());
100 LyXLength const & LyXGlueLength::len() const
106 LyXLength const & LyXGlueLength::plus() const
112 LyXLength const & LyXGlueLength::minus() const
118 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
120 return l1.len() == l2.len()
121 && l1.plus() == l2.plus()
122 && l1.minus() == l2.minus();
126 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)