]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCancel.cpp
g-brief loads babel internally. So don't load it ourselves.
[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 }
43
44
45 void InsetMathCancel::draw(PainterInfo & pi, int x, int y) const
46 {
47         Changer dummy = pi.base.changeEnsureMath();
48         // We first draw the text and then an arrow
49         ColorCode const origcol = pi.base.font.color();
50         cell(0).draw(pi, x, y);
51         Dimension const dim = dimension(*pi.base.bv);
52         int const t = pi.base.solidLineThickness();
53
54         /*
55          * y1 \    /
56          *     \  /
57          *      \/
58          *      /\
59          *     /  \
60          * y2 /    \
61          *    x1  x2
62          */
63
64         int const x2 = x + dim.wid;
65         int const x1 = x;
66         int const y1 = y - dim.asc;
67         int const y2 = y + dim.des;
68
69         if (kind_ == cancel)
70                 pi.pain.line(x2, y1, x1, y2, origcol, pi.pain.line_solid, t);
71         else if (kind_ == bcancel)
72                 pi.pain.line(x2, y2, x1, y1, origcol, pi.pain.line_solid, t);
73         else if (kind_ == xcancel) {
74                 pi.pain.line(x2, y1, x1, y2, origcol, pi.pain.line_solid, t);
75                 pi.pain.line(x2, y2, x1, y1, origcol, pi.pain.line_solid, t);
76         }
77 }
78
79
80 void InsetMathCancel::write(TeXMathStream & os) const
81 {
82         MathEnsurer ensurer(os);
83         switch (kind_) {
84         case cancel:
85                 os << "\\cancel{";
86                 break;
87         case bcancel:
88                 os << "\\bcancel{";
89                 break;
90         case xcancel:
91                 os << "\\xcancel{";
92                 break;
93         }
94         os << cell(0) << '}';
95 }
96
97
98 void InsetMathCancel::normalize(NormalStream & os) const
99 {
100         switch (kind_) {
101         case cancel:
102                 os << "[cancel ";
103                 break;
104         case bcancel:
105                 os << "[bcancel ";
106                 break;
107         case xcancel:
108                 os << "[xcancel ";
109                 break;
110         }
111         os << cell(0) << ']';
112 }
113
114
115 void InsetMathCancel::infoize(odocstream & os) const
116 {
117         switch (kind_) {
118         case cancel:
119                 os << "Cancel";
120                 break;
121         case bcancel:
122                 os << "Bcancel";
123                 break;
124         case xcancel:
125                 os << "Xcancel";
126                 break;
127         }
128 }
129
130
131 // unfortunately, we do not have many options here, so we have to treat
132 // them all the same way.
133 void InsetMathCancel::htmlize(HtmlStream & os) const
134 {
135         os << MTag("span", "style='text-decoration: line-through;'")
136            << cell(0)
137            << ETag("span");
138 }
139
140
141 void InsetMathCancel::mathmlize(MathMLStream & ms) const
142 {
143         switch (kind_) {
144         case cancel:
145                 ms << MTag("menclose", "notation='updiagonalstrike'")
146                    << cell(0)
147                    << ETag("menclose");
148                 break;
149         case bcancel:
150                 ms << MTag("menclose", "notation='downdiagonalstrike'")
151                    << cell(0)
152                    << ETag("menclose");
153                 break;
154         case xcancel:
155                 ms << MTag("menclose", "notation='updiagonalstrike'")
156                    << MTag("menclose", "notation='downdiagonalstrike'")
157                    << cell(0)
158                    << ETag("menclose")
159                    << ETag("menclose");
160                 break;
161         }
162 }
163
164
165 void InsetMathCancel::validate(LaTeXFeatures & features) const
166 {
167         InsetMathNest::validate(features);
168         if (features.runparams().isLaTeX())
169                 features.require("cancel");
170         InsetMathNest::validate(features);
171 }
172
173 } // namespace lyx