]> git.lyx.org Git - lyx.git/blob - src/lyxgluelength.C
"Inter-word Space"
[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 #include "lyxgluelength.h"
14 #include "lengthcommon.h"
15
16 #include "Lsstream.h"
17
18
19 LyXGlueLength::LyXGlueLength(LyXLength const & len)
20         : len_(len)
21 {}
22
23
24 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
25                 LyXLength const & minus)
26         : len_(len), plus_(plus), minus_(minus)
27 {}
28
29
30 LyXGlueLength::LyXGlueLength(string const & data)
31 {
32         isValidGlueLength(data, this);
33 }
34
35
36 string const LyXGlueLength::asString() const
37 {
38         ostringstream buffer;
39
40         buffer << len_.value();
41
42         if (plus_.zero() && minus_.zero()) {
43                 buffer << unit_name[len_.unit()];
44                 return STRCONV(buffer.str());
45         }
46
47         // just len and plus
48         if (minus_.zero()) {
49                 if (len_.unit() != plus_.unit())
50                         buffer << unit_name[len_.unit()];
51                 buffer << '+' << plus_.value();
52                 buffer << unit_name[plus_.unit()];
53                 return STRCONV(buffer.str());
54         }
55
56         // just len and minus
57         if (plus_.zero()) {
58                 if (len_.unit() != minus_.unit())
59                         buffer << unit_name[len_.unit()];
60                 buffer << '-' << minus_.value();
61                 buffer << unit_name[minus_.unit()];
62                 return STRCONV(buffer.str());
63         }
64
65         // ok, len, plus AND minus
66
67         // len+-
68         if (minus_ == plus_) {
69                 if (len_.unit() != minus_.unit())
70                         buffer << unit_name[len_.unit()];
71                 buffer << "+-" << minus_.value();
72                 buffer << unit_name[minus_.unit()];
73                 return STRCONV(buffer.str());
74         }
75
76         // this is so rare a case, why bother minimising units ?
77
78         buffer << unit_name[len_.unit()];
79         buffer << '+' << plus_.value() << unit_name[plus_.unit()];
80         buffer << '-' << minus_.value() << unit_name[minus_.unit()];
81
82         return STRCONV(buffer.str());
83 }
84
85
86 string const LyXGlueLength::asLatexString() const
87 {
88         ostringstream buffer;
89
90         buffer << len_.value() << unit_name[len_.unit()];
91
92         if (!plus_.zero())
93                 buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
94         if (!minus_.zero())
95                 buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
96         return STRCONV(buffer.str());
97 }
98
99
100 LyXLength const & LyXGlueLength::len() const
101 {
102         return len_;
103 }
104
105
106 LyXLength const & LyXGlueLength::plus() const
107 {
108         return plus_;
109 }
110
111
112 LyXLength const & LyXGlueLength::minus() const
113 {
114         return minus_;
115 }
116
117
118 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
119 {
120         return l1.len() == l2.len()
121                  && l1.plus() == l2.plus()
122                  && l1.minus() == l2.minus();
123 }
124
125
126 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)
127 {
128         return !(l1 == l2);
129 }