]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCancel.cpp
Merge branch 'master' into biblatex2
[lyx.git] / src / mathed / InsetMathCancel.cpp
1 /**
2  * \file InsetMathCancel.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Uwe Stöhr
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathCancel.h"
14
15 #include "MathStream.h"
16
17 #include "LaTeXFeatures.h"
18 #include "MetricsInfo.h"
19
20 #include "frontends/Painter.h"
21
22 #include <ostream>
23
24 namespace lyx {
25
26
27 InsetMathCancel::InsetMathCancel(Buffer * buf, Kind k)
28         : InsetMathNest(buf, 1), kind_(k)
29 {}
30
31
32 Inset * InsetMathCancel::clone() const
33 {
34         return new InsetMathCancel(*this);
35 }
36
37
38 void InsetMathCancel::metrics(MetricsInfo & mi, Dimension & dim) const
39 {
40         Changer dummy = mi.base.changeEnsureMath();
41         cell(0).metrics(mi, dim);
42         metricsMarkers(mi, dim);
43 }
44
45
46 void InsetMathCancel::draw(PainterInfo & pi, int x, int y) const
47 {
48         Changer dummy = pi.base.changeEnsureMath();
49         // We first draw the text and then an arrow
50         ColorCode const origcol = pi.base.font.color();
51         cell(0).draw(pi, x + 1, y);
52         Dimension const dim = dimension(*pi.base.bv);
53         int const t = pi.base.solidLineThickness();
54
55         /*
56          * y1 \    /
57          *     \  /
58          *      \/
59          *      /\
60          *     /  \
61          * y2 /    \
62          *    x1  x2
63          */
64
65         int const x2 = x + dim.wid;
66         int const x1 = x;
67         int const y1 = y - dim.asc;
68         int const y2 = y + dim.des;
69
70         if (kind_ == cancel)
71                 pi.pain.line(x2, y1, x1, y2, origcol, pi.pain.line_solid, t);
72         else if (kind_ == bcancel)
73                 pi.pain.line(x2, y2, x1, y1, origcol, pi.pain.line_solid, t);
74         else if (kind_ == xcancel) {
75                 pi.pain.line(x2, y1, x1, y2, origcol, pi.pain.line_solid, t);
76                 pi.pain.line(x2, y2, x1, y1, origcol, pi.pain.line_solid, t);
77         }
78
79         drawMarkers(pi, x, y);
80 }
81
82
83 void InsetMathCancel::write(WriteStream & os) const
84 {
85         MathEnsurer ensurer(os);
86         switch (kind_) {
87         case cancel:
88                 os << "\\cancel{";
89                 break;
90         case bcancel:
91                 os << "\\bcancel{";
92                 break;
93         case xcancel:
94                 os << "\\xcancel{";
95                 break;
96         }
97         os << cell(0) << '}';
98 }
99
100
101 void InsetMathCancel::normalize(NormalStream & os) const
102 {
103         switch (kind_) {
104         case cancel:
105                 os << "[cancel ";
106                 break;
107         case bcancel:
108                 os << "[bcancel ";
109                 break;
110         case xcancel:
111                 os << "[xcancel ";
112                 break;
113         }
114         os << cell(0) << ']';
115 }
116
117
118 void InsetMathCancel::infoize(odocstream & os) const
119 {
120         switch (kind_) {
121         case cancel:
122                 os << "Cancel";
123                 break;
124         case bcancel:
125                 os << "Bcancel";
126                 break;
127         case xcancel:
128                 os << "Xcancel";
129                 break;
130         }
131 }
132
133
134 // unfortunately, we do not have many options here, so we have to treat
135 // them all the same way.
136 void InsetMathCancel::htmlize(HtmlStream & os) const
137 {
138         os << MTag("span", "style='text-decoration: line-through;'")
139            << cell(0)
140            << ETag("span");
141 }
142
143
144 void InsetMathCancel::mathmlize(MathStream & os) const
145 {
146         switch (kind_) {
147         case cancel:
148                 os << MTag("menclose", "notation='updiagonalstrike'")
149                    << cell(0)
150                    << ETag("menclose"); 
151                 break;
152         case bcancel:
153                 os << MTag("menclose", "notation='downdiagonalstrike'")
154                    << cell(0)
155                    << ETag("menclose"); 
156                 break;
157         case xcancel:
158                 os << MTag("menclose", "notation='updiagonalstrike'")
159                    << MTag("menclose", "notation='downdiagonalstrike'")
160                    << cell(0)
161                    << ETag("menclose")
162                    << ETag("menclose");
163                 break;
164         }
165 }
166
167
168 void InsetMathCancel::validate(LaTeXFeatures & features) const
169 {
170         InsetMathNest::validate(features);
171         if (features.runparams().isLaTeX())
172                 features.require("cancel");
173         InsetMathNest::validate(features);
174 }
175
176 } // namespace lyx