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