]> git.lyx.org Git - lyx.git/blob - src/vspace.h
8e224649899418477c2e5411bfbe07e50b601b8f
[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 <stdio.h>
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(LString 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 other);
74
75         /// conversion
76         virtual LString asString() const;
77         virtual LString asLatexString() const { return this->asString(); };
78
79
80         /** If "data" is valid, the length represented by it is
81           stored into "result", if that is not NULL. */
82         friend bool isValidLength(LString const & data, 
83                                   LyXLength* result=NULL);
84
85 protected:
86         float           val;
87         LyXLength::UNIT uni;
88 };
89
90 extern LyXLength::UNIT unitFromString (LString const & data);
91 extern bool isValidLength(LString const &data, LyXLength* result);
92
93 /// LyXGlueLength class
94 class LyXGlueLength : public LyXLength {
95 public:
96         //@Man: constructors
97         //@{
98         ///
99         LyXGlueLength(float v,      LyXLength::UNIT u, 
100                       float pv=0.0, LyXLength::UNIT pu=LyXLength::UNIT_NONE, 
101                       float mv=0.0, LyXLength::UNIT mu=LyXLength::UNIT_NONE) 
102                 : LyXLength (v, u), 
103                   plus_val(pv), minus_val(mv), 
104                   plus_uni(pu), minus_uni(mu) {};
105
106         /** "data" must be a decimal number, followed by a unit, and 
107           optional "glue" indicated by "+" and "-".  You may abbreviate
108           reasonably.  Examples:
109           1.2 cm  //  4mm +2pt  //  2cm -4mm +2mm  //  4+0.1-0.2cm
110           The traditional Latex format is also accepted, like  
111           4cm plus 10pt minus 10pt */
112         LyXGlueLength(LString const & data);
113         //@}
114         
115         //@Man: selectors
116         //@{
117         ///
118         float plusValue() const         { return plus_val; };
119         ///
120         LyXLength::UNIT plusUnit() const { return plus_uni; };
121         ///
122         float minusValue() const         { return minus_val; };
123         ///
124         LyXLength::UNIT minusUnit() const { return minus_uni; };
125         //@}
126
127         ///
128         bool operator==(LyXGlueLength other);
129
130         /// conversion
131         virtual LString asString() const;
132         virtual LString asLatexString() const;
133
134
135         /** If "data" is valid, the length represented by it is
136           stored into "result", if that is not NULL. */
137         friend bool isValidGlueLength(LString const & data, 
138                                       LyXGlueLength* result=NULL);
139
140 protected:
141         float           plus_val, minus_val;
142         LyXLength::UNIT plus_uni, minus_uni;
143 };
144
145 extern bool isValidGlueLength(LString const &data, LyXGlueLength* result);
146
147 ///  VSpace class
148 class VSpace {
149 public:
150         ///
151         enum vspace_kind { NONE, DEFSKIP, 
152                            SMALLSKIP, MEDSKIP, BIGSKIP, 
153                            VFILL, LENGTH };
154         // constructors
155         VSpace() : 
156                 kin (NONE), 
157                 len(0.0, LyXLength::PT),
158                 kp (false) {};
159
160         VSpace(vspace_kind k) : 
161                 kin (k), 
162                 len (0.0, LyXLength::PT),
163                 kp (false) {};
164
165         VSpace(LyXGlueLength l) :
166                 kin (LENGTH),
167                 len (l),
168                 kp (false) {};
169
170         VSpace(float v, LyXLength::UNIT u) : 
171                 kin (LENGTH), 
172                 len (v, u),
173                 kp (false) {};
174
175         /// this constructor is for reading from a .lyx file
176         VSpace(LString const & data);
177         
178         // access functions
179         vspace_kind kind() const  { return  kin; }
180         LyXLength   length() const { return len; }
181
182         // a flag that switches between \vspace and \vspace*
183         bool keep() const      { return kp; }
184         void setKeep(bool val) { kp = val; } 
185
186         bool operator== (VSpace other);
187
188         // conversion
189         LString asLyXCommand() const;  // how it goes into the LyX file
190         LString asLatexCommand() const;
191         int inPixels() const;
192 private:
193         vspace_kind  kin;  
194         LyXGlueLength    len;
195         bool kp;
196 };
197
198 #endif
199
200