2 * \file InsetMathCancelto.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathCancelto.h"
16 #include "MathStream.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
22 #include "frontends/Painter.h"
31 InsetMathCancelto::InsetMathCancelto(Buffer * buf)
32 : InsetMathNest(buf, 2)
36 Inset * InsetMathCancelto::clone() const
38 return new InsetMathCancelto(*this);
42 void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const
44 Changer dummy = mi.base.changeEnsureMath();
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;
54 void InsetMathCancelto::draw(PainterInfo & pi, int x, int y) const
56 Changer dummy = pi.base.changeEnsureMath();
57 ColorCode const origcol = pi.base.font.color();
59 // We first draw the text and then an arrow
60 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
61 cell(0).draw(pi, x, y);
62 cell(1).draw(pi, x + dim0.wid + 1 + 8, y - dim0.asc - 8);
64 //Dimension const dim = dimension(*pi.base.bv);
76 int const x2 = x + dim0.wid;
77 int const x3 = x2 + 8;
79 int const y1 = y + dim0.des;
80 int const y2 = y - dim0.asc;
81 int const y3 = y2 - 8;
84 pi.pain.line(x3, y3, x1, y1, origcol);
86 pi.pain.line(x3, y3, x2 + 2, y3, origcol);
87 pi.pain.line(x3, y3, x3 - 2, y2 - 2, origcol);
91 void InsetMathCancelto::write(TeXMathStream & os) const
93 MathEnsurer ensurer(os);
94 os << "\\cancelto{" << cell(1) << "}{" << cell(0) << '}';
98 void InsetMathCancelto::normalize(NormalStream & os) const
100 os << "[cancelto " << cell(1) << ' ' << cell(0) << ']';
103 bool InsetMathCancelto::idxUpDown(Cursor & cur, bool up) const
105 idx_type const target = up ? 1 : 0;
106 if (cur.idx() == target)
109 cur.pos() = up ? cur.lastpos() : 0;
113 void InsetMathCancelto::infoize(odocstream & os) const
118 void InsetMathCancelto::validate(LaTeXFeatures & features) const
120 InsetMathNest::validate(features);
121 if (features.runparams().isLaTeX())
122 features.require("cancel");
123 InsetMathNest::validate(features);