2012-01-23 01:49:49 +00:00
|
|
|
/**
|
|
|
|
* \file InsetMathCancel.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2012-02-06 22:38:46 +00:00
|
|
|
* \author Uwe Stöhr
|
2012-01-23 01:49:49 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "InsetMathCancel.h"
|
|
|
|
|
|
|
|
#include "MathStream.h"
|
|
|
|
|
2016-06-04 08:41:13 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
2012-01-23 01:49:49 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
|
InsetMathCancel::InsetMathCancel(Buffer * buf, Kind k)
|
|
|
|
: InsetMathNest(buf, 1), kind_(k)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
Inset * InsetMathCancel::clone() const
|
|
|
|
{
|
|
|
|
return new InsetMathCancel(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathCancel::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
{
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer dummy = mi.base.changeEnsureMath();
|
2012-01-23 01:49:49 +00:00
|
|
|
cell(0).metrics(mi, dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathCancel::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer dummy = pi.base.changeEnsureMath();
|
2012-01-23 01:49:49 +00:00
|
|
|
// We first draw the text and then an arrow
|
|
|
|
ColorCode const origcol = pi.base.font.color();
|
2017-01-06 08:52:10 +00:00
|
|
|
cell(0).draw(pi, x, y);
|
2012-01-23 01:49:49 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2016-12-19 23:15:59 +00:00
|
|
|
int const t = pi.base.solidLineThickness();
|
2012-01-23 01:49:49 +00:00
|
|
|
|
2012-02-02 00:25:13 +00:00
|
|
|
/*
|
|
|
|
* y1 \ /
|
|
|
|
* \ /
|
|
|
|
* \/
|
|
|
|
* /\
|
|
|
|
* / \
|
|
|
|
* y2 / \
|
|
|
|
* x1 x2
|
|
|
|
*/
|
2012-01-23 01:49:49 +00:00
|
|
|
|
|
|
|
int const x2 = x + dim.wid;
|
|
|
|
int const x1 = x;
|
|
|
|
int const y1 = y - dim.asc;
|
|
|
|
int const y2 = y + dim.des;
|
|
|
|
|
|
|
|
if (kind_ == cancel)
|
2016-12-19 23:15:59 +00:00
|
|
|
pi.pain.line(x2, y1, x1, y2, origcol, pi.pain.line_solid, t);
|
2012-01-23 01:49:49 +00:00
|
|
|
else if (kind_ == bcancel)
|
2016-12-19 23:15:59 +00:00
|
|
|
pi.pain.line(x2, y2, x1, y1, origcol, pi.pain.line_solid, t);
|
2012-01-23 01:49:49 +00:00
|
|
|
else if (kind_ == xcancel) {
|
2016-12-19 23:15:59 +00:00
|
|
|
pi.pain.line(x2, y1, x1, y2, origcol, pi.pain.line_solid, t);
|
|
|
|
pi.pain.line(x2, y2, x1, y1, origcol, pi.pain.line_solid, t);
|
2012-01-23 01:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathCancel::write(WriteStream & os) const
|
|
|
|
{
|
|
|
|
MathEnsurer ensurer(os);
|
|
|
|
switch (kind_) {
|
|
|
|
case cancel:
|
|
|
|
os << "\\cancel{";
|
|
|
|
break;
|
|
|
|
case bcancel:
|
|
|
|
os << "\\bcancel{";
|
|
|
|
break;
|
|
|
|
case xcancel:
|
|
|
|
os << "\\xcancel{";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
os << cell(0) << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathCancel::normalize(NormalStream & os) const
|
|
|
|
{
|
|
|
|
switch (kind_) {
|
|
|
|
case cancel:
|
|
|
|
os << "[cancel ";
|
|
|
|
break;
|
|
|
|
case bcancel:
|
|
|
|
os << "[bcancel ";
|
|
|
|
break;
|
|
|
|
case xcancel:
|
|
|
|
os << "[xcancel ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
os << cell(0) << ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathCancel::infoize(odocstream & os) const
|
|
|
|
{
|
|
|
|
switch (kind_) {
|
|
|
|
case cancel:
|
|
|
|
os << "Cancel";
|
|
|
|
break;
|
|
|
|
case bcancel:
|
|
|
|
os << "Bcancel";
|
|
|
|
break;
|
|
|
|
case xcancel:
|
|
|
|
os << "Xcancel";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 17:35:29 +00:00
|
|
|
|
2012-02-06 22:38:41 +00:00
|
|
|
// unfortunately, we do not have many options here, so we have to treat
|
|
|
|
// them all the same way.
|
|
|
|
void InsetMathCancel::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
os << MTag("span", "style='text-decoration: line-through;'")
|
|
|
|
<< cell(0)
|
|
|
|
<< ETag("span");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-06 17:35:29 +00:00
|
|
|
void InsetMathCancel::mathmlize(MathStream & os) const
|
|
|
|
{
|
|
|
|
switch (kind_) {
|
|
|
|
case cancel:
|
2012-02-06 22:38:41 +00:00
|
|
|
os << MTag("menclose", "notation='updiagonalstrike'")
|
|
|
|
<< cell(0)
|
2017-07-03 17:53:14 +00:00
|
|
|
<< ETag("menclose");
|
2012-02-06 17:35:29 +00:00
|
|
|
break;
|
|
|
|
case bcancel:
|
2012-02-06 22:38:41 +00:00
|
|
|
os << MTag("menclose", "notation='downdiagonalstrike'")
|
|
|
|
<< cell(0)
|
2017-07-03 17:53:14 +00:00
|
|
|
<< ETag("menclose");
|
2012-02-06 17:35:29 +00:00
|
|
|
break;
|
|
|
|
case xcancel:
|
|
|
|
os << MTag("menclose", "notation='updiagonalstrike'")
|
|
|
|
<< MTag("menclose", "notation='downdiagonalstrike'")
|
|
|
|
<< cell(0)
|
|
|
|
<< ETag("menclose")
|
2012-02-06 22:38:41 +00:00
|
|
|
<< ETag("menclose");
|
2012-02-06 17:35:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-23 01:49:49 +00:00
|
|
|
void InsetMathCancel::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
InsetMathNest::validate(features);
|
|
|
|
if (features.runparams().isLaTeX())
|
|
|
|
features.require("cancel");
|
|
|
|
InsetMathNest::validate(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace lyx
|