2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright (C) 1995 1996 Matthias Ettrich
10 *======================================================*/
26 /// Scaled point (65536sp = 1pt) TeX's smallest unit.
28 /// Point = 1/72.27in = 0.351mm
30 /// Big point (72bp = 1in), also PostScript point
32 /// Didot point = 1/72 of a French inch, = 0.376mm
34 /// Millimeter = 2.845pt
36 /// Pica = 12pt = 4.218mm
38 /// Cicero = 12dd = 4.531mm
40 /// Centimeter = 10mm = 2.371pc
42 /// Inch = 25.4mm = 72.27pt = 6.022pc
44 /// Height of a small "x" for the current font.
46 /// Width of capital "M" in current font.
48 /// Math unit (18mu = 1em) for positioning in math mode
57 LyXLength() : val(0), uni(LyXLength::PT) {}
58 LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
60 /** "data" must be a decimal number, followed by a unit. */
61 LyXLength(string const & data);
67 float value() const { return val; };
69 LyXLength::UNIT unit() const { return uni; };
73 bool operator==(LyXLength const &) const;
76 virtual string asString() const;
78 virtual string asLatexString() const { return this->asString(); };
81 /** If "data" is valid, the length represented by it is
82 stored into "result", if that is not 0. */
83 friend bool isValidLength(string const & data,
84 LyXLength * result=0);
93 extern LyXLength::UNIT unitFromString (string const & data);
94 extern bool isValidLength(string const & data, LyXLength * result);
96 /// LyXGlueLength class
97 class LyXGlueLength : public LyXLength {
102 LyXGlueLength(float v, LyXLength::UNIT u,
103 float pv=0.0, LyXLength::UNIT pu=LyXLength::UNIT_NONE,
104 float mv=0.0, LyXLength::UNIT mu=LyXLength::UNIT_NONE)
106 plus_val(pv), minus_val(mv),
107 plus_uni(pu), minus_uni(mu) {}
109 /** "data" must be a decimal number, followed by a unit, and
110 optional "glue" indicated by "+" and "-". You may abbreviate
111 reasonably. Examples:
112 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
113 The traditional Latex format is also accepted, like
114 4cm plus 10pt minus 10pt */
115 LyXGlueLength(string const & data);
121 float plusValue() const { return plus_val; };
123 LyXLength::UNIT plusUnit() const { return plus_uni; };
125 float minusValue() const { return minus_val; };
127 LyXLength::UNIT minusUnit() const { return minus_uni; };
131 bool operator==(LyXGlueLength const &) const;
134 virtual string asString() const;
136 virtual string asLatexString() const;
139 /** If "data" is valid, the length represented by it is
140 stored into "result", if that is not 0. */
141 friend bool isValidGlueLength(string const & data,
142 LyXGlueLength* result=0);
146 float plus_val, minus_val;
148 LyXLength::UNIT plus_uni, minus_uni;
151 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
157 enum vspace_kind { NONE, DEFSKIP,
158 SMALLSKIP, MEDSKIP, BIGSKIP,
163 len(0.0, LyXLength::PT),
166 VSpace(vspace_kind k) :
168 len (0.0, LyXLength::PT),
171 VSpace(LyXGlueLength l) :
176 VSpace(float v, LyXLength::UNIT u) :
181 /// this constructor is for reading from a .lyx file
182 VSpace(string const & data);
185 vspace_kind kind() const { return kin; }
187 LyXLength length() const { return len; }
189 // a flag that switches between \vspace and \vspace*
190 bool keep() const { return kp; }
192 void setKeep(bool val) { kp = val; }
194 bool operator==(VSpace const &) const;
198 string asLyXCommand() const; // how it goes into the LyX file
200 string asLatexCommand() const;
202 int inPixels() const;