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
58 LyXLength() : val(0), uni(LyXLength::PT) {}
60 LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
62 /** "data" must be a decimal number, followed by a unit. */
64 LyXLength(string const & data);
67 float value() const { return val; };
69 LyXLength::UNIT unit() const { return uni; };
72 virtual string asString() const;
74 virtual string asLatexString() const { return this->asString(); };
77 /** If "data" is valid, the length represented by it is
78 stored into "result", if that is not 0. */
79 friend bool isValidLength(string const & data,
80 LyXLength * result= 0);
91 bool operator==(LyXLength const & l1, LyXLength const & l2)
93 return l1.value() == l2.value()
94 && l1.unit() == l2.unit();
98 extern LyXLength::UNIT unitFromString (string const & data);
100 extern bool isValidLength(string const & data, LyXLength * result);
102 /// LyXGlueLength class
103 class LyXGlueLength : public LyXLength {
106 LyXGlueLength(float v,
109 LyXLength::UNIT pu = LyXLength::UNIT_NONE,
111 LyXLength::UNIT mu = LyXLength::UNIT_NONE)
113 plus_val(pv), minus_val(mv),
114 plus_uni(pu), minus_uni(mu) {}
116 /** "data" must be a decimal number, followed by a unit, and
117 optional "glue" indicated by "+" and "-". You may abbreviate
118 reasonably. Examples:
119 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
120 The traditional Latex format is also accepted, like
121 4cm plus 10pt minus 10pt */
123 LyXGlueLength(string const & data);
126 float plusValue() const { return plus_val; };
128 LyXLength::UNIT plusUnit() const { return plus_uni; };
130 float minusValue() const { return minus_val; };
132 LyXLength::UNIT minusUnit() const { return minus_uni; };
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;
154 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
156 return l1.value() == l2.value()
157 && l1.unit() == l2.unit()
158 && l1.plusValue() == l2.plusValue()
159 && l1.plusUnit() == l2.plusUnit()
160 && l1.minusValue() == l2.minusValue()
161 && l1.minusUnit() == l2.minusUnit();
166 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
191 len(0.0, LyXLength::PT),
195 VSpace(vspace_kind k) :
197 len (0.0, LyXLength::PT),
201 VSpace(LyXGlueLength l) :
208 VSpace(float v, LyXLength::UNIT u) :
213 /// this constructor is for reading from a .lyx file
215 VSpace(string const & data);
218 vspace_kind kind() const { return kin; }
220 LyXLength length() const { return len; }
222 // a flag that switches between \vspace and \vspace*
223 bool keep() const { return kp; }
225 void setKeep(bool val) { kp = val; }
227 bool operator == (VSpace const &) const;
231 string asLyXCommand() const; // how it goes into the LyX file
233 string asLatexCommand(BufferParams const & params) const;
235 int inPixels(BufferView * bv) const;
237 int inPixels(int default_height, int default_skip) const;