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