]> git.lyx.org Git - lyx.git/blob - src/Spacing.C
remove wrong sections
[lyx.git] / src / Spacing.C
1 #include <config.h>
2
3
4 #ifdef HAVE_SSTREAM
5 #include <sstream>
6 using std::istringstream;
7 using std::ostringstream;
8 #else
9 #include <strstream>
10 #endif
11
12 #include "Spacing.h"
13 #include "LString.h"
14
15 using std::ios;
16 using std::ostream;
17
18 /// how can I put this inside of Spacing (class)
19 static
20 char const * spacing_string[] = {"single", "onehalf", "double", "other"};
21
22
23 float Spacing::getValue() const 
24 {
25         switch(space) {
26         case Default: // nothing special should happen with this...
27         case Single: return 1.0;
28         case Onehalf: return 1.25;
29         case Double: return 1.667;
30         case Other: return value;
31         }
32         return 1.0;
33 }
34
35
36 void Spacing::set(Spacing::Space sp, float val)
37 {
38         space = sp;
39         if (sp == Other) {
40                 switch(int(val * 1000 + 0.5)) {
41                 case 1000: space = Single; break;
42                 case 1250: space = Onehalf; break;
43                 case 1667: space = Double; break;
44                 default: value = val; break;
45                 }
46         }
47 }
48
49
50 void Spacing::set(Spacing::Space sp, char const * val)
51 {
52         float fval;
53 #ifdef HAVE_SSTREAM
54         istringstream istr(val);
55 #else
56         istrstream istr(val);
57 #endif
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 Spacing::writeEnvirBegin() const
81 {
82         switch(space) {
83         case Default: break; // do nothing
84         case Single:
85                 return "\\begin{singlespace}";
86                 break;
87         case Onehalf:
88                 return "\\begin{onehalfspace}";
89                 break;
90         case Double:
91                 return "\\begin{doublespace}";
92                 break;
93         case Other:
94 #ifdef HAVE_SSTREAM
95                 ostringstream ost;
96                 ost << "\\begin{spacing}{"
97                     << getValue() << "}";
98                 return ost.str().c_str();
99 #else
100                 {
101                         char tmp[512];
102                         ostrstream ost(tmp, 512);
103                         ost << "\\begin{spacing}{"
104                             << getValue() << "}";
105                         return ost.str();
106                 }
107 #endif
108                 break;
109         }
110         return string();
111 }
112
113
114 string Spacing::writeEnvirEnd() const
115 {
116         switch(space) {
117         case Default: break; // do nothing
118         case Single:
119                 return "\\end{singlespace}";
120                 break;
121         case Onehalf:
122                 return "\\end{onehalfspace}";
123                 break;
124         case Double:
125                 return "\\end{doublespace}";
126                 break;
127         case Other:
128                 return "\\end{spacing}";
129                 break;
130         }
131         return string();
132 }