]> git.lyx.org Git - lyx.git/blob - src/HSpace.cpp
prepare Qt 5.6 builds
[lyx.git] / src / HSpace.cpp
1 /**
2  * \file HSpace.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Spitzmüller
7  * \author Uwe Stöhr
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "HSpace.h"
15
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "BufferView.h"
19 #include "support/gettext.h"
20 #include "Length.h"
21 #include "Text.h"
22
23 #include "support/lstrings.h"
24
25 #include "support/lassert.h"
26
27 using namespace std;
28 using namespace lyx::support;
29
30
31 namespace lyx {
32
33
34 HSpace::HSpace()
35         : kind_(DEFAULT), len_()
36 {}
37
38
39 HSpace::HSpace(HSpaceKind k)
40         : kind_(k), len_()
41 {}
42
43
44 HSpace::HSpace(Length const & l)
45         : kind_(LENGTH), len_(l)
46 {}
47
48
49 HSpace::HSpace(GlueLength const & l)
50         : kind_(LENGTH), len_(l)
51 {}
52
53
54 HSpace::HSpace(string const & data)
55         : kind_(DEFAULT), len_()
56 {
57         if (data.empty())
58                 return;
59
60         string input = rtrim(data);
61
62         if (prefixIs(input, "default"))
63                 kind_ = DEFAULT;
64         else if (isValidGlueLength(input, &len_))
65                 kind_ = LENGTH;
66 }
67
68
69 bool HSpace::operator==(HSpace const & other) const
70 {
71         if (kind_ != other.kind_)
72                 return false;
73         if (len_ != other.len_)
74                 return false;
75         return true;
76 }
77
78
79 string const HSpace::asLyXCommand() const
80 {
81         string result;
82         switch (kind_) {
83         case DEFAULT:
84                 result = "default";
85                 break;
86         case LENGTH:
87                 result = len_.asString();
88                 break;
89         }
90         return result;
91 }
92
93
94 string const HSpace::asLatexCommand() const
95 {
96         switch (kind_) {
97         case DEFAULT:
98                 return string();
99         case LENGTH:
100                 return len_.asLatexString();
101         default:
102                 LATTEST(false);
103                 // fall through in release mode
104         }
105         return string();
106 }
107
108
109 docstring const HSpace::asGUIName() const
110 {
111         docstring result;
112         switch (kind_) {
113         case DEFAULT:
114                 result = _("Default");
115                 break;
116         case LENGTH:
117                 result = from_ascii(len_.asString());
118                 break;
119         }
120         return result;
121 }
122
123
124 string HSpace::asHTMLLength() const 
125 {
126         string result;
127         switch (kind_) {
128         case DEFAULT:
129                 // 30pt are LaTeX's default
130                 result = "30pt";
131                 break;
132         case LENGTH: {
133                 Length tmp = len_.len();
134                 if (tmp.value() > 0)
135                         result = tmp.asHTMLString();
136                 break;
137                 }
138         }
139         return result;
140 }
141
142
143 int HSpace::inPixels(BufferView const & bv) const
144 {
145         switch (kind_) {
146         case DEFAULT:
147                 // FIXME: replace by correct length
148                 return bv.buffer().params().getIndentation().inPixels(bv);
149         case LENGTH:
150                 return len_.len().inPixels(bv.workWidth());
151         default:
152                 LATTEST(false);
153                 // fall through in release mode
154         }
155         return 0;
156 }
157
158
159 } // namespace lyx