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"
22 // this is now here and in lyxlenght.h
24 int const num_units = LyXLength::UNIT_NONE;
26 // I am not sure if "mu" should be possible to select (Lgb)
27 char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
28 "mm", "pc", "cc", "cm",
29 "in", "ex", "em", "mu",
30 "%", "c%", "p%", "l%" };
35 LyXGlueLength::LyXGlueLength(LyXLength const & len)
40 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
41 LyXLength const & minus)
42 : len_(len), plus_(plus), minus_(minus)
46 LyXGlueLength::LyXGlueLength(string const & data)
48 isValidGlueLength(data, this);
52 string const LyXGlueLength::asString() const
56 if (plus_.value() != 0.0)
57 if (minus_.value() != 0.0)
58 if (len_.unit() == plus_.unit() && len_.unit() == minus_.unit())
59 if (plus_.value() == minus_.value())
60 buffer << len_.value() << "+-"
61 << plus_.value() << unit_name[len_.unit()];
63 buffer << len_.value()
64 << '+' << plus_.value()
65 << '-' << minus_.value()
66 << unit_name[len_.unit()];
68 if (plus_.unit() == minus_.unit()
69 && plus_.value() == minus_.value())
70 buffer << len_.value() << unit_name[len_.unit()]
71 << "+-" << plus_.value()
72 << unit_name[plus_.unit()];
75 buffer << len_.value() << unit_name[len_.unit()]
76 << '+' << plus_.value()
77 << unit_name[plus_.unit()]
78 << '-' << minus_.value()
79 << unit_name[minus_.unit()];
81 if (len_.unit() == plus_.unit())
82 buffer << len_.value() << '+' << plus_.value()
83 << unit_name[len_.unit()];
85 buffer << len_.value() << unit_name[len_.unit()]
86 << '+' << plus_.value()
87 << unit_name[plus_.unit()];
90 if (minus_.value() != 0.0)
91 if (len_.unit() == minus_.unit())
92 buffer << len_.value() << '-' << minus_.value()
93 << unit_name[len_.unit()];
96 buffer << len_.value() << unit_name[len_.unit()]
97 << '-' << minus_.value()
98 << unit_name[minus_.unit()];
100 buffer << len_.value() << unit_name[len_.unit()];
102 return buffer.str().c_str();
106 string const LyXGlueLength::asLatexString() const
108 ostringstream buffer;
110 if (plus_.value() != 0.0)
111 if (minus_.value() != 0.0)
112 buffer << len_.value() << unit_name[len_.unit()]
114 << plus_.value() << unit_name[plus_.unit()]
116 << minus_.value() << unit_name[minus_.unit()];
118 buffer << len_.value() << unit_name[len_.unit()]
120 << plus_.value() << unit_name[plus_.unit()];
122 if (minus_.value() != 0.0)
123 buffer << len_.value() << unit_name[len_.unit()]
125 << minus_.value() << unit_name[minus_.unit()];
127 buffer << len_.value() << unit_name[len_.unit()];
129 return buffer.str().c_str();
133 LyXLength const & LyXGlueLength::len() const
139 LyXLength const & LyXGlueLength::plus() const
145 LyXLength const & LyXGlueLength::minus() const
151 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
153 return l1.len() == l2.len()
154 && l1.plus() == l2.plus()
155 && l1.minus() == l2.minus();
159 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)