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