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