]> git.lyx.org Git - lyx.git/blob - src/lyxgluelength.C
1342bbf7dbf8acbaae124b3505c3de8e3805f3e3
[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 #if 0
23 namespace {
24 // this is now here and in lyxlenght.h
25
26 int const num_units = LyXLength::UNIT_NONE;
27
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%" };
33
34 }
35 #endif
36
37 LyXGlueLength::LyXGlueLength(LyXLength const & len)
38         : len_(len)
39 {}
40
41
42 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
43                 LyXLength const & minus)
44         : len_(len), plus_(plus), minus_(minus)
45 {}
46
47
48 LyXGlueLength::LyXGlueLength(string const & data)
49 {
50         isValidGlueLength(data, this);
51 }
52
53
54 string const LyXGlueLength::asString() const
55 {
56         ostringstream buffer;
57
58         if (!plus_.zero())
59                 if (!minus_.zero())
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()];
64                                 else
65                                         buffer << len_.value()
66                                                << '+' << plus_.value()
67                                                << '-' << minus_.value()
68                                                << unit_name[len_.unit()];
69                         else
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()];
75         
76                                 else
77                                         buffer << len_.value() << unit_name[len_.unit()]
78                                                << '+' << plus_.value()
79                                                << unit_name[plus_.unit()]
80                                                << '-' << minus_.value()
81                                                << unit_name[minus_.unit()];
82                 else
83                         if (len_.unit() == plus_.unit())
84                                 buffer << len_.value() << '+' << plus_.value()
85                                        << unit_name[len_.unit()];
86                         else
87                                 buffer << len_.value() << unit_name[len_.unit()]
88                                        << '+' << plus_.value()
89                                        << unit_name[plus_.unit()];
90         
91         else
92                 if (!minus_.zero())
93                         if (len_.unit() == minus_.unit())
94                                 buffer << len_.value() << '-' << minus_.value()
95                                        << unit_name[len_.unit()];
96         
97                         else
98                                 buffer << len_.value() << unit_name[len_.unit()]
99                                        << '-' << minus_.value()
100                                        << unit_name[minus_.unit()];
101                 else
102                         buffer << len_.value() << unit_name[len_.unit()];
103
104         return buffer.str().c_str();
105 }
106
107
108 string const LyXGlueLength::asLatexString() const
109 {
110         ostringstream buffer;
111
112         if (!plus_.zero())
113                 if (!minus_.zero())
114                         buffer << len_.value() << unit_name[len_.unit()]
115                                << " plus "
116                                << plus_.value() << unit_name[plus_.unit()]
117                                << " minus "
118                                << minus_.value() << unit_name[minus_.unit()];
119                 else
120                         buffer << len_.value() << unit_name[len_.unit()]
121                                << " plus "
122                                << plus_.value() << unit_name[plus_.unit()];
123         else
124                 if (!minus_.zero())
125                         buffer << len_.value() << unit_name[len_.unit()]
126                                << " minus "
127                                << minus_.value() << unit_name[minus_.unit()];
128                 else
129                         buffer << len_.value() << unit_name[len_.unit()];
130
131         return buffer.str().c_str();
132 }
133
134
135 LyXLength const & LyXGlueLength::len() const
136 {
137         return len_;
138 }
139
140
141 LyXLength const & LyXGlueLength::plus() const
142 {
143         return plus_;
144 }
145
146
147 LyXLength const & LyXGlueLength::minus() const
148 {
149         return minus_;
150 }
151
152
153 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
154 {
155         return l1.len() == l2.len()
156                  && l1.plus() == l2.plus()
157                  && l1.minus() == l2.minus();
158 }
159
160
161 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)
162 {
163         return !(l1 == l2);
164 }