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"
56 /// Percent of pagewidth
58 /// Percent of linewidth
65 LyXLength() : val(0), uni(LyXLength::PT) {}
67 LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
69 /** "data" must be a decimal number, followed by a unit. */
71 LyXLength(string const & data);
74 float value() const { return val; }
76 LyXLength::UNIT unit() const { return uni; }
79 virtual string const asString() const;
81 virtual string const asLatexString() const;
83 /** If "data" is valid, the length represented by it is
84 stored into "result", if that is not 0. */
85 friend bool isValidLength(string const & data,
86 LyXLength * result = 0);
97 bool operator==(LyXLength const & l1, LyXLength const & l2)
99 return l1.value() == l2.value()
100 && l1.unit() == l2.unit();
104 extern LyXLength::UNIT unitFromString (string const & data);
106 extern bool isValidLength(string const & data, LyXLength * result);
108 extern const char * stringFromUnit(int unit);
110 /// LyXGlueLength class
111 class LyXGlueLength : public LyXLength {
114 LyXGlueLength(float v,
117 LyXLength::UNIT pu = LyXLength::UNIT_NONE,
119 LyXLength::UNIT mu = LyXLength::UNIT_NONE)
121 plus_val(pv), minus_val(mv),
122 plus_uni(pu), minus_uni(mu) {}
124 /** "data" must be a decimal number, followed by a unit, and
125 optional "glue" indicated by "+" and "-". You may abbreviate
126 reasonably. Examples:
127 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
128 The traditional Latex format is also accepted, like
129 4cm plus 10pt minus 10pt */
131 LyXGlueLength(string const & data);
134 float plusValue() const { return plus_val; }
136 LyXLength::UNIT plusUnit() const { return plus_uni; }
138 float minusValue() const { return minus_val; }
140 LyXLength::UNIT minusUnit() const { return minus_uni; }
143 virtual string const asString() const;
145 virtual string const asLatexString() const;
148 /** If "data" is valid, the length represented by it is
149 stored into "result", if that is not 0. */
150 friend bool isValidGlueLength(string const & data,
151 LyXGlueLength* result = 0);
159 LyXLength::UNIT plus_uni;
161 LyXLength::UNIT minus_uni;
166 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
168 return l1.value() == l2.value()
169 && l1.unit() == l2.unit()
170 && l1.plusValue() == l2.plusValue()
171 && l1.plusUnit() == l2.plusUnit()
172 && l1.minusValue() == l2.minusValue()
173 && l1.minusUnit() == l2.minusUnit();
178 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
183 /// The different kinds of spaces.
203 len(0.0, LyXLength::PT),
207 VSpace(vspace_kind k) :
209 len (0.0, LyXLength::PT),
213 VSpace(LyXGlueLength l) :
220 VSpace(float v, LyXLength::UNIT u) :
225 /// Constructor for reading from a .lyx file
227 VSpace(string const & data);
230 vspace_kind kind() const { return kin; }
232 LyXGlueLength length() const { return len; }
234 // a flag that switches between \vspace and \vspace*
235 bool keep() const { return kp; }
237 void setKeep(bool val) { kp = val; }
239 bool operator==(VSpace const &) const;
243 string const asLyXCommand() const; // how it goes into the LyX file
245 string const asLatexCommand(BufferParams const & params) const;
247 int inPixels(BufferView * bv) const;
249 int inPixels(int default_height, int default_skip, int default_width=0) const;