]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
use stream-like syntax for LaTeX output
[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
34                         name_ == "overbrace" ||
35                         name_ == "underbrace" ||
36                         name_ == "overleftarrow" ||
37                         name_ == "overrightarrow";
38 }
39
40
41 bool MathDecorationInset::protect() const
42 {
43         return
44                         name_ == "overbrace" ||
45                         name_ == "underbrace" ||
46                         name_ == "overleftarrow" ||
47                         name_ == "overrightarrow";
48 }
49
50
51 bool MathDecorationInset::wide() const
52 {
53         return
54                         name_ == "overline" ||
55                         name_ == "underline" ||
56                         name_ == "overbrace" ||
57                         name_ == "underbrace" ||
58                         name_ == "overleftarrow" ||
59                         name_ == "overrightarrow" ||
60                         name_ == "widehat" ||
61                         name_ == "widetilde";
62 }
63
64
65 void MathDecorationInset::metrics(MathMetricsInfo const & st) const
66 {
67         xcell(0).metrics(st);
68         size_    = st;
69         width_   = xcell(0).width();
70         ascent_  = xcell(0).ascent();
71         descent_ = xcell(0).descent();
72
73         dh_ = 5; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);  
74
75         if (upper()) {
76                 dy_ = -ascent_ - dh_;
77                 ascent_ += dh_ + 1;
78         } else {
79                 dy_ = descent_ + 1;
80                 descent_ += dh_ + 2;
81         }
82 }
83
84
85 void MathDecorationInset::draw(Painter & pain, int x, int y) const
86
87         xo(x);
88         yo(x);
89         xcell(0).draw(pain, x, y);
90         if (wide()) 
91                 mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
92         else {
93                 int w = 2 + mathed_char_width(LM_TC_VAR, size(), 'x'); 
94                 mathed_draw_deco(pain, x + (width_ - w) / 2, y + dy_, w, dh_, name_);
95         }
96 }
97
98
99 void MathDecorationInset::write(MathWriteInfo & os) const
100 {
101         if (os.fragile && protect())
102                 os << "\\protect";
103         os << '\\' << name_ << '{' << cell(0) << '}';
104 }
105
106
107 void MathDecorationInset::writeNormal(ostream & os) const
108 {
109         os << "[" << name_ << " ";
110         cell(0).writeNormal(os);
111         os << "] ";
112 }