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"
23 // Solaris/x86 version 9 and earlier define these
27 /////////////////////////////////////////////////////////////////////
31 /////////////////////////////////////////////////////////////////////
35 * Length - Represents latex length measurement
41 SP, ///< Scaled point (65536sp = 1pt) TeX's smallest unit.
42 PT, ///< Point = 1/72.27in = 0.351mm
43 BP, ///< Big point (72bp = 1in), also PostScript point
44 DD, ///< Didot point = 1/72 of a French inch, = 0.376mm
45 MM, ///< Millimeter = 2.845pt
46 PC, ///< Pica = 12pt = 4.218mm
47 CC, ///< Cicero = 12dd = 4.531mm
48 CM, ///< Centimeter = 10mm = 2.371pc
49 IN, ///< Inch = 25.4mm = 72.27pt = 6.022pc
50 EX, ///< Height of a small "x" for the current font.
51 EM, ///< Width of capital "M" in current font.
52 MU, ///< Math unit (18mu = 1em) for positioning in math mode
53 PTW, //< Percent of TextWidth
54 PCW, //< Percent of ColumnWidth
55 PPW, //< Percent of PageWidth
56 PLW, //< Percent of LineWidth
57 PTH, //< Percent of TextHeight // Herbert 2002-05-16
58 PPH, //< Percent of PaperHeight // Herbert 2002-05-16
59 UNIT_NONE ///< no unit
65 Length(double v, Length::UNIT u);
67 /// "data" must be a decimal number, followed by a unit
68 explicit Length(std::string const & data);
71 void swap(Length & rhs);
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 the on-screen size of this length
91 int inPixels(int text_width, int em_width = 0) const;
92 /// return the on-screen size of this length of an image
95 friend bool isValidLength(std::string const & data, Length * result);
105 bool operator==(Length const & l1, Length const & l2);
107 bool operator!=(Length const & l1, Length const & l2);
108 /** Test whether \p data represents a valid length.
110 * \returns whether \p data is a valid length
111 * \param data Length in LyX format. Since the only difference between LyX
112 * and LaTeX format is the representation of length variables as units (e.g.
113 * \c text% vs. \c \\textwidth) you can actually use this function as well
114 * for testing LaTeX lengths as long as they only contain real units like pt.
115 * \param result Pointer to a Length variable. If \p result is not 0 and
116 * \p data is valid, the length represented by it is stored into \p result.
118 bool isValidLength(std::string const & data, Length * result = 0);
119 /// return the LyX name of the given unit number
120 char const * stringFromUnit(int unit);
123 /////////////////////////////////////////////////////////////////////
127 /////////////////////////////////////////////////////////////////////
134 explicit GlueLength(Length const & len);
136 GlueLength(Length const & len,
138 Length const & minus);
140 /** "data" must be a decimal number, followed by a unit, and
141 optional "glue" indicated by "+" and "-". You may abbreviate
142 reasonably. Examples:
143 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
144 The traditional Latex format is also accepted, like
145 4cm plus 10pt minus 10pt */
146 explicit GlueLength(std::string const & data);
149 Length const & len() const;
151 Length const & plus() const;
153 Length const & minus() const;
157 std::string const asString() const;
159 std::string const asLatexString() const;
161 friend bool isValidGlueLength(std::string const & data,
174 bool operator==(GlueLength const & l1, GlueLength const & l2);
176 bool operator!=(GlueLength const & l1, GlueLength const & l2);
177 /** If "data" is valid, the length represented by it is
178 stored into "result", if that is not 0. */
179 bool isValidGlueLength(std::string const & data, GlueLength * result = 0);
181 /// the number of units possible
182 extern int const num_units;
185 * array of unit names
187 * FIXME: I am not sure if "mu" should be possible to select (Lgb)
189 extern char const * const unit_name[];
190 extern char const * const unit_name_gui[];
192 /// return the unit given a string representation such as "cm"
193 Length::UNIT unitFromString(std::string const & data);