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"
21 #include "TextMetrics.h" // for defaultRowHeight()
23 #include "support/convert.h"
24 #include "support/lstrings.h"
26 #include "support/lassert.h"
29 using namespace lyx::support;
39 : kind_(DEFSKIP), len_(), keep_(false)
43 VSpace::VSpace(VSpaceKind k)
44 : kind_(k), len_(), keep_(false)
48 VSpace::VSpace(Length const & l)
49 : kind_(LENGTH), len_(l), keep_(false)
53 VSpace::VSpace(GlueLength const & l)
54 : kind_(LENGTH), len_(l), keep_(false)
58 VSpace::VSpace(string const & data)
59 : kind_(DEFSKIP), len_(), keep_(false)
64 string input = rtrim(data);
66 size_t const length = input.length();
68 if (length > 1 && input[length - 1] == '*') {
70 input.erase(length - 1);
73 if (prefixIs(input, "defskip"))
75 else if (prefixIs(input, "smallskip"))
77 else if (prefixIs(input, "medskip"))
79 else if (prefixIs(input, "bigskip"))
81 else if (prefixIs(input, "halfline"))
83 else if (prefixIs(input, "fullline"))
85 else if (prefixIs(input, "vfill"))
87 else if (isValidGlueLength(input, &len_))
89 else if (isStrDbl(input)) {
90 // This last one is for reading old .lyx files
91 // without units in added_space_top/bottom.
92 // Let unit default to centimeters here.
94 len_ = GlueLength(Length(convert<double>(input), Length::CM));
99 bool VSpace::operator==(VSpace const & other) const
101 if (kind_ != other.kind_)
105 return this->keep_ == other.keep_;
107 if (len_ != other.len_)
110 return keep_ == other.keep_;
114 string const VSpace::asLyXCommand() const
122 result = "smallskip";
140 result = len_.asString();
149 string const VSpace::asLatexCommand(BufferParams const & params) const
153 return params.getDefSkip().asLatexCommand(params);
156 return keep_ ? "\\vspace*{\\smallskipamount}" : "\\smallskip{}";
159 return keep_ ? "\\vspace*{\\medskipamount}" : "\\medskip{}";
162 return keep_ ? "\\vspace*{\\bigskipamount}" : "\\bigskip{}";
165 return keep_ ? "\\vspace*{.5\\baselineskip}" : "\\vspace{.5\\baselineskip}";
168 return keep_ ? "\\vspace*{\\baselineskip}" : "\\vspace{\\baselineskip}";
171 return keep_ ? "\\vspace*{\\fill}" : "\\vfill{}";
174 return keep_ ? "\\vspace*{" + len_.asLatexString() + '}'
175 : "\\vspace{" + len_.asLatexString() + '}';
179 // fall through in release mode
185 docstring const VSpace::asGUIName() const
190 result = _("Default skip");
193 result = _("Small skip");
196 result = _("Medium skip");
199 result = _("Big skip");
202 result = _("Half line height");
205 result = _("Line height");
208 result = _("Vertical fill");
211 result = from_ascii(len_.asString());
215 result += ", " + _("protected");
220 string VSpace::asHTMLLength() const
243 Length tmp = len_.len();
245 result = tmp.asHTMLString();
254 int VSpace::inPixels(BufferView const & bv) const
256 // Height of a normal line in pixels (zoom factor considered)
257 int const default_height = defaultRowHeight();
262 return bv.buffer().params().getDefSkip().inPixels(bv);
264 // This is how the skips are normally defined by LaTeX.
265 // But there should be some way to change this per document.
267 return int(default_height / 4);
270 return int(default_height / 2);
273 return default_height;
276 // leave space for the vfill symbol
277 return 3 * default_height;
280 return int(default_height / 2);
283 return default_height;
286 return bv.inPixels(len_.len());
290 // fall through in release mode