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