]> git.lyx.org Git - lyx.git/blob - src/lyxlength.h
cleanup some debug messages
[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 // Solaris/x86 version 9 and earlier define these
21 #ifdef PC
22 #  undef PC
23 #endif
24 #ifdef SP
25 #  undef SP
26 #endif
27
28
29 /**
30  * LyXLength - Represents latex length measurement
31  */
32 class LyXLength {
33 public:
34         /// length units
35         enum UNIT {
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
55         };
56
57         ///
58         LyXLength();
59         ///
60         LyXLength(double v, LyXLength::UNIT u);
61
62         /// "data" must be a decimal number, followed by a unit
63         explicit LyXLength(std::string const & data);
64
65         void swap(LyXLength & rhs)
66         {
67                 std::swap(val_, rhs.val_);
68                 std::swap(unit_, rhs.unit_);
69         }
70
71         ///
72         double value() const;
73         ///
74         LyXLength::UNIT unit() const;
75         ///
76         void value(double);
77         ///
78         void unit(LyXLength::UNIT unit);
79         ///
80         bool zero() const;
81         ///
82         bool empty() const;
83         /// return string representation
84         std::string const asString() const;
85         /// return string representation for LaTeX
86         std::string const asLatexString() const;
87         /// return the on-screen size of this length
88         int inPixels(int text_width, int em_width = 0) const;
89         /// return the on-screen size of this length of an image
90         int inBP() const;
91
92         friend bool isValidLength(std::string const & data, LyXLength * result);
93
94 private:
95         ///
96         double          val_;
97         ///
98         LyXLength::UNIT unit_;
99 };
100
101 ///
102 bool operator==(LyXLength const & l1, LyXLength const & l2);
103 ///
104 bool operator!=(LyXLength const & l1, LyXLength const & l2);
105 /** If "data" is valid, the length represented by it is
106     stored into "result", if that is not 0. */
107 bool isValidLength(std::string const & data, LyXLength * result = 0);
108 /// return the name of the given unit number
109 char const * stringFromUnit(int unit);
110
111 #endif // LYXLENGTH_H