]> git.lyx.org Git - lyx.git/blob - src/lyxgluelength.C
update no.po
[lyx.git] / src / lyxgluelength.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "lyxgluelength.h"
18 #include "lengthcommon.h"
19
20 #include "Lsstream.h"
21
22
23 LyXGlueLength::LyXGlueLength(LyXLength const & len)
24         : len_(len)
25 {}
26
27
28 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
29                 LyXLength const & minus)
30         : len_(len), plus_(plus), minus_(minus)
31 {}
32
33
34 LyXGlueLength::LyXGlueLength(string const & data)
35 {
36         isValidGlueLength(data, this);
37 }
38
39
40 string const LyXGlueLength::asString() const
41 {
42         ostringstream buffer;
43
44         buffer << len_.value();
45
46         if (plus_.zero() && minus_.zero()) {
47                 buffer << unit_name[len_.unit()];
48                 return STRCONV(buffer.str());
49         }
50
51         // just len and plus
52         if (minus_.zero()) {
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());
58         }
59
60         // just len and minus
61         if (plus_.zero()) {
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());
67         }
68
69         // ok, len, plus AND minus
70
71         // len+-
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());
78         }
79
80         // this is so rare a case, why bother minimising units ?
81
82         buffer << unit_name[len_.unit()];
83         buffer << "+" << plus_.value() << unit_name[plus_.unit()];
84         buffer << "-" << minus_.value() << unit_name[minus_.unit()];
85
86         return STRCONV(buffer.str());
87 }
88
89
90 string const LyXGlueLength::asLatexString() const
91 {
92         ostringstream buffer;
93
94         buffer << len_.value() << unit_name[len_.unit()];
95
96         if (!plus_.zero())
97                 buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
98         if (!minus_.zero())
99                 buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
100         return STRCONV(buffer.str());
101 }
102
103
104 LyXLength const & LyXGlueLength::len() const
105 {
106         return len_;
107 }
108
109
110 LyXLength const & LyXGlueLength::plus() const
111 {
112         return plus_;
113 }
114
115
116 LyXLength const & LyXGlueLength::minus() const
117 {
118         return minus_;
119 }
120
121
122 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
123 {
124         return l1.len() == l2.len()
125                  && l1.plus() == l2.plus()
126                  && l1.minus() == l2.minus();
127 }
128
129
130 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)
131 {
132         return !(l1 == l2);
133 }