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"
24 // this is now here and in lyxlenght.h
26 int const num_units = LyXLength::UNIT_NONE;
28 // I am not sure if "mu" should be possible to select (Lgb)
29 char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
30 "mm", "pc", "cc", "cm",
31 "in", "ex", "em", "mu",
32 "%", "c%", "p%", "l%" };
37 LyXGlueLength::LyXGlueLength(LyXLength const & len)
42 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
43 LyXLength const & minus)
44 : len_(len), plus_(plus), minus_(minus)
48 LyXGlueLength::LyXGlueLength(string const & data)
50 isValidGlueLength(data, this);
54 string const LyXGlueLength::asString() const
60 if (len_.unit() == plus_.unit() && len_.unit() == minus_.unit())
61 if (plus_.value() == minus_.value())
62 buffer << len_.value() << "+-"
63 << plus_.value() << unit_name[len_.unit()];
65 buffer << len_.value()
66 << '+' << plus_.value()
67 << '-' << minus_.value()
68 << unit_name[len_.unit()];
70 if (plus_.unit() == minus_.unit()
71 && plus_.value() == minus_.value())
72 buffer << len_.value() << unit_name[len_.unit()]
73 << "+-" << plus_.value()
74 << unit_name[plus_.unit()];
77 buffer << len_.value() << unit_name[len_.unit()]
78 << '+' << plus_.value()
79 << unit_name[plus_.unit()]
80 << '-' << minus_.value()
81 << unit_name[minus_.unit()];
83 if (len_.unit() == plus_.unit())
84 buffer << len_.value() << '+' << plus_.value()
85 << unit_name[len_.unit()];
87 buffer << len_.value() << unit_name[len_.unit()]
88 << '+' << plus_.value()
89 << unit_name[plus_.unit()];
93 if (len_.unit() == minus_.unit())
94 buffer << len_.value() << '-' << minus_.value()
95 << unit_name[len_.unit()];
98 buffer << len_.value() << unit_name[len_.unit()]
99 << '-' << minus_.value()
100 << unit_name[minus_.unit()];
102 buffer << len_.value() << unit_name[len_.unit()];
104 return buffer.str().c_str();
108 string const LyXGlueLength::asLatexString() const
110 ostringstream buffer;
114 buffer << len_.value() << unit_name[len_.unit()]
116 << plus_.value() << unit_name[plus_.unit()]
118 << minus_.value() << unit_name[minus_.unit()];
120 buffer << len_.value() << unit_name[len_.unit()]
122 << plus_.value() << unit_name[plus_.unit()];
125 buffer << len_.value() << unit_name[len_.unit()]
127 << minus_.value() << unit_name[minus_.unit()];
129 buffer << len_.value() << unit_name[len_.unit()];
131 return buffer.str().c_str();
135 LyXLength const & LyXGlueLength::len() const
141 LyXLength const & LyXGlueLength::plus() const
147 LyXLength const & LyXGlueLength::minus() const
153 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
155 return l1.len() == l2.len()
156 && l1.plus() == l2.plus()
157 && l1.minus() == l2.minus();
161 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)