]> git.lyx.org Git - lyx.git/blob - src/Spacing.h
white-space changes, removed definitions.h several enum changes because of this,...
[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
17 ///
18 class Spacing {
19 public:
20         ///
21         enum Space {
22                 ///
23                 Single,
24                 ///
25                 Onehalf,
26                 ///
27                 Double,
28                 ///
29                 Other
30         };
31         ///
32         Spacing()
33         {
34                 space = Single;
35                 value = getValue();
36         }
37         ///
38         float getValue() const
39         {
40                 switch(space) {
41                 case Single: return 1.0;
42                 case Onehalf: return 1.25;
43                 case Double: return 1.667;
44                 case Other: return value;
45                 }
46                 return 1.0;
47         }
48         ///
49         Spacing::Space getSpace() const
50         {
51                 return space;
52         }
53         ///
54         void set(Spacing::Space sp, float val = 1.0)
55         {
56                 space = sp;
57                 if (sp == Other) {
58                         switch(int(val * 1000 + 0.5)) {
59                         case 1000: space = Single; break;
60                         case 1250: space = Onehalf; break;
61                         case 1667: space = Double; break;
62                         default: value = val; break;
63                         }
64                 }
65         }
66         ///
67         void set(Spacing::Space sp, char const * val)
68         {
69                 float fval;
70                 sscanf(val, "%f", &fval);
71                 set(sp, fval);
72         }
73         ///
74         void writeFile(FILE * file);
75         ///
76         friend bool operator!=(Spacing const & a, Spacing const & b)
77         {
78                 if (a.space == b.space && a.getValue() == b.getValue())
79                         return false;
80                 return true;
81         }
82 private:
83         ///
84         Space space;
85         ///
86         float value;
87 };
88
89 #endif