]> git.lyx.org Git - lyx.git/blob - src/lyxlength.h
caba9ee171ab2f2ce14f222dae5347871defc8b4
[lyx.git] / src / lyxlength.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *      
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef LYX_LENGTH_H
13 #define LYX_LENGTH_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "LString.h"
20
21 class BufferView;
22
23 //
24 ///  LyXLength Class
25 //
26 class LyXLength {
27 public:
28         /// length units
29         enum UNIT {
30                 /// Scaled point (65536sp = 1pt) TeX's smallest unit.
31                 SP,
32                 /// Point = 1/72.27in = 0.351mm
33                 PT,
34                 /// Big point (72bp = 1in), also PostScript point
35                 BP,
36                 /// Didot point = 1/72 of a French inch, = 0.376mm
37                 DD,
38                 /// Millimeter = 2.845pt
39                 MM,
40                 /// Pica = 12pt = 4.218mm
41                 PC,
42                 /// Cicero = 12dd = 4.531mm
43                 CC,
44                 /// Centimeter = 10mm = 2.371pc
45                 CM,
46                 /// Inch = 25.4mm = 72.27pt = 6.022pc
47                 IN,
48                 /// Height of a small "x" for the current font.
49                 EX,
50                 /// Width of capital "M" in current font.
51                 EM,
52                 /// Math unit (18mu = 1em) for positioning in math mode
53                 MU,
54                 /// Percent of columnwidth both "%" or "%c"
55                 PW,
56                 ///
57                 PE,
58                 /// Percent of pagewidth
59                 PP,
60                 /// Percent of linewidth
61                 PL,
62                 /// no unit
63                 UNIT_NONE
64         };
65
66         ///
67         LyXLength();
68         ///
69         LyXLength(double v, LyXLength::UNIT u);
70
71         /// "data" must be a decimal number, followed by a unit
72         explicit LyXLength(string const & data);
73
74         ///
75         double value() const;
76         ///
77         LyXLength::UNIT unit() const;
78         ///
79         void value(double);
80         ///
81         void unit(LyXLength::UNIT unit);
82         ///
83         bool zero() const;
84         /// conversion
85         string const asString() const;
86         ///
87         string const asLatexString() const;
88         ///
89         int inPixels(BufferView const * bv) const;
90
91         /** If "data" is valid, the length represented by it is
92           stored into "result", if that is not 0. */
93         friend bool isValidLength(string const & data, LyXLength * result = 0);
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 ///
107 bool isValidLength(string const & data, LyXLength * result);
108 ///
109 char const * stringFromUnit(int unit);
110
111 #endif