]> git.lyx.org Git - features.git/blob - src/mathed/math_decorationinset.C
11d5ff0f344e24c792bb36475ae275bc7ec78ad5
[features.git] / src / mathed / math_decorationinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_decorationinset.h"
6 #include "mathed/support.h"
7 #include "math_parser.h"
8 #include "support/LOstream.h"
9
10
11 using std::ostream;
12
13
14 MathDecorationInset::MathDecorationInset(latexkeys const * key)
15         : MathNestInset(1), key_(key)
16 {
17 }
18
19
20 MathInset * MathDecorationInset::clone() const
21 {   
22         return new MathDecorationInset(*this);
23 }
24
25
26 bool MathDecorationInset::upper() const
27 {
28         return key_->id != LM_underline && key_->id != LM_underbrace;
29 }
30
31
32 bool MathDecorationInset::protect() const
33 {
34         return
35                         key_->name == "overbrace" ||
36                         key_->name == "underbrace" ||
37                         key_->name == "overleftarrow" ||
38                         key_->name == "overrightarrow";
39 }
40
41
42 void MathDecorationInset::metrics(MathStyles st) const
43 {
44         xcell(0).metrics(st);
45         size_    = st;
46         width_   = xcell(0).width();
47         ascent_  = xcell(0).ascent();
48         descent_ = xcell(0).descent();
49
50         dh_ = 5; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);  
51
52         if (upper()) {
53                 dy_ = -ascent_ - dh_;
54                 ascent_ += dh_ + 1;
55         } else {
56                 dy_ = descent_ + 1;
57                 descent_ += dh_ + 2;
58         }
59
60         if (key_->id == LM_not) {
61                 ascent_  += dh_;
62                 descent_ += dh_;
63                 dh_ = height();
64                 dy_ = - ascent_;
65         }
66 }
67
68 void MathDecorationInset::draw(Painter & pain, int x, int y) const
69
70         xo(x);
71         yo(x);
72         xcell(0).draw(pain, x, y);
73         mathed_draw_deco(pain, x, y + dy_, width_, dh_, key_);
74 }
75
76
77 void MathDecorationInset::write(ostream & os, bool fragile) const
78 {
79         if (fragile && protect())
80                 os << "\\protect";
81         os << '\\' << key_->name;
82
83         if (key_->id == LM_not)
84                 os << ' ';
85         else
86                 os << '{';
87
88         cell(0).write(os, fragile);  
89
90         if (key_->id != LM_not)
91                 os << '}';
92 }
93
94
95 void MathDecorationInset::writeNormal(ostream & os) const
96 {
97         os << "[" << key_->name << " ";
98         cell(0).writeNormal(os);
99         os << "] ";
100 }