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/docstring.h"
24 // Solaris/x86 version 9 and earlier define these
30 * LyXLength - Represents latex length measurement
36 SP, ///< Scaled point (65536sp = 1pt) TeX's smallest unit.
37 PT, ///< Point = 1/72.27in = 0.351mm
38 BP, ///< Big point (72bp = 1in), also PostScript point
39 DD, ///< Didot point = 1/72 of a French inch, = 0.376mm
40 MM, ///< Millimeter = 2.845pt
41 PC, ///< Pica = 12pt = 4.218mm
42 CC, ///< Cicero = 12dd = 4.531mm
43 CM, ///< Centimeter = 10mm = 2.371pc
44 IN, ///< Inch = 25.4mm = 72.27pt = 6.022pc
45 EX, ///< Height of a small "x" for the current font.
46 EM, ///< Width of capital "M" in current font.
47 MU, ///< Math unit (18mu = 1em) for positioning in math mode
48 PTW, //< Percent of TextWidth
49 PCW, //< Percent of ColumnWidth
50 PPW, //< Percent of PageWidth
51 PLW, //< Percent of LineWidth
52 PTH, //< Percent of TextHeight // Herbert 2002-05-16
53 PPH, //< Percent of PaperHeight // Herbert 2002-05-16
54 UNIT_NONE ///< no unit
60 LyXLength(double v, LyXLength::UNIT u);
62 /// "data" must be a decimal number, followed by a unit
63 explicit LyXLength(std::string const & data);
65 void swap(LyXLength & rhs)
67 std::swap(val_, rhs.val_);
68 std::swap(unit_, rhs.unit_);
74 LyXLength::UNIT unit() const;
78 void unit(LyXLength::UNIT unit);
83 /// return string representation
84 std::string const asString() const;
85 /// return string representation
86 docstring const asDocstring() const;
87 /// return string representation for LaTeX
88 std::string const asLatexString() const;
89 /// return the on-screen size of this length
90 int inPixels(int text_width, int em_width = 0) const;
91 /// return the on-screen size of this length of an image
94 friend bool isValidLength(std::string const & data, LyXLength * result);
100 LyXLength::UNIT unit_;
104 bool operator==(LyXLength const & l1, LyXLength const & l2);
106 bool operator!=(LyXLength const & l1, LyXLength const & l2);
107 /** Test whether \p data represents a valid length.
109 * \returns whether \p data is a valid length
110 * \param data Length in LyX format. Since the only difference between LyX
111 * and LaTeX format is the representation of length variables as units (e.g.
112 * \c text% vs. \c \\textwidth) you can actually use this function as well
113 * for testing LaTeX lengths as long as they only contain real units like pt.
114 * \param result Pointer to a LyXLength variable. If \p result is not 0 and
115 * \p data is valid, the length represented by it is stored into \p result.
117 bool isValidLength(std::string const & data, LyXLength * result = 0);
118 /// return the LyX name of the given unit number
119 char const * stringFromUnit(int unit);
124 #endif // LYXLENGTH_H