]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
small up/down tweaking
[lyx.git] / src / mathed / math_decorationinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_decorationinset.h"
8 #include "math_support.h"
9 #include "math_parser.h"
10 #include "math_mathmlstream.h"
11 #include "math_streamstr.h"
12 #include "support/LOstream.h"
13
14
15 MathDecorationInset::MathDecorationInset(latexkeys const * key)
16         : MathNestInset(1), key_(key)
17 {}
18
19
20 MathInset * MathDecorationInset::clone() const
21 {
22         return new MathDecorationInset(*this);
23 }
24
25
26 bool MathDecorationInset::upper() const
27 {
28         return key_->name.substr(0, 5) != "under";
29 }
30
31
32 bool MathDecorationInset::isScriptable() const
33 {
34         return
35                         key_->name == "overbrace" ||
36                         key_->name == "underbrace" ||
37                         key_->name == "overleftarrow" ||
38                         key_->name == "overrightarrow" ||
39                         key_->name == "overleftrightarrow" ||
40                         key_->name == "underleftarrow" ||
41                         key_->name == "underrightarrow" ||
42                         key_->name == "underleftrightarrow";
43 }
44
45
46 bool MathDecorationInset::protect() const
47 {
48         return
49                         key_->name == "overbrace" ||
50                         key_->name == "underbrace" ||
51                         key_->name == "overleftarrow" ||
52                         key_->name == "overrightarrow" ||
53                         key_->name == "overleftrightarrow" ||
54                         key_->name == "underleftarrow" ||
55                         key_->name == "underrightarrow" ||
56                         key_->name == "underleftrightarrow";
57 }
58
59
60 bool MathDecorationInset::wide() const
61 {
62         return
63                         key_->name == "overline" ||
64                         key_->name == "underline" ||
65                         key_->name == "overbrace" ||
66                         key_->name == "underbrace" ||
67                         key_->name == "overleftarrow" ||
68                         key_->name == "overrightarrow" ||
69                         key_->name == "overleftrightarrow" ||
70                         key_->name == "widehat" ||
71                         key_->name == "widetilde" ||
72                         key_->name == "underleftarrow" ||
73                         key_->name == "underrightarrow" ||
74                         key_->name == "underleftrightarrow";
75 }
76
77
78 void MathDecorationInset::metrics(MathMetricsInfo & mi) const
79 {
80         cell(0).metrics(mi);
81         dim_ = cell(0).dim();
82         dh_  = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
83         dw_  = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
84
85         if (upper()) {
86                 dy_ = -dim_.a - dh_;
87                 dim_.a += dh_ + 1;
88         } else {
89                 dy_ = dim_.d + 1;
90                 dim_.d += dh_ + 2;
91         }
92
93         metricsMarkers();
94 }
95
96
97 void MathDecorationInset::draw(MathPainterInfo & pi, int x, int y) const
98 {
99         cell(0).draw(pi, x + 1, y);
100         if (wide())
101                 mathed_draw_deco(pi, x + 1, y + dy_, width(), dh_, key_->name);
102         else
103                 mathed_draw_deco(pi, x + 1 + (width() - dw_) / 2, y + dy_, dw_, dh_, key_->name);
104         drawMarkers(pi, x, y);
105 }
106
107
108 void MathDecorationInset::write(WriteStream & os) const
109 {
110         if (os.fragile() && protect())
111                 os << "\\protect";
112         os << '\\' << key_->name << '{' << cell(0) << '}';
113 }
114
115
116 void MathDecorationInset::normalize(NormalStream & os) const
117 {
118         os << "[deco " << key_->name << ' ' <<  cell(0) << ']';
119 }
120
121
122 void MathDecorationInset::infoize(std::ostream & os) const
123 {
124         os << "Deco: " << key_->name;
125 }