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