]> git.lyx.org Git - features.git/blob - src/mathed/InsetMathCancel.cpp
add support for the package cancel in math (fixes #6819); fileformat change only...
[features.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         // y1 \    /
51         //     \  /
52         //      \/
53         //      /\
54         //     /  \
55         // y2 /    \
56         //    x1  x2
57
58         int const x2 = x + dim.wid;
59         int const x1 = x;
60         int const y1 = y - dim.asc;
61         int const y2 = y + dim.des;
62
63         if (kind_ == cancel)
64                 pi.pain.line(x2, y1, x1, y2, origcol);
65         else if (kind_ == bcancel)
66                 pi.pain.line(x2, y2, x1, y1, origcol);
67         else if (kind_ == xcancel) {
68                 pi.pain.line(x2, y1, x1, y2, origcol);
69                 pi.pain.line(x2, y2, x1, y1, origcol);
70         }
71
72         drawMarkers(pi, x, y);
73 }
74
75
76 void InsetMathCancel::write(WriteStream & os) const
77 {
78         MathEnsurer ensurer(os);
79         switch (kind_) {
80         case cancel:
81                 os << "\\cancel{";
82                 break;
83         case bcancel:
84                 os << "\\bcancel{";
85                 break;
86         case xcancel:
87                 os << "\\xcancel{";
88                 break;
89         }
90         os << cell(0) << '}';
91 }
92
93
94 void InsetMathCancel::normalize(NormalStream & os) const
95 {
96         switch (kind_) {
97         case cancel:
98                 os << "[cancel ";
99                 break;
100         case bcancel:
101                 os << "[bcancel ";
102                 break;
103         case xcancel:
104                 os << "[xcancel ";
105                 break;
106         }
107         os << cell(0) << ']';
108 }
109
110
111 void InsetMathCancel::infoize(odocstream & os) const
112 {
113         switch (kind_) {
114         case cancel:
115                 os << "Cancel";
116                 break;
117         case bcancel:
118                 os << "Bcancel";
119                 break;
120         case xcancel:
121                 os << "Xcancel";
122                 break;
123         }
124 }
125
126 void InsetMathCancel::validate(LaTeXFeatures & features) const
127 {
128         InsetMathNest::validate(features);
129         if (features.runparams().isLaTeX())
130                 features.require("cancel");
131         InsetMathNest::validate(features);
132 }
133
134 } // namespace lyx