]> git.lyx.org Git - lyx.git/blob - src/vspace.h
546ae3a11791bc1117fd7a188be08c15d83ca5aa
[lyx.git] / src / vspace.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-2000 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef VSPACE_H
13 #define VSPACE_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "LString.h"
20
21 class BufferParams;
22 class BufferView;
23
24 ///  LyXLength Class
25 class LyXLength {
26 public:
27         /// length units
28         enum UNIT {
29                 /// Scaled point (65536sp = 1pt) TeX's smallest unit.
30                 SP,
31                 /// Point = 1/72.27in = 0.351mm
32                 PT,
33                 /// Big point (72bp = 1in), also PostScript point
34                 BP,
35                 /// Didot point = 1/72 of a French inch, = 0.376mm
36                 DD,
37                 /// Millimeter = 2.845pt
38                 MM,
39                 /// Pica = 12pt = 4.218mm
40                 PC,
41                 /// Cicero = 12dd = 4.531mm
42                 CC,
43                 /// Centimeter = 10mm = 2.371pc
44                 CM,
45                 /// Inch = 25.4mm = 72.27pt = 6.022pc
46                 IN,
47                 /// Height of a small "x" for the current font.
48                 EX,
49                 /// Width of capital "M" in current font.
50                 EM,
51                 /// Math unit (18mu = 1em) for positioning in math mode
52                 MU,
53                 /// no unit
54                 UNIT_NONE
55         };
56
57         //@Man: constructors
58         //@{
59         ///
60         LyXLength() : val(0), uni(LyXLength::PT) {}
61         LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
62
63         /** "data" must be a decimal number, followed by a unit. */
64         LyXLength(string const & data);
65         //@}
66         
67         //@Man: selectors
68         //@{
69         ///
70         float value() const         { return val; };
71         ///
72         LyXLength::UNIT unit() const { return uni; };
73         //@}
74
75         ///
76         bool operator== (LyXLength const &) const;
77
78         /// conversion
79         virtual string asString() const;
80         ///
81         virtual string asLatexString() const { return this->asString(); };
82
83
84         /** If "data" is valid, the length represented by it is
85           stored into "result", if that is not 0. */
86         friend bool isValidLength(string const & data, 
87                                   LyXLength * result= 0);
88
89 protected:
90         ///
91         float           val;
92         ///
93         LyXLength::UNIT uni;
94 };
95
96 extern LyXLength::UNIT unitFromString (string const & data);
97 extern bool isValidLength(string const & data, LyXLength * result);
98
99 /// LyXGlueLength class
100 class LyXGlueLength : public LyXLength {
101 public:
102         //@Man: constructors
103         //@{
104         ///
105         LyXGlueLength(float v,      LyXLength::UNIT u, 
106                       float pv= 0.0, LyXLength::UNIT pu= LyXLength::UNIT_NONE, 
107                       float mv= 0.0, LyXLength::UNIT mu= LyXLength::UNIT_NONE) 
108                 : LyXLength (v, u), 
109                   plus_val(pv), minus_val(mv), 
110                   plus_uni(pu), minus_uni(mu) {}
111
112         /** "data" must be a decimal number, followed by a unit, and 
113           optional "glue" indicated by "+" and "-".  You may abbreviate
114           reasonably.  Examples:
115           1.2 cm  //  4mm +2pt  //  2cm -4mm +2mm  //  4+0.1-0.2cm
116           The traditional Latex format is also accepted, like  
117           4cm plus 10pt minus 10pt */
118         LyXGlueLength(string const & data);
119         //@}
120         
121         //@Man: selectors
122         //@{
123         ///
124         float plusValue() const         { return plus_val; };
125         ///
126         LyXLength::UNIT plusUnit() const { return plus_uni; };
127         ///
128         float minusValue() const         { return minus_val; };
129         ///
130         LyXLength::UNIT minusUnit() const { return minus_uni; };
131         //@}
132
133         ///
134         bool operator == (LyXGlueLength const &) const;
135
136         /// conversion
137         virtual string asString() const;
138         ///
139         virtual string asLatexString() const;
140
141
142         /** If "data" is valid, the length represented by it is
143           stored into "result", if that is not 0. */
144         friend bool isValidGlueLength(string const & data, 
145                                       LyXGlueLength* result= 0);
146
147 protected:
148         ///
149         float           plus_val, minus_val;
150         ///
151         LyXLength::UNIT plus_uni, minus_uni;
152 };
153
154 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
155
156 ///  VSpace class
157 class VSpace {
158 public:
159         ///
160         enum vspace_kind { NONE, DEFSKIP, 
161                            SMALLSKIP, MEDSKIP, BIGSKIP, 
162                            VFILL, LENGTH };
163         // constructors
164         VSpace() : 
165                 kin (NONE), 
166                 len(0.0, LyXLength::PT),
167                 kp (false) {}
168
169         VSpace(vspace_kind k) : 
170                 kin (k), 
171                 len (0.0, LyXLength::PT),
172                 kp (false) {}
173
174         VSpace(LyXGlueLength l) :
175                 kin (LENGTH),
176                 len (l),
177                 kp (false) {}
178
179         VSpace(float v, LyXLength::UNIT u) : 
180                 kin (LENGTH), 
181                 len (v, u),
182                 kp (false) {}
183
184         /// this constructor is for reading from a .lyx file
185         VSpace(string const & data);
186         
187         // access functions
188         vspace_kind kind() const  { return  kin; }
189         ///
190         LyXLength   length() const { return len; }
191
192         // a flag that switches between \vspace and \vspace*
193         bool keep() const      { return kp; }
194         ///
195         void setKeep(bool val) { kp = val; } 
196         ///
197         bool operator == (VSpace const &) const;
198
199         // conversion
200         ///
201         string asLyXCommand() const;  // how it goes into the LyX file
202         ///
203         string asLatexCommand(BufferParams const & params) const;
204         ///
205         int inPixels(BufferView * bv) const;
206 private:
207         ///
208         vspace_kind  kin;
209         ///
210         LyXGlueLength    len;
211         ///
212         bool kp;
213 };
214
215 #endif