]> git.lyx.org Git - lyx.git/blob - src/Spacing.C
fix typo that put too many include paths for most people
[lyx.git] / src / Spacing.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "Lsstream.h"
18 #include "Spacing.h"
19 #include "LString.h"
20
21 using std::ios;
22 using std::ostream;
23
24 string const Spacing::spacing_string[]
25         = {"single", "onehalf", "double", "other"};
26
27 float Spacing::getValue() const
28 {
29         switch (space) {
30         case Default: // nothing special should happen with this...
31         case Single: return 1.0;
32         case Onehalf: return 1.25;
33         case Double: return 1.667;
34         case Other: return value;
35         }
36         return 1.0;
37 }
38
39
40 void Spacing::set(Spacing::Space sp, float val)
41 {
42         space = sp;
43         if (sp == Other) {
44                 switch (int(val * 1000 + 0.5)) {
45                 case 1000: space = Single; break;
46                 case 1250: space = Onehalf; break;
47                 case 1667: space = Double; break;
48                 default: value = val; break;
49                 }
50         }
51 }
52
53
54 void Spacing::set(Spacing::Space sp, string const & val)
55 {
56         float fval = 0.0;
57         istringstream istr(val.c_str());
58         istr >> fval;
59         set(sp, fval);
60 }
61
62
63 void Spacing::writeFile(ostream & os, bool para) const
64 {
65         if (space == Default) return;
66
67         string cmd = para ? "\\paragraph_spacing " : "\\spacing ";
68
69         if (getSpace() == Spacing::Other) {
70                 os.setf(ios::showpoint|ios::fixed);
71                 os.precision(2);
72                 os << cmd << spacing_string[getSpace()]
73                    << " " << getValue() << " \n";
74         } else {
75                 os << cmd << spacing_string[getSpace()] << " \n";
76         }
77 }
78
79
80 string const Spacing::writeEnvirBegin() const
81 {
82         switch (space) {
83         case Default: break; // do nothing
84         case Single:
85                 return "\\begin{singlespace}";
86         case Onehalf:
87                 return "\\begin{onehalfspace}";
88         case Double:
89                 return "\\begin{doublespace}";
90         case Other:
91         {
92                 ostringstream ost;
93                 ost << "\\begin{spacing}{"
94                     << getValue() << "}";
95                 return ost.str().c_str();
96         }
97         }
98         return string();
99 }
100
101
102 string const Spacing::writeEnvirEnd() const
103 {
104         switch (space) {
105         case Default: break; // do nothing
106         case Single:
107                 return "\\end{singlespace}";
108         case Onehalf:
109                 return "\\end{onehalfspace}";
110         case Double:
111                 return "\\end{doublespace}";
112         case Other:
113                 return "\\end{spacing}";
114         }
115         return string();
116 }