]> git.lyx.org Git - features.git/blob - src/mathed/math_decorationinset.C
make on-screen appearance of nested delimiters closer to what LaTeX does
[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         string name = key_->name;
80         if (fragile && protect())
81                 os << "\\protect";
82         os << '\\' << name;
83
84         if (key_->id == LM_not)
85                 os << ' ';
86         else
87                 os << '{';
88
89         cell(0).write(os, fragile);  
90
91         if (key_->id != LM_not)
92                 os << '}';
93 }
94
95
96 void MathDecorationInset::writeNormal(ostream & os) const
97 {
98         os << "[" << key_->name << " ";
99         cell(0).writeNormal(os);
100         os << "] ";
101 }