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