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