]> git.lyx.org Git - lyx.git/blob - src/lyxlength.h
avoid to update when navigating
[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 <string>
19
20 /**
21  * LyXLength - Represents latex length measurement
22  */
23 class LyXLength {
24 public:
25         /// length units
26         enum UNIT {
27                 SP, ///< Scaled point (65536sp = 1pt) TeX's smallest unit.
28                 PT, ///< Point = 1/72.27in = 0.351mm
29                 BP, ///< Big point (72bp = 1in), also PostScript point
30                 DD, ///< Didot point = 1/72 of a French inch, = 0.376mm
31                 MM, ///< Millimeter = 2.845pt
32                 PC, ///< Pica = 12pt = 4.218mm
33                 CC, ///< Cicero = 12dd = 4.531mm
34                 CM, ///< Centimeter = 10mm = 2.371pc
35                 IN, ///< Inch = 25.4mm = 72.27pt = 6.022pc
36                 EX, ///< Height of a small "x" for the current font.
37                 EM, ///< Width of capital "M" in current font.
38                 MU, ///< Math unit (18mu = 1em) for positioning in math mode
39                 PTW, //< Percent of TextWidth
40                 PCW, //< Percent of ColumnWidth
41                 PPW, //< Percent of PageWidth
42                 PLW, //< Percent of LineWidth
43                 PTH, //< Percent of TextHeight          // Herbert 2002-05-16
44                 PPH, //< Percent of PaperHeight         // Herbert 2002-05-16
45                 UNIT_NONE ///< no unit
46         };
47
48         ///
49         LyXLength();
50         ///
51         LyXLength(double v, LyXLength::UNIT u);
52
53         /// "data" must be a decimal number, followed by a unit
54         explicit LyXLength(std::string const & data);
55
56         ///
57         double value() const;
58         ///
59         LyXLength::UNIT unit() const;
60         ///
61         void value(double);
62         ///
63         void unit(LyXLength::UNIT unit);
64         ///
65         bool zero() const;
66         ///
67         bool empty() const;
68         /// return string representation
69         std::string const asString() const;
70         /// return string representation for LaTeX
71         std::string const asLatexString() const;
72         /// return the on-screen size of this length
73         int inPixels(int text_width, int em_width = 0) const;
74         /// return the on-screen size of this length of an image
75         int inBP() const;
76
77         friend bool isValidLength(std::string const & data, LyXLength * result);
78
79 private:
80         ///
81         double          val_;
82         ///
83         LyXLength::UNIT unit_;
84 };
85
86 ///
87 bool operator==(LyXLength const & l1, LyXLength const & l2);
88 ///
89 bool operator!=(LyXLength const & l1, LyXLength const & l2);
90 /** If "data" is valid, the length represented by it is
91     stored into "result", if that is not 0. */
92 bool isValidLength(std::string const & data, LyXLength * result = 0);
93 /// return the name of the given unit number
94 char const * stringFromUnit(int unit);
95
96 #endif // LYXLENGTH_H