This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / vspace.h
blobc33233d602822547c646c59c41f11503157247be
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>
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
54 //@Man: constructors
55 //@{
56 ///
57 LyXLength() : val(0), uni(LyXLength::PT) {}
58 LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
60 /** "data" must be a decimal number, followed by a unit. */
61 LyXLength(string const & data);
62 //@}
64 //@Man: selectors
65 //@{
66 ///
67 float value() const { return val; };
68 ///
69 LyXLength::UNIT unit() const { return uni; };
70 //@}
72 ///
73 bool operator==(LyXLength const &) const;
75 /// conversion
76 virtual string asString() const;
77 ///
78 virtual string asLatexString() const { return this->asString(); };
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);
86 protected:
87 ///
88 float val;
89 ///
90 LyXLength::UNIT uni;
93 extern LyXLength::UNIT unitFromString (string const & data);
94 extern bool isValidLength(string const & data, LyXLength * result);
96 /// LyXGlueLength class
97 class LyXGlueLength : public LyXLength {
98 public:
99 //@Man: constructors
100 //@{
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) {}
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 //@}
118 //@Man: selectors
119 //@{
121 float plusValue() const { return plus_val; };
123 LyXLength::UNIT plusUnit() const { return plus_uni; };
125 float minusValue() const { return minus_val; };
127 LyXLength::UNIT minusUnit() const { return minus_uni; };
128 //@}
131 bool operator==(LyXGlueLength const &) const;
133 /// conversion
134 virtual string asString() const;
136 virtual string asLatexString() const;
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);
144 protected:
146 float plus_val, minus_val;
148 LyXLength::UNIT plus_uni, minus_uni;
151 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
153 /// VSpace class
154 class VSpace {
155 public:
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) {}
166 VSpace(vspace_kind k) :
167 kin (k),
168 len (0.0, LyXLength::PT),
169 kp (false) {}
171 VSpace(LyXGlueLength l) :
172 kin (LENGTH),
173 len (l),
174 kp (false) {}
176 VSpace(float v, LyXLength::UNIT u) :
177 kin (LENGTH),
178 len (v, u),
179 kp (false) {}
181 /// this constructor is for reading from a .lyx file
182 VSpace(string const & data);
184 // access functions
185 vspace_kind kind() const { return kin; }
187 LyXLength length() const { return len; }
189 // a flag that switches between \vspace and \vspace*
190 bool keep() const { return kp; }
192 void setKeep(bool val) { kp = val; }
194 bool operator==(VSpace const &) const;
196 // conversion
198 string asLyXCommand() const; // how it goes into the LyX file
200 string asLatexCommand() const;
202 int inPixels() const;
203 private:
205 vspace_kind kin;
207 LyXGlueLength len;
209 bool kp;
212 #endif