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. */
64 LyXLength(string const & data);
70 float value() const { return val; };
72 LyXLength::UNIT unit() const { return uni; };
76 bool operator== (LyXLength const &) const;
79 virtual string asString() const;
81 virtual string asLatexString() const { return this->asString(); };
84 /** If "data" is valid, the length represented by it is
85 stored into "result", if that is not 0. */
86 friend bool isValidLength(string const & data,
87 LyXLength * result= 0);
96 extern LyXLength::UNIT unitFromString (string const & data);
97 extern bool isValidLength(string const & data, LyXLength * result);
99 /// LyXGlueLength class
100 class LyXGlueLength : public LyXLength {
105 LyXGlueLength(float v, LyXLength::UNIT u,
106 float pv= 0.0, LyXLength::UNIT pu= LyXLength::UNIT_NONE,
107 float mv= 0.0, LyXLength::UNIT mu= LyXLength::UNIT_NONE)
109 plus_val(pv), minus_val(mv),
110 plus_uni(pu), minus_uni(mu) {}
112 /** "data" must be a decimal number, followed by a unit, and
113 optional "glue" indicated by "+" and "-". You may abbreviate
114 reasonably. Examples:
115 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
116 The traditional Latex format is also accepted, like
117 4cm plus 10pt minus 10pt */
118 LyXGlueLength(string const & data);
124 float plusValue() const { return plus_val; };
126 LyXLength::UNIT plusUnit() const { return plus_uni; };
128 float minusValue() const { return minus_val; };
130 LyXLength::UNIT minusUnit() const { return minus_uni; };
134 bool operator == (LyXGlueLength const &) const;
137 virtual string asString() const;
139 virtual string asLatexString() const;
142 /** If "data" is valid, the length represented by it is
143 stored into "result", if that is not 0. */
144 friend bool isValidGlueLength(string const & data,
145 LyXGlueLength* result= 0);
149 float plus_val, minus_val;
151 LyXLength::UNIT plus_uni, minus_uni;
154 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
160 enum vspace_kind { NONE, DEFSKIP,
161 SMALLSKIP, MEDSKIP, BIGSKIP,
166 len(0.0, LyXLength::PT),
169 VSpace(vspace_kind k) :
171 len (0.0, LyXLength::PT),
174 VSpace(LyXGlueLength l) :
179 VSpace(float v, LyXLength::UNIT u) :
184 /// this constructor is for reading from a .lyx file
185 VSpace(string const & data);
188 vspace_kind kind() const { return kin; }
190 LyXLength length() const { return len; }
192 // a flag that switches between \vspace and \vspace*
193 bool keep() const { return kp; }
195 void setKeep(bool val) { kp = val; }
197 bool operator == (VSpace const &) const;
201 string asLyXCommand() const; // how it goes into the LyX file
203 string asLatexCommand(BufferParams const & params) const;
205 int inPixels(BufferView * bv) const;