4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Matthias Ettrich
8 * \author Lars Gullik Bjønnes
9 * \author Jean-Marc Lasgouttes
12 * Full author contact details are available in file CREDITS.
18 #include "support/strfwd.h"
25 // Solaris/x86 version 9 and earlier define these
29 /////////////////////////////////////////////////////////////////////
33 /////////////////////////////////////////////////////////////////////
37 * Length - Represents latex length measurement
43 BP, ///< Big point (72bp = 1in), also PostScript point
44 CC, ///< Cicero = 12dd = 4.531mm
45 CM, ///< Centimeter = 10mm = 2.371pc
46 DD, ///< Didot point = 1/72 of a French inch, = 0.376mm
47 EM, ///< Width of capital "M" in current font.
48 EX, ///< Height of a small "x" for the current font.
49 IN, ///< Inch = 25.4mm = 72.27pt = 6.022pc
50 MM, ///< Millimeter = 2.845pt
51 MU, ///< Math unit (18mu = 1em) for positioning in math mode
52 PC, ///< Pica = 12pt = 4.218mm
53 PT, ///< Point = 1/72.27in = 0.351mm
54 SP, ///< Scaled point (65536sp = 1pt) TeX's smallest unit.
55 PTW, //< Percent of TextWidth
56 PCW, //< Percent of ColumnWidth
57 PPW, //< Percent of PageWidth
58 PLW, //< Percent of LineWidth
59 PTH, //< Percent of TextHeight // Herbert 2002-05-16
60 PPH, //< Percent of PaperHeight // Herbert 2002-05-16
61 UNIT_NONE ///< no unit
67 Length(double v, Length::UNIT u);
69 /// "data" must be a decimal number, followed by a unit
70 explicit Length(std::string const & data);
75 Length::UNIT unit() const;
79 void unit(Length::UNIT unit);
84 /// return string representation
85 std::string const asString() const;
86 /// return string representation
87 docstring const asDocstring() const;
88 /// return string representation for LaTeX
89 std::string const asLatexString() const;
90 /// return string representation for HTML
91 std::string const asHTMLString() const;
92 /** return the on-screen size of this length.
94 * If the second argument is not provided, then the unit EM will
95 * only be approximated. It is better if possible to use
96 * FontMetrics::em() to get this value.
98 int inPixels(int text_width, int em_width = 0) const;
99 /** return the on-screen size of this length
101 * This version of the function uses the right EM definition.
103 int inPixels(MetricsBase const &) const;
104 /// return the value in Big Postscript points.
107 /// return the default unit (centimeter or inch)
108 static UNIT defaultUnit();
110 friend bool isValidLength(std::string const & data, Length * result);
120 bool operator==(Length const & l1, Length const & l2);
122 bool operator!=(Length const & l1, Length const & l2);
123 /** Test whether \p data represents a valid length.
125 * \returns whether \p data is a valid length
126 * \param data Length in LyX format. Since the only difference between LyX
127 * and LaTeX format is the representation of length variables as units (e.g.
128 * \c text% vs. \c \\textwidth) you can actually use this function as well
129 * for testing LaTeX lengths as long as they only contain real units like pt.
130 * \param result Pointer to a Length variable. If \p result is not 0 and
131 * \p data is valid, the length represented by it is stored into \p result.
133 bool isValidLength(std::string const & data, Length * result = 0);
134 /// return the LyX name of the given unit number
135 char const * stringFromUnit(int unit);
138 /////////////////////////////////////////////////////////////////////
142 /////////////////////////////////////////////////////////////////////
149 explicit GlueLength(Length const & len);
151 GlueLength(Length const & len,
153 Length const & minus);
155 /** "data" must be a decimal number, followed by a unit, and
156 optional "glue" indicated by "+" and "-". You may abbreviate
157 reasonably. Examples:
158 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
159 The traditional Latex format is also accepted, like
160 4cm plus 10pt minus 10pt */
161 explicit GlueLength(std::string const & data);
164 Length const & len() const;
166 Length const & plus() const;
168 Length const & minus() const;
172 std::string const asString() const;
174 std::string const asLatexString() const;
176 friend bool isValidGlueLength(std::string const & data,
189 bool operator==(GlueLength const & l1, GlueLength const & l2);
191 bool operator!=(GlueLength const & l1, GlueLength const & l2);
192 /** If "data" is valid, the length represented by it is
193 stored into "result", if that is not 0. */
194 bool isValidGlueLength(std::string const & data, GlueLength * result = 0);
196 /// the number of units possible
197 extern int const num_units;
200 * array of unit names
202 * FIXME: I am not sure if "mu" should be possible to select (Lgb)
204 extern char const * const unit_name[];
205 extern char const * const unit_name_gui[];
207 /// return the unit given a string representation such as "cm"
208 Length::UNIT unitFromString(std::string const & data);