]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
remove debug output from last commit
[lyx.git] / src / mathed / math_decorationinset.C
1 /**
2  * \file math_decorationinset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "math_decorationinset.h"
15 #include "math_data.h"
16 #include "math_support.h"
17 #include "math_parser.h"
18 #include "math_mathmlstream.h"
19 #include "math_streamstr.h"
20
21 #include "support/std_ostream.h"
22
23 using std::auto_ptr;
24
25
26 MathDecorationInset::MathDecorationInset(latexkeys const * key)
27         : MathNestInset(1), key_(key)
28 {}
29
30
31 auto_ptr<InsetBase> MathDecorationInset::clone() const
32 {
33         return auto_ptr<InsetBase>(new MathDecorationInset(*this));
34 }
35
36
37 bool MathDecorationInset::upper() const
38 {
39         return key_->name.substr(0, 5) != "under";
40 }
41
42
43 bool MathDecorationInset::isScriptable() 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::protect() const
58 {
59         return
60                         key_->name == "overbrace" ||
61                         key_->name == "underbrace" ||
62                         key_->name == "overleftarrow" ||
63                         key_->name == "overrightarrow" ||
64                         key_->name == "overleftrightarrow" ||
65                         key_->name == "underleftarrow" ||
66                         key_->name == "underrightarrow" ||
67                         key_->name == "underleftrightarrow";
68 }
69
70
71 bool MathDecorationInset::wide() const
72 {
73         return
74                         key_->name == "overline" ||
75                         key_->name == "underline" ||
76                         key_->name == "overbrace" ||
77                         key_->name == "underbrace" ||
78                         key_->name == "overleftarrow" ||
79                         key_->name == "overrightarrow" ||
80                         key_->name == "overleftrightarrow" ||
81                         key_->name == "widehat" ||
82                         key_->name == "widetilde" ||
83                         key_->name == "underleftarrow" ||
84                         key_->name == "underrightarrow" ||
85                         key_->name == "underleftrightarrow";
86 }
87
88
89 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
90 {
91         cell(0).metrics(mi, dim);
92
93         dh_  = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
94         dw_  = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
95
96         if (upper()) {
97                 dy_ = -dim.asc - dh_;
98                 dim.asc += dh_ + 1;
99         } else {
100                 dy_ = dim.des + 1;
101                 dim.des += dh_ + 2;
102         }
103
104         metricsMarkers(dim);
105         dim_ = dim;
106 }
107
108
109 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
110 {
111         cell(0).draw(pi, x + 1, y);
112         if (wide())
113                 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
114         else
115                 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
116                         y + dy_, dw_, dh_, key_->name);
117         drawMarkers(pi, x, y);
118 }
119
120
121 void MathDecorationInset::write(WriteStream & os) const
122 {
123         if (os.fragile() && protect())
124                 os << "\\protect";
125         os << '\\' << key_->name << '{' << cell(0) << '}';
126 }
127
128
129 void MathDecorationInset::normalize(NormalStream & os) const
130 {
131         os << "[deco " << key_->name << ' ' <<  cell(0) << ']';
132 }
133
134
135 void MathDecorationInset::infoize(std::ostream & os) const
136 {
137         os << "Deco: " << key_->name;
138 }