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