]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
Otto's \underrightarrow/\underleftarrow patch
[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
28                         name_ != "underbar" &&
29                         name_ != "underline" &&
30                         name_ != "underbrace" &&
31                         name_ != "underleftarrow" &&
32                         name_ != "underrightarrow";
33 }
34
35
36 bool MathDecorationInset::isScriptable() const
37 {
38         return
39                         name_ == "overbrace" ||
40                         name_ == "underbrace" ||
41                         name_ == "overleftarrow" ||
42                         name_ == "overrightarrow" ||
43                         name_ == "underleftarrow" ||
44                         name_ == "underrightarrow";
45 }
46
47
48 bool MathDecorationInset::protect() const
49 {
50         return
51                         name_ == "overbrace" ||
52                         name_ == "underbrace" ||
53                         name_ == "overleftarrow" ||
54                         name_ == "overrightarrow" ||
55                         name_ == "underleftarrow" ||
56                         name_ == "underrightarrow";
57 }
58
59
60 bool MathDecorationInset::wide() const
61 {
62         return
63                         name_ == "overline" ||
64                         name_ == "underline" ||
65                         name_ == "overbrace" ||
66                         name_ == "underbrace" ||
67                         name_ == "overleftarrow" ||
68                         name_ == "overrightarrow" ||
69                         name_ == "widehat" ||
70                         name_ == "widetilde" ||
71                         name_ == "underleftarrow" ||
72                         name_ == "underrightarrow";
73 }
74
75
76 void MathDecorationInset::metrics(MathMetricsInfo const & st) const
77 {
78         xcell(0).metrics(st);
79         size_    = st;
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, size(), 'I', ascent_, descent_);  
85
86         if (upper()) {
87                 dy_ = -ascent_ - dh_;
88                 ascent_ += dh_ + 1;
89         } else {
90                 dy_ = descent_ + 1;
91                 descent_ += dh_ + 2;
92         }
93 }
94
95
96 void MathDecorationInset::draw(Painter & pain, int x, int y) const
97
98         xcell(0).draw(pain, x, y);
99         if (wide()) 
100                 mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
101         else {
102                 int w = mathed_char_width(LM_TC_VAR, size_, 'x'); 
103                 mathed_draw_deco(pain, x + (width_ - w) / 2, y + dy_, w, dh_, name_);
104         }
105 }
106
107
108 void MathDecorationInset::write(WriteStream & os) const
109 {
110         if (os.fragile() && protect())
111                 os << "\\protect";
112         os << '\\' << name_ << '{' << cell(0) << '}';
113 }
114
115
116 void MathDecorationInset::normalize(NormalStream & os) const
117 {
118         os << "[deco " << name_ << ' ' <<  cell(0) << ']';
119 }