3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Matthias Ettrich
8 * Full author contact details are available in file CREDITS.
16 #include "BufferParams.h"
17 #include "BufferView.h"
18 #include "support/gettext.h"
19 #include "TextMetrics.h" // for defaultRowHeight()
21 #include "support/convert.h"
22 #include "support/Length.h"
23 #include "support/lstrings.h"
25 #include "support/lassert.h"
28 using namespace lyx::support;
38 : kind_(DEFSKIP), len_(), keep_(false)
42 VSpace::VSpace(VSpaceKind k)
43 : kind_(k), len_(), keep_(false)
47 VSpace::VSpace(Length const & l)
48 : kind_(LENGTH), len_(l), keep_(false)
52 VSpace::VSpace(GlueLength const & l)
53 : kind_(LENGTH), len_(l), keep_(false)
57 VSpace::VSpace(string const & data)
58 : kind_(DEFSKIP), len_(), keep_(false)
63 string input = rtrim(data);
65 size_t const length = input.length();
67 if (length > 1 && input[length - 1] == '*') {
69 input.erase(length - 1);
72 if (prefixIs(input, "defskip"))
74 else if (prefixIs(input, "smallskip"))
76 else if (prefixIs(input, "medskip"))
78 else if (prefixIs(input, "bigskip"))
80 else if (prefixIs(input, "halfline"))
82 else if (prefixIs(input, "fullline"))
84 else if (prefixIs(input, "vfill"))
86 else if (isValidGlueLength(input, &len_))
88 else if (isStrDbl(input)) {
89 // This last one is for reading old .lyx files
90 // without units in added_space_top/bottom.
91 // Let unit default to centimeters here.
93 len_ = GlueLength(Length(convert<double>(input), Length::CM));
98 bool VSpace::operator==(VSpace const & other) const
100 if (kind_ != other.kind_)
104 return this->keep_ == other.keep_;
106 if (len_ != other.len_)
109 return keep_ == other.keep_;
113 string const VSpace::asLyXCommand() const
121 result = "smallskip";
139 result = len_.asString();
148 string const VSpace::asLatexCommand(BufferParams const & params) const
152 return params.getDefSkip().asLatexCommand(params);
155 return keep_ ? "\\vspace*{\\smallskipamount}" : "\\smallskip{}";
158 return keep_ ? "\\vspace*{\\medskipamount}" : "\\medskip{}";
161 return keep_ ? "\\vspace*{\\bigskipamount}" : "\\bigskip{}";
164 return keep_ ? "\\vspace*{.5\\baselineskip}" : "\\vspace{.5\\baselineskip}";
167 return keep_ ? "\\vspace*{\\baselineskip}" : "\\vspace{\\baselineskip}";
170 return keep_ ? "\\vspace*{\\fill}" : "\\vfill{}";
173 return keep_ ? "\\vspace*{" + len_.asLatexString() + '}'
174 : "\\vspace{" + len_.asLatexString() + '}';
178 // fall through in release mode
184 docstring const VSpace::asGUIName() const
189 result = _("Default skip");
192 result = _("Small skip");
195 result = _("Medium skip");
198 result = _("Big skip");
201 result = _("Half line height");
204 result = _("Line height");
207 result = _("Vertical fill");
210 result = from_ascii(len_.asString());
214 result += ", " + _("protected");
219 string VSpace::asHTMLLength() const
242 Length tmp = len_.len();
244 result = tmp.asHTMLString();
253 int VSpace::inPixels(BufferView const & bv) const
255 // Height of a normal line in pixels (zoom factor considered)
256 int const default_height = defaultRowHeight();
261 return bv.buffer().params().getDefSkip().inPixels(bv);
263 // This is how the skips are normally defined by LaTeX.
264 // But there should be some way to change this per document.
266 return default_height / 4;
269 return default_height / 2;
272 return default_height;
275 // leave space for the vfill symbol
276 return 3 * default_height;
279 return default_height / 2;
282 return default_height;
285 return bv.inPixels(len_.len());
289 // fall through in release mode