scramble email addresses
[lyx.git] / src / Spacing.cpp
blobd2ed1acd80dee85017672f17af7b4eb088d7d4ec
1 /**
2 * \file Spacing.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
12 #include <config.h>
14 #include "Spacing.h"
15 #include "support/lstrings.h"
16 #include "support/convert.h"
18 #include <sstream>
19 #include <string>
22 namespace lyx {
25 using std::ostream;
26 using std::ostringstream;
27 using std::string;
30 string const Spacing::spacing_string[]
31 = {"single", "onehalf", "double", "other"};
34 string const Spacing::getValueAsString() const
36 switch (space) {
37 case Default: // nothing special should happen with this...
38 case Single: return "1.0";
39 case Onehalf: return "1.25";
40 case Double: return "1.667";
41 case Other: return value;
43 return "1.0";
47 double Spacing::getValue() const
49 return convert<double>(getValueAsString());
53 void Spacing::set(Spacing::Space sp, double val)
55 set(sp, convert<string>(val));
59 void Spacing::set(Spacing::Space sp, string const & val)
61 space = sp;
62 if (sp == Other) {
63 switch (int(convert<double>(val) * 1000 + 0.5)) {
64 case 1000:
65 space = Single;
66 break;
67 case 1250:
68 space = Onehalf;
69 break;
70 case 1667:
71 space = Double;
72 break;
73 default:
74 value = val;
75 break;
81 void Spacing::writeFile(ostream & os, bool para) const
83 if (space == Default) return;
85 string cmd = para ? "\\paragraph_spacing " : "\\spacing ";
87 if (getSpace() == Spacing::Other) {
88 os << cmd << spacing_string[getSpace()]
89 << ' ' << getValueAsString() << "\n";
90 } else {
91 os << cmd << spacing_string[getSpace()] << "\n";
96 string const Spacing::writeEnvirBegin() const
98 switch (space) {
99 case Default: break; // do nothing
100 case Single:
101 return "\\begin{singlespace}";
102 case Onehalf:
103 return "\\begin{onehalfspace}";
104 case Double:
105 return "\\begin{doublespace}";
106 case Other:
108 ostringstream ost;
109 ost << "\\begin{spacing}{"
110 << getValueAsString() << '}';
111 return ost.str();
114 return string();
118 string const Spacing::writeEnvirEnd() const
120 switch (space) {
121 case Default: break; // do nothing
122 case Single:
123 return "\\end{singlespace}";
124 case Onehalf:
125 return "\\end{onehalfspace}";
126 case Double:
127 return "\\end{doublespace}";
128 case Other:
129 return "\\end{spacing}";
131 return string();
135 } // namespace lyx