]> git.lyx.org Git - lyx.git/blob - src/Spacing.C
update all .po files ot latestes pot
[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-2000 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 /// how can I put this inside of Spacing (class)
25 static
26 char const * spacing_string[] = {"single", "onehalf", "double", "other"};
27
28
29 float Spacing::getValue() const 
30 {
31         switch(space) {
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;
37         }
38         return 1.0;
39 }
40
41
42 void Spacing::set(Spacing::Space sp, float val)
43 {
44         space = sp;
45         if (sp == Other) {
46                 switch(int(val * 1000 + 0.5)) {
47                 case 1000: space = Single; break;
48                 case 1250: space = Onehalf; break;
49                 case 1667: space = Double; break;
50                 default: value = val; break;
51                 }
52         }
53 }
54
55
56 void Spacing::set(Spacing::Space sp, string const & val)
57 {
58         float fval;
59         istringstream istr(val);
60         istr >> fval;
61         set(sp, fval);
62 }
63
64
65 void Spacing::writeFile(ostream & os, bool para) const
66 {
67         if (space == Default) return;
68         
69         string cmd = para ? "\\paragraph_spacing " : "\\spacing ";
70         
71         if (getSpace() == Spacing::Other) {
72                 os.setf(ios::showpoint|ios::fixed);
73                 os.precision(2);
74                 os << cmd << spacing_string[getSpace()]
75                    << " " << getValue() << " \n";
76         } else {
77                 os << cmd << spacing_string[getSpace()] << " \n";
78         }       
79 }
80
81
82 string const Spacing::writeEnvirBegin() const
83 {
84         switch(space) {
85         case Default: break; // do nothing
86         case Single:
87                 return "\\begin{singlespace}";
88         case Onehalf:
89                 return "\\begin{onehalfspace}";
90         case Double:
91                 return "\\begin{doublespace}";
92         case Other:
93         {
94                 ostringstream ost;
95                 ost << "\\begin{spacing}{"
96                     << getValue() << "}";
97                 return ost.str().c_str();
98         }
99         }
100         return string();
101 }
102
103
104 string const Spacing::writeEnvirEnd() const
105 {
106         switch(space) {
107         case Default: break; // do nothing
108         case Single:
109                 return "\\end{singlespace}";
110         case Onehalf:
111                 return "\\end{onehalfspace}";
112         case Double:
113                 return "\\end{doublespace}";
114         case Other:
115                 return "\\end{spacing}";
116         }
117         return string();
118 }