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 const asString() const;
74 virtual string const asLatexString() const {
75 return this->asString();
78 /** If "data" is valid, the length represented by it is
79 stored into "result", if that is not 0. */
80 friend bool isValidLength(string const & data,
81 LyXLength * result = 0);
92 bool operator==(LyXLength const & l1, LyXLength const & l2)
94 return l1.value() == l2.value()
95 && l1.unit() == l2.unit();
99 extern LyXLength::UNIT unitFromString (string const & data);
101 extern bool isValidLength(string const & data, LyXLength * result);
103 /// LyXGlueLength class
104 class LyXGlueLength : public LyXLength {
107 LyXGlueLength(float v,
110 LyXLength::UNIT pu = LyXLength::UNIT_NONE,
112 LyXLength::UNIT mu = LyXLength::UNIT_NONE)
114 plus_val(pv), minus_val(mv),
115 plus_uni(pu), minus_uni(mu) {}
117 /** "data" must be a decimal number, followed by a unit, and
118 optional "glue" indicated by "+" and "-". You may abbreviate
119 reasonably. Examples:
120 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
121 The traditional Latex format is also accepted, like
122 4cm plus 10pt minus 10pt */
124 LyXGlueLength(string const & data);
127 float plusValue() const { return plus_val; }
129 LyXLength::UNIT plusUnit() const { return plus_uni; }
131 float minusValue() const { return minus_val; }
133 LyXLength::UNIT minusUnit() const { return minus_uni; }
136 virtual string const asString() const;
138 virtual string const asLatexString() const;
141 /** If "data" is valid, the length represented by it is
142 stored into "result", if that is not 0. */
143 friend bool isValidGlueLength(string const & data,
144 LyXGlueLength* result = 0);
152 LyXLength::UNIT plus_uni;
154 LyXLength::UNIT minus_uni;
159 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
161 return l1.value() == l2.value()
162 && l1.unit() == l2.unit()
163 && l1.plusValue() == l2.plusValue()
164 && l1.plusUnit() == l2.plusUnit()
165 && l1.minusValue() == l2.minusValue()
166 && l1.minusUnit() == l2.minusUnit();
171 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
176 /// The different kinds of spaces.
196 len(0.0, LyXLength::PT),
200 VSpace(vspace_kind k) :
202 len (0.0, LyXLength::PT),
206 VSpace(LyXGlueLength l) :
213 VSpace(float v, LyXLength::UNIT u) :
218 /// Constructor for reading from a .lyx file
220 VSpace(string const & data);
223 vspace_kind kind() const { return kin; }
225 LyXGlueLength length() const { return len; }
227 // a flag that switches between \vspace and \vspace*
228 bool keep() const { return kp; }
230 void setKeep(bool val) { kp = val; }
232 bool operator==(VSpace const &) const;
236 string const asLyXCommand() const; // how it goes into the LyX file
238 string const asLatexCommand(BufferParams const & params) const;
240 int inPixels(BufferView * bv) const;
242 int inPixels(int default_height, int default_skip) const;