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