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