]> git.lyx.org Git - lyx.git/blob - src/vspace.h
ee1922d5d0fbda1e69f9c0906b7bc619f8a9ad53
[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 #include "LString.h"
21
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
53         };
54
55         //@Man: constructors
56         //@{
57         ///
58         LyXLength() : val(0), uni(LyXLength::PT) {}
59         LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
60
61         /** "data" must be a decimal number, followed by a unit. */
62         LyXLength(string const & data);
63         //@}
64         
65         //@Man: selectors
66         //@{
67         ///
68         float value() const         { return val; };
69         ///
70         LyXLength::UNIT unit() const { return uni; };
71         //@}
72
73         ///
74         bool operator==(LyXLength const &) const;
75
76         /// conversion
77         virtual string asString() const;
78         ///
79         virtual string asLatexString() const { return this->asString(); };
80
81
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);
86
87 protected:
88         ///
89         float           val;
90         ///
91         LyXLength::UNIT uni;
92 };
93
94 extern LyXLength::UNIT unitFromString (string const & data);
95 extern bool isValidLength(string const & data, LyXLength * result);
96
97 /// LyXGlueLength class
98 class LyXGlueLength : public LyXLength {
99 public:
100         //@Man: constructors
101         //@{
102         ///
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) {}
109
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         //@}
118         
119         //@Man: selectors
120         //@{
121         ///
122         float plusValue() const         { return plus_val; };
123         ///
124         LyXLength::UNIT plusUnit() const { return plus_uni; };
125         ///
126         float minusValue() const         { return minus_val; };
127         ///
128         LyXLength::UNIT minusUnit() const { return minus_uni; };
129         //@}
130
131         ///
132         bool operator==(LyXGlueLength const &) const;
133
134         /// conversion
135         virtual string asString() const;
136         ///
137         virtual string asLatexString() const;
138
139
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);
144
145 protected:
146         ///
147         float           plus_val, minus_val;
148         ///
149         LyXLength::UNIT plus_uni, minus_uni;
150 };
151
152 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
153
154 ///  VSpace class
155 class VSpace {
156 public:
157         ///
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) {}
166
167         VSpace(vspace_kind k) : 
168                 kin (k), 
169                 len (0.0, LyXLength::PT),
170                 kp (false) {}
171
172         VSpace(LyXGlueLength l) :
173                 kin (LENGTH),
174                 len (l),
175                 kp (false) {}
176
177         VSpace(float v, LyXLength::UNIT u) : 
178                 kin (LENGTH), 
179                 len (v, u),
180                 kp (false) {}
181
182         /// this constructor is for reading from a .lyx file
183         VSpace(string const & data);
184         
185         // access functions
186         vspace_kind kind() const  { return  kin; }
187         ///
188         LyXLength   length() const { return len; }
189
190         // a flag that switches between \vspace and \vspace*
191         bool keep() const      { return kp; }
192         ///
193         void setKeep(bool val) { kp = val; } 
194         ///
195         bool operator==(VSpace const &) const;
196
197         // conversion
198         ///
199         string asLyXCommand() const;  // how it goes into the LyX file
200         ///
201         string asLatexCommand() const;
202         ///
203         int inPixels() const;
204 private:
205         ///
206         vspace_kind  kin;
207         ///
208         LyXGlueLength    len;
209         ///
210         bool kp;
211 };
212
213 #endif