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 bool operator== (LyXLength const &) const;
80 virtual string asString() const;
82 virtual string asLatexString() const { return this->asString(); };
85 /** If "data" is valid, the length represented by it is
86 stored into "result", if that is not 0. */
87 friend bool isValidLength(string const & data,
88 LyXLength * result= 0);
97 extern LyXLength::UNIT unitFromString (string const & data);
98 extern bool isValidLength(string const & data, LyXLength * result);
100 /// LyXGlueLength class
101 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);
129 float plusValue() const { return plus_val; };
131 LyXLength::UNIT plusUnit() const { return plus_uni; };
133 float minusValue() const { return minus_val; };
135 LyXLength::UNIT minusUnit() const { return minus_uni; };
139 bool operator == (LyXGlueLength const &) const;
142 virtual string asString() const;
144 virtual string asLatexString() const;
147 /** If "data" is valid, the length represented by it is
148 stored into "result", if that is not 0. */
149 friend bool isValidGlueLength(string const & data,
150 LyXGlueLength* result= 0);
154 float plus_val, minus_val;
156 LyXLength::UNIT plus_uni, minus_uni;
159 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
165 enum vspace_kind { NONE, DEFSKIP,
166 SMALLSKIP, MEDSKIP, BIGSKIP,
171 len(0.0, LyXLength::PT),
175 VSpace(vspace_kind k) :
177 len (0.0, LyXLength::PT),
181 VSpace(LyXGlueLength l) :
186 VSpace(float v, LyXLength::UNIT u) :
191 /// this constructor is for reading from a .lyx file
193 VSpace(string const & data);
196 vspace_kind kind() const { return kin; }
198 LyXLength length() const { return len; }
200 // a flag that switches between \vspace and \vspace*
201 bool keep() const { return kp; }
203 void setKeep(bool val) { kp = val; }
205 bool operator == (VSpace const &) const;
209 string asLyXCommand() const; // how it goes into the LyX file
211 string asLatexCommand(BufferParams const & params) const;
213 int inPixels(BufferView * bv) const;
215 int inPixels(int default_height, int default_skip) const;