]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCancelto.cpp
Accept \kern and \mkern for math kerning
[lyx.git] / src / mathed / InsetMathCancelto.cpp
1 /**
2  * \file InsetMathCancelto.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 "InsetMathCancelto.h"
14
15 #include "MathData.h"
16 #include "MathStream.h"
17
18 #include "Cursor.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
21
22 #include "frontends/Painter.h"
23
24 #include <ostream>
25
26 using namespace std;
27
28 namespace lyx {
29
30
31 InsetMathCancelto::InsetMathCancelto(Buffer * buf)
32         : InsetMathNest(buf, 2)
33 {}
34
35
36 Inset * InsetMathCancelto::clone() const
37 {
38         return new InsetMathCancelto(*this);
39 }
40
41
42 void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const
43 {
44         Changer dummy = mi.base.changeEnsureMath();
45         InsetMathNest::metrics(mi);
46         Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
47         Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
48         dim.asc = max(dim0.ascent() + 2, dim0.ascent() + dim1.ascent()) + 2 + 8;
49         dim.des = max(dim0.descent() - 2, dim1.descent()) + 2;
50         dim.wid = dim0.width() + dim1.width() + 10;
51         metricsMarkers(mi, dim);
52 }
53
54
55 void InsetMathCancelto::draw(PainterInfo & pi, int x, int y) const
56 {
57         Changer dummy = pi.base.changeEnsureMath();
58         ColorCode const origcol = pi.base.font.color();
59
60         // We first draw the text and then an arrow
61         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
62         cell(0).draw(pi, x + 1, y);
63         cell(1).draw(pi, x + dim0.wid + 2 + 8, y - dim0.asc - 8);
64                 
65         //Dimension const dim = dimension(*pi.base.bv);
66         
67         // y3____ ___
68         //          /|
69         // y2_     / |
70         //        /
71         //       /
72         //      /
73         //     /
74         // y1 /    | |
75         //    x1  x2 x3
76
77         int const x2 = x + dim0.wid;
78         int const x3 = x2 + 8;
79         int const x1 = x;
80         int const y1 = y + dim0.des;
81         int const y2 = y - dim0.asc;
82         int const y3 = y2 - 8;
83
84         // the main line
85         pi.pain.line(x3, y3, x1, y1, origcol);
86         // the arrow bars
87         pi.pain.line(x3, y3, x2 + 2, y3, origcol);
88         pi.pain.line(x3, y3, x3 - 2, y2 - 2, origcol);
89
90         drawMarkers(pi, x, y);
91 }
92
93
94 void InsetMathCancelto::write(WriteStream & os) const
95 {
96         MathEnsurer ensurer(os);
97         os << "\\cancelto{" << cell(1) << "}{" << cell(0) << '}';
98 }
99
100
101 void InsetMathCancelto::normalize(NormalStream & os) const
102 {
103         os << "[cancelto " << cell(1) << ' ' << cell(0) << ']';
104 }
105
106 bool InsetMathCancelto::idxUpDown(Cursor & cur, bool up) const
107 {
108         Cursor::idx_type const target = up ? 1 : 0;
109         if (cur.idx() == target)
110                 return false;
111         cur.idx() = target;
112         cur.pos() = up ? cur.lastpos() : 0;
113         return true;
114 }
115
116 void InsetMathCancelto::infoize(odocstream & os) const
117 {
118         os << "Cancelto";
119 }
120
121 void InsetMathCancelto::validate(LaTeXFeatures & features) const
122 {
123         InsetMathNest::validate(features);
124         if (features.runparams().isLaTeX())
125                 features.require("cancel");
126         InsetMathNest::validate(features);
127 }
128
129
130 } // namespace lyx