]> git.lyx.org Git - lyx.git/blob - src/Spacing.C
19f9d1fa65fd6ff084b859faed282a6ccc50f1e2
[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 #include "LString.h"
13
14 using std::ios;
15 using std::ostream;
16
17 /// how can I put this inside of Spacing (class)
18 static
19 char const * spacing_string[] = {"single", "onehalf", "double", "other"};
20
21
22 float Spacing::getValue() const 
23 {
24         switch(space) {
25         case Default: // nothing special should happen with this...
26         case Single: return 1.0;
27         case Onehalf: return 1.25;
28         case Double: return 1.667;
29         case Other: return value;
30         }
31         return 1.0;
32 }
33
34
35 void Spacing::set(Spacing::Space sp, float val)
36 {
37         space = sp;
38         if (sp == Other) {
39                 switch(int(val * 1000 + 0.5)) {
40                 case 1000: space = Single; break;
41                 case 1250: space = Onehalf; break;
42                 case 1667: space = Double; break;
43                 default: value = val; break;
44                 }
45         }
46 }
47
48
49 void Spacing::set(Spacing::Space sp, char const * val)
50 {
51         float fval;
52 #ifdef HAVE_SSTREAM
53         istringstream istr(val);
54 #else
55         istrstream istr(val);
56 #endif
57         istr >> fval;
58         set(sp, fval);
59 }
60
61
62 void Spacing::writeFile(ostream & os, bool para) const
63 {
64         if (space == Default) return;
65         
66         string cmd = para ? "\\paragraph_spacing " : "\\spacing ";
67         
68         if (getSpace() == Spacing::Other) {
69                 os.setf(ios::showpoint|ios::fixed);
70                 os.precision(2);
71                 os << cmd << spacing_string[getSpace()]
72                    << " " << getValue() << " \n";
73         } else {
74                 os << cmd << spacing_string[getSpace()] << " \n";
75         }       
76 }