2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
29 /// Scaled point (65536sp = 1pt) TeX's smallest unit.
31 /// Point = 1/72.27in = 0.351mm
33 /// Big point (72bp = 1in), also PostScript point
35 /// Didot point = 1/72 of a French inch, = 0.376mm
37 /// Millimeter = 2.845pt
39 /// Pica = 12pt = 4.218mm
41 /// Cicero = 12dd = 4.531mm
43 /// Centimeter = 10mm = 2.371pc
45 /// Inch = 25.4mm = 72.27pt = 6.022pc
47 /// Height of a small "x" for the current font.
49 /// Width of capital "M" in current font.
51 /// Math unit (18mu = 1em) for positioning in math mode
60 LyXLength() : val(0), uni(LyXLength::PT) {}
61 LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
63 /** "data" must be a decimal number, followed by a unit. */
65 LyXLength(string const & data);
71 float value() const { return val; };
73 LyXLength::UNIT unit() const { return uni; };
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);
96 bool operator==(LyXLength const & l1, LyXLength const & l2)
98 return l1.value() == l2.value()
99 && l1.unit() == l2.unit();
103 extern LyXLength::UNIT unitFromString (string const & data);
104 extern bool isValidLength(string const & data, LyXLength * result);
106 /// LyXGlueLength class
107 class LyXGlueLength : public LyXLength {
112 LyXGlueLength(float v,
115 LyXLength::UNIT pu = LyXLength::UNIT_NONE,
117 LyXLength::UNIT mu = LyXLength::UNIT_NONE)
119 plus_val(pv), minus_val(mv),
120 plus_uni(pu), minus_uni(mu) {}
122 /** "data" must be a decimal number, followed by a unit, and
123 optional "glue" indicated by "+" and "-". You may abbreviate
124 reasonably. Examples:
125 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
126 The traditional Latex format is also accepted, like
127 4cm plus 10pt minus 10pt */
129 LyXGlueLength(string const & data);
135 float plusValue() const { return plus_val; };
137 LyXLength::UNIT plusUnit() const { return plus_uni; };
139 float minusValue() const { return minus_val; };
141 LyXLength::UNIT minusUnit() const { return minus_uni; };
145 virtual string asString() const;
147 virtual string asLatexString() const;
150 /** If "data" is valid, the length represented by it is
151 stored into "result", if that is not 0. */
152 friend bool isValidGlueLength(string const & data,
153 LyXGlueLength* result= 0);
157 float plus_val, minus_val;
159 LyXLength::UNIT plus_uni, minus_uni;
164 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
166 return l1.value() == l2.value()
167 && l1.unit() == l2.unit()
168 && l1.plusValue() == l2.plusValue()
169 && l1.plusUnit() == l2.plusUnit()
170 && l1.minusValue() == l2.minusValue()
171 && l1.minusUnit() == l2.minusUnit();
176 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
182 enum vspace_kind { NONE, DEFSKIP,
183 SMALLSKIP, MEDSKIP, BIGSKIP,
188 len(0.0, LyXLength::PT),
192 VSpace(vspace_kind k) :
194 len (0.0, LyXLength::PT),
198 VSpace(LyXGlueLength l) :
203 VSpace(float v, LyXLength::UNIT u) :
208 /// this constructor is for reading from a .lyx file
210 VSpace(string const & data);
213 vspace_kind kind() const { return kin; }
215 LyXLength length() const { return len; }
217 // a flag that switches between \vspace and \vspace*
218 bool keep() const { return kp; }
220 void setKeep(bool val) { kp = val; }
222 bool operator == (VSpace const &) const;
226 string asLyXCommand() const; // how it goes into the LyX file
228 string asLatexCommand(BufferParams const & params) const;
230 int inPixels(BufferView * bv) const;
232 int inPixels(int default_height, int default_skip) const;