]> git.lyx.org Git - lyx.git/blob - src/Spacing.h
the fstream/iostream changes and some small other things
[lyx.git] / src / Spacing.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-1999 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef SPACING_H
13 #define SPACING_H
14
15 #include <cstdio>
16 #include "support/LOstream.h"
17
18
19 ///
20 class Spacing {
21 public:
22         ///
23         enum Space {
24                 ///
25                 Single,
26                 ///
27                 Onehalf,
28                 ///
29                 Double,
30                 ///
31                 Other
32         };
33         ///
34         Spacing()
35         {
36                 space = Single;
37                 value = getValue();
38         }
39         ///
40         float getValue() const
41         {
42                 switch(space) {
43                 case Single: return 1.0;
44                 case Onehalf: return 1.25;
45                 case Double: return 1.667;
46                 case Other: return value;
47                 }
48                 return 1.0;
49         }
50         ///
51         Spacing::Space getSpace() const
52         {
53                 return space;
54         }
55         ///
56         void set(Spacing::Space sp, float val = 1.0)
57         {
58                 space = sp;
59                 if (sp == Other) {
60                         switch(int(val * 1000 + 0.5)) {
61                         case 1000: space = Single; break;
62                         case 1250: space = Onehalf; break;
63                         case 1667: space = Double; break;
64                         default: value = val; break;
65                         }
66                 }
67         }
68         ///
69         void set(Spacing::Space sp, char const * val)
70         {
71                 float fval;
72                 sscanf(val, "%f", &fval);
73                 set(sp, fval);
74         }
75         ///
76         void writeFile(ostream &);
77         ///
78         friend bool operator!=(Spacing const & a, Spacing const & b)
79         {
80                 if (a.space == b.space && a.getValue() == b.getValue())
81                         return false;
82                 return true;
83         }
84 private:
85         ///
86         Space space;
87         ///
88         float value;
89 };
90
91 #endif