]> git.lyx.org Git - lyx.git/blob - src/lyxlength.h
fix typo in commit 16925
[lyx.git] / src / lyxlength.h
1 // -*- C++ -*-
2 /**
3  * \file lyxlength.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Matthias Ettrich
8  * \author Lars Gullik Bjønnes
9  * \author Jean-Marc Lasgouttes
10  * \author John Levon
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef LYX_LENGTH_H
16 #define LYX_LENGTH_H
17
18 #include "support/docstring.h"
19
20
21 namespace lyx {
22
23 // Solaris/x86 version 9 and earlier define these
24 #undef PC
25 #undef SP
26
27
28 /**
29  * LyXLength - Represents latex length measurement
30  */
31 class LyXLength {
32 public:
33         /// length units
34         enum UNIT {
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
54         };
55
56         ///
57         LyXLength();
58         ///
59         LyXLength(double v, LyXLength::UNIT u);
60
61         /// "data" must be a decimal number, followed by a unit
62         explicit LyXLength(std::string const & data);
63
64         void swap(LyXLength & rhs)
65         {
66                 std::swap(val_, rhs.val_);
67                 std::swap(unit_, rhs.unit_);
68         }
69
70         ///
71         double value() const;
72         ///
73         LyXLength::UNIT unit() const;
74         ///
75         void value(double);
76         ///
77         void unit(LyXLength::UNIT unit);
78         ///
79         bool zero() const;
80         ///
81         bool empty() const;
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
91         int inBP() const;
92
93         friend bool isValidLength(std::string const & data, LyXLength * result);
94
95 private:
96         ///
97         double          val_;
98         ///
99         LyXLength::UNIT unit_;
100 };
101
102 ///
103 bool operator==(LyXLength const & l1, LyXLength const & l2);
104 ///
105 bool operator!=(LyXLength const & l1, LyXLength const & l2);
106 /** Test whether \p data represents a valid length.
107  * 
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.
115  */
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);
119
120
121 } // namespace lyx
122
123 #endif // LYXLENGTH_H