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