]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
Fix for mis-drawing reported by Dekel
[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 "mathed/support.h"
9 #include "math_parser.h"
10 #include "support/LOstream.h"
11 #include "support/lstrings.h"
12
13
14 using std::ostream;
15
16
17 MathDecorationInset::MathDecorationInset(int d)
18         : MathInset("", LM_OT_DECO, 1), deco_(d)
19 {
20         upper_ = deco_ != LM_underline && deco_ != LM_underbrace;
21 }
22
23
24 MathInset * MathDecorationInset::clone() const
25 {   
26         return new MathDecorationInset(*this);
27 }
28
29
30
31 void MathDecorationInset::Metrics(MathStyles st)
32 {
33         int const h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I',
34                                              ascent_, descent_);  
35         xcell(0).Metrics(st);
36         width_   = xcell(0).width();
37         ascent_  = xcell(0).ascent();
38         descent_ = xcell(0).descent();
39
40         int w = width() + 4;
41
42         dh_ = w / 5;
43         if (dh_ > h)
44                 dh_ = h;
45
46         if (upper_) {
47                 ascent_ += dh_ + 2;
48                 dy_ = -ascent_;
49         } else {
50                 dy_ = descent_ + 2;
51                 descent_ += dh_ + 4;
52         }
53         width_ = w;
54 }
55
56 void MathDecorationInset::draw(Painter & pain, int x, int y)
57
58         xo(x);
59         yo(x);
60         xcell(0).draw(pain, x, y);
61         mathed_draw_deco(pain, x, y + dy_, width_, dh_, deco_);
62 }
63
64
65 void MathDecorationInset::Write(ostream & os, bool fragile) const
66 {
67         latexkeys const * l = lm_get_key_by_id(deco_, LM_TK_WIDE);
68         if (fragile &&
69             (compare(l->name, "overbrace") == 0 ||
70              compare(l->name, "underbrace") == 0 ||
71              compare(l->name, "overleftarrow") == 0 ||
72              compare(l->name, "overrightarrow") == 0))
73                 os << "\\protect";
74         os << '\\' << l->name << '{';
75         cell(0).Write(os, fragile);  
76         os << '}';
77 }