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.
15 #include "support/lstrings.h"
16 #include "support/convert.h"
25 string
const Spacing::spacing_string
[]
26 = {"single", "onehalf", "double", "other"};
29 string
const Spacing::getValueAsString() const
32 case Default
: // nothing special should happen with this...
33 case Single
: return "1.0";
34 case Onehalf
: return "1.25";
35 case Double
: return "1.667";
36 case Other
: return value
;
42 double Spacing::getValue() const
44 return convert
<double>(getValueAsString());
48 void Spacing::set(Spacing::Space sp
, double val
)
50 set(sp
, convert
<string
>(val
));
54 void Spacing::set(Spacing::Space sp
, string
const & val
)
58 switch (int(convert
<double>(val
) * 1000 + 0.5)) {
76 void Spacing::writeFile(ostream
& os
, bool para
) const
78 if (space
== Default
) return;
80 string cmd
= para
? "\\paragraph_spacing " : "\\spacing ";
82 if (getSpace() == Spacing::Other
) {
83 os
<< cmd
<< spacing_string
[getSpace()]
84 << ' ' << getValueAsString() << "\n";
86 os
<< cmd
<< spacing_string
[getSpace()] << "\n";
93 string
envName(Spacing::Space space
, bool useSetSpace
)
95 static char const * const env_names
[]
96 = { "SingleSpace", "OnehalfSpace", "DoubleSpace", "Spacing", ""};
97 string
const name
= env_names
[space
];
99 return useSetSpace
? name
: support::ascii_lowercase(name
);
104 string
const Spacing::writeEnvirBegin(bool useSetSpace
) const
106 string
const name
= envName(space
, useSetSpace
);
108 return "\\begin{" + name
+ "}{" + getValueAsString() + '}';
110 return name
.empty() ? string() : "\\begin{" + name
+ '}';
114 string
const Spacing::writeEnvirEnd(bool useSetSpace
) const
116 string
const name
= envName(space
, useSetSpace
);
117 return name
.empty() ? string() : "\\end{" + name
+ '}';
121 string
const Spacing::writePreamble(bool useSetSpace
) const
127 // we dont use setspace.sty so dont print anything
128 //return "\\singlespacing\n";
131 preamble
= useSetSpace
? "\\OnehalfSpacing\n"
132 : "\\onehalfspacing\n";
135 preamble
= useSetSpace
? "\\DoubleSpacing\n"
136 : "\\doublespacing\n";
139 preamble
= (useSetSpace
? "\\setSpacing{" : "\\setstretch{")
140 + getValueAsString() + "}\n";