]> git.lyx.org Git - features.git/blob - src/mathed/math_decorationinset.C
remove symbol_def.h
[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(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::protect() const
32 {
33         return
34                         name_ == "overbrace" ||
35                         name_ == "underbrace" ||
36                         name_ == "overleftarrow" ||
37                         name_ == "overrightarrow";
38 }
39
40
41 void MathDecorationInset::metrics(MathStyles st) const
42 {
43         xcell(0).metrics(st);
44         size_    = st;
45         width_   = xcell(0).width();
46         ascent_  = xcell(0).ascent();
47         descent_ = xcell(0).descent();
48
49         dh_ = 5; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);  
50
51         if (upper()) {
52                 dy_ = -ascent_ - dh_;
53                 ascent_ += dh_ + 1;
54         } else {
55                 dy_ = descent_ + 1;
56                 descent_ += dh_ + 2;
57         }
58 }
59
60
61 void MathDecorationInset::draw(Painter & pain, int x, int y) const
62
63         xo(x);
64         yo(x);
65         xcell(0).draw(pain, x, y);
66         mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
67 }
68
69
70 void MathDecorationInset::write(ostream & os, bool fragile) const
71 {
72         if (fragile && protect())
73                 os << "\\protect";
74         os << '\\' << name_ << '{';
75         cell(0).write(os, fragile);  
76         os << '}';
77 }
78
79
80 void MathDecorationInset::writeNormal(ostream & os) const
81 {
82         os << "[" << name_ << " ";
83         cell(0).writeNormal(os);
84         os << "] ";
85 }