]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
IU of drawing phase one without 'semantic changes' as requested by John
[lyx.git] / src / mathed / math_decorationinset.C
1 #include <config.h>
2
3
4 #include "math_decorationinset.h"
5 #include "math_support.h"
6 #include "math_parser.h"
7 #include "math_mathmlstream.h"
8 #include "math_streamstr.h"
9 #include "support/LOstream.h"
10
11
12 MathDecorationInset::MathDecorationInset(latexkeys const * key)
13         : MathNestInset(1), key_(key)
14 {}
15
16
17 MathInset * MathDecorationInset::clone() const
18 {
19         return new MathDecorationInset(*this);
20 }
21
22
23 bool MathDecorationInset::upper() const
24 {
25         return key_->name.substr(0, 5) != "under";
26 }
27
28
29 bool MathDecorationInset::isScriptable() const
30 {
31         return
32                         key_->name == "overbrace" ||
33                         key_->name == "underbrace" ||
34                         key_->name == "overleftarrow" ||
35                         key_->name == "overrightarrow" ||
36                         key_->name == "overleftrightarrow" ||
37                         key_->name == "underleftarrow" ||
38                         key_->name == "underrightarrow" ||
39                         key_->name == "underleftrightarrow";
40 }
41
42
43 bool MathDecorationInset::protect() const
44 {
45         return
46                         key_->name == "overbrace" ||
47                         key_->name == "underbrace" ||
48                         key_->name == "overleftarrow" ||
49                         key_->name == "overrightarrow" ||
50                         key_->name == "overleftrightarrow" ||
51                         key_->name == "underleftarrow" ||
52                         key_->name == "underrightarrow" ||
53                         key_->name == "underleftrightarrow";
54 }
55
56
57 bool MathDecorationInset::wide() const
58 {
59         return
60                         key_->name == "overline" ||
61                         key_->name == "underline" ||
62                         key_->name == "overbrace" ||
63                         key_->name == "underbrace" ||
64                         key_->name == "overleftarrow" ||
65                         key_->name == "overrightarrow" ||
66                         key_->name == "overleftrightarrow" ||
67                         key_->name == "widehat" ||
68                         key_->name == "widetilde" ||
69                         key_->name == "underleftarrow" ||
70                         key_->name == "underrightarrow" ||
71                         key_->name == "underleftrightarrow";
72 }
73
74
75 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
76 {
77         cell(0).metrics(mi);
78         dim_ = cell(0).dim();
79
80         dh_  = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
81         dw_  = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
82
83         if (upper()) {
84                 dy_ = -dim_.asc - dh_;
85                 dim_.asc += dh_ + 1;
86         } else {
87                 dy_ = dim_.des + 1;
88                 dim_.des += dh_ + 2;
89         }
90
91         metricsMarkers();
92         dim = dim_;
93 }
94
95
96 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
97 {
98         cell(0).draw(pi, x + 1, y);
99         if (wide())
100                 mathed_draw_deco(pi, x + 1, y + dy_, pi.width, dh_, key_->name);
101         else
102                 mathed_draw_deco(pi, x + 1 + (pi.width - dw_) / 2,
103                         y + dy_, dw_, dh_, key_->name);
104         drawMarkers(pi, x, y);
105 }
106
107
108 void MathDecorationInset::write(WriteStream & os) const
109 {
110         if (os.fragile() && protect())
111                 os << "\\protect";
112         os << '\\' << key_->name << '{' << cell(0) << '}';
113 }
114
115
116 void MathDecorationInset::normalize(NormalStream & os) const
117 {
118         os << "[deco " << key_->name << ' ' <<  cell(0) << ']';
119 }
120
121
122 void MathDecorationInset::infoize(std::ostream & os) const
123 {
124         os << "Deco: " << key_->name;
125 }