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