]> git.lyx.org Git - lyx.git/blob - src/Spacing.C
Small changes; ChangeLog is your friend
[lyx.git] / src / Spacing.C
1 #include <config.h>
2
3
4 #ifdef HAVE_SSTREAM
5 #include <sstream>
6 using std::istringstream;
7 #else
8 #include <strstream>
9 #endif
10
11 #include "Spacing.h"
12
13 using std::ios;
14 using std::ostream;
15
16 /// how can I put this inside of Spacing (class)
17 static
18 char const * spacing_string[] = {"single", "onehalf", "double", "other"};
19
20
21 float Spacing::getValue() const 
22 {
23         switch(space) {
24         case Single: return 1.0;
25         case Onehalf: return 1.25;
26         case Double: return 1.667;
27         case Other: return value;
28         }
29         return 1.0;
30 }
31
32
33 void Spacing::set(Spacing::Space sp, float val)
34 {
35         space = sp;
36         if (sp == Other) {
37                 switch(int(val * 1000 + 0.5)) {
38                 case 1000: space = Single; break;
39                 case 1250: space = Onehalf; break;
40                 case 1667: space = Double; break;
41                 default: value = val; break;
42                 }
43         }
44 }
45
46
47 void Spacing::set(Spacing::Space sp, char const * val)
48 {
49         float fval;
50 #ifdef HAVE_SSTREAM
51         istringstream istr(val);
52 #else
53         istrstream istr(val);
54 #endif
55         istr >> fval;
56         set(sp, fval);
57 }
58
59
60 void Spacing::writeFile(ostream & os) const
61 {
62         if (getSpace() == Spacing::Other) {
63                 os.setf(ios::showpoint|ios::fixed);
64                 os.precision(2);
65                 os << "\\spacing " << spacing_string[getSpace()]
66                    << " " << getValue() << " \n";
67         } else {
68                 os << "\\spacing " << spacing_string[getSpace()] << " \n";
69         }       
70 }