2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 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
53 /// Percent of columnwidth both "%" or "%c"
57 /// Percent of pagewidth
59 /// Percent of linewidth
66 LyXLength() : val(0), uni(LyXLength::PT) {}
68 LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
70 /** "data" must be a decimal number, followed by a unit. */
72 LyXLength(string const & data);
75 float value() const { return val; }
77 LyXLength::UNIT unit() const { return uni; }
80 virtual string const asString() const;
82 virtual string const asLatexString() const;
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);
98 bool operator==(LyXLength const & l1, LyXLength const & l2)
100 return l1.value() == l2.value()
101 && l1.unit() == l2.unit();
105 extern LyXLength::UNIT unitFromString (string const & data);
107 extern bool isValidLength(string const & data, LyXLength * result);
109 extern const char * stringFromUnit(int unit);
111 /// LyXGlueLength class
112 class LyXGlueLength : public LyXLength {
115 LyXGlueLength(float v,
118 LyXLength::UNIT pu = LyXLength::UNIT_NONE,
120 LyXLength::UNIT mu = LyXLength::UNIT_NONE)
122 plus_val(pv), minus_val(mv),
123 plus_uni(pu), minus_uni(mu) {}
125 /** "data" must be a decimal number, followed by a unit, and
126 optional "glue" indicated by "+" and "-". You may abbreviate
127 reasonably. Examples:
128 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
129 The traditional Latex format is also accepted, like
130 4cm plus 10pt minus 10pt */
132 LyXGlueLength(string const & data);
135 float plusValue() const { return plus_val; }
137 LyXLength::UNIT plusUnit() const { return plus_uni; }
139 float minusValue() const { return minus_val; }
141 LyXLength::UNIT minusUnit() const { return minus_uni; }
144 virtual string const asString() const;
146 virtual string const asLatexString() const;
149 /** If "data" is valid, the length represented by it is
150 stored into "result", if that is not 0. */
151 friend bool isValidGlueLength(string const & data,
152 LyXGlueLength* result = 0);
160 LyXLength::UNIT plus_uni;
162 LyXLength::UNIT minus_uni;
167 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
169 return l1.value() == l2.value()
170 && l1.unit() == l2.unit()
171 && l1.plusValue() == l2.plusValue()
172 && l1.plusUnit() == l2.plusUnit()
173 && l1.minusValue() == l2.minusValue()
174 && l1.minusUnit() == l2.minusUnit();
179 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
184 /// The different kinds of spaces.
204 len(0.0, LyXLength::PT),
208 VSpace(vspace_kind k) :
210 len (0.0, LyXLength::PT),
214 VSpace(LyXGlueLength l) :
221 VSpace(float v, LyXLength::UNIT u) :
226 /// Constructor for reading from a .lyx file
228 VSpace(string const & data);
231 vspace_kind kind() const { return kin; }
233 LyXGlueLength length() const { return len; }
235 // a flag that switches between \vspace and \vspace*
236 bool keep() const { return kp; }
238 void setKeep(bool val) { kp = val; }
240 bool operator==(VSpace const &) const;
244 string const asLyXCommand() const; // how it goes into the LyX file
246 string const asLatexCommand(BufferParams const & params) const;
248 int inPixels(BufferView * bv) const;
250 int inPixels(int default_height, int default_skip, int default_width=0) const;