2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright (C) 1995 1996 Matthias Ettrich
10 *======================================================*/
27 /// Scaled point (65536sp = 1pt) TeX's smallest unit.
29 /// Point = 1/72.27in = 0.351mm
31 /// Big point (72bp = 1in), also PostScript point
33 /// Didot point = 1/72 of a French inch, = 0.376mm
35 /// Millimeter = 2.845pt
37 /// Pica = 12pt = 4.218mm
39 /// Cicero = 12dd = 4.531mm
41 /// Centimeter = 10mm = 2.371pc
43 /// Inch = 25.4mm = 72.27pt = 6.022pc
45 /// Height of a small "x" for the current font.
47 /// Width of capital "M" in current font.
49 /// Math unit (18mu = 1em) for positioning in math mode
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);
68 float value() const { return val; };
70 LyXLength::UNIT unit() const { return uni; };
74 bool operator==(LyXLength const &) const;
77 virtual string asString() const;
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);
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 {
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)
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);
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; };
132 bool operator==(LyXGlueLength const &) const;
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);
147 float plus_val, minus_val;
149 LyXLength::UNIT plus_uni, minus_uni;
152 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
158 enum vspace_kind { NONE, DEFSKIP,
159 SMALLSKIP, MEDSKIP, BIGSKIP,
164 len(0.0, LyXLength::PT),
167 VSpace(vspace_kind k) :
169 len (0.0, LyXLength::PT),
172 VSpace(LyXGlueLength l) :
177 VSpace(float v, LyXLength::UNIT u) :
182 /// this constructor is for reading from a .lyx file
183 VSpace(string const & data);
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;
199 string asLyXCommand() const; // how it goes into the LyX file
201 string asLatexCommand() const;
203 int inPixels() const;