2006-04-15 09:54:24 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathPhantom.cpp
|
2006-04-15 09:54:24 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Georg Baum
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathPhantom.h"
|
2006-04-15 09:54:24 +00:00
|
|
|
|
2012-01-08 12:34:12 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-11-06 21:45:24 +00:00
|
|
|
#include "MathStream.h"
|
2016-06-04 08:41:13 +00:00
|
|
|
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
2006-04-15 09:54:24 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2015-12-10 00:15:16 +00:00
|
|
|
#include <algorithm>
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathPhantom::InsetMathPhantom(Buffer * buf, Kind k)
|
|
|
|
: InsetMathNest(buf, 1), kind_(k)
|
2006-04-15 09:54:24 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathPhantom::clone() const
|
2006-04-15 09:54:24 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathPhantom(*this);
|
2006-04-15 09:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
|
2006-04-15 09:54:24 +00:00
|
|
|
{
|
|
|
|
cell(0).metrics(mi, dim);
|
|
|
|
metricsMarkers(dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
|
2006-04-15 09:54:24 +00:00
|
|
|
{
|
|
|
|
static int const arrow_size = 4;
|
|
|
|
|
|
|
|
// We first draw the text and then an arrow
|
2007-10-25 12:41:02 +00:00
|
|
|
ColorCode const origcol = pi.base.font.color();
|
2012-01-08 12:34:12 +00:00
|
|
|
if (visibleContents())
|
|
|
|
pi.base.font.setColor(Color_special);
|
2006-04-15 09:54:24 +00:00
|
|
|
cell(0).draw(pi, x + 1, y);
|
2012-01-08 12:34:12 +00:00
|
|
|
if (visibleContents())
|
|
|
|
pi.base.font.setColor(origcol);
|
2007-09-23 22:39:49 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2006-04-15 09:54:24 +00:00
|
|
|
|
|
|
|
if (kind_ == phantom || kind_ == vphantom) {
|
|
|
|
// y1---------
|
|
|
|
// / \.
|
|
|
|
// y2----- / | \.
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// y3----- \ | /
|
|
|
|
// \ /
|
|
|
|
// y4---------
|
|
|
|
// | | |
|
|
|
|
// / | \.
|
|
|
|
// x1 x2 x3
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
int const x2 = x + dim.wid / 2;
|
2006-04-15 09:54:24 +00:00
|
|
|
int const x1 = x2 - arrow_size;
|
|
|
|
int const x3 = x2 + arrow_size;
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
int const y1 = y - dim.asc;
|
2006-04-15 09:54:24 +00:00
|
|
|
int const y2 = y1 + arrow_size;
|
2007-09-23 22:39:49 +00:00
|
|
|
int const y4 = y + dim.des;
|
2006-04-15 09:54:24 +00:00
|
|
|
int const y3 = y4 - arrow_size;
|
|
|
|
|
|
|
|
// top arrow
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(x2, y1, x1, y2, Color_added_space);
|
|
|
|
pi.pain.line(x2, y1, x3, y2, Color_added_space);
|
2006-04-15 09:54:24 +00:00
|
|
|
|
|
|
|
// bottom arrow
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(x2, y4, x1, y3, Color_added_space);
|
|
|
|
pi.pain.line(x2, y4, x3, y3, Color_added_space);
|
2006-04-15 09:54:24 +00:00
|
|
|
|
|
|
|
// joining line
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(x2, y1, x2, y4, Color_added_space);
|
2006-04-15 09:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (kind_ == phantom || kind_ == hphantom) {
|
2012-01-08 12:34:12 +00:00
|
|
|
// y1---- / \.
|
2006-04-15 09:54:24 +00:00
|
|
|
// / \.
|
|
|
|
// y2--- <---------------->
|
|
|
|
// \ /
|
2012-01-08 12:34:12 +00:00
|
|
|
// y3---- \ /
|
|
|
|
// | | | |
|
|
|
|
// x1 x2 x3 x4
|
2006-04-15 09:54:24 +00:00
|
|
|
|
|
|
|
int const x1 = x;
|
|
|
|
int const x2 = x + arrow_size;
|
2007-09-23 22:39:49 +00:00
|
|
|
int const x4 = x + dim.wid;
|
2006-04-15 09:54:24 +00:00
|
|
|
int const x3 = x4 - arrow_size;
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
int const y2 = y + (dim.des - dim.asc) / 2;
|
2006-04-15 09:54:24 +00:00
|
|
|
int const y1 = y2 - arrow_size;
|
|
|
|
int const y3 = y2 + arrow_size;
|
|
|
|
|
|
|
|
// left arrow
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(x1, y2, x2, y3, Color_added_space);
|
|
|
|
pi.pain.line(x1, y2, x2, y1, Color_added_space);
|
2006-04-15 09:54:24 +00:00
|
|
|
|
|
|
|
// right arrow
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(x4, y2, x3, y3, Color_added_space);
|
|
|
|
pi.pain.line(x4, y2, x3, y1, Color_added_space);
|
2006-04-15 09:54:24 +00:00
|
|
|
|
|
|
|
// joining line
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(x1, y2, x4, y2, Color_added_space);
|
2006-04-15 09:54:24 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 12:34:12 +00:00
|
|
|
else if (kind_ == mathclap) {
|
|
|
|
// y1---- \ /
|
|
|
|
// \ /
|
|
|
|
// y2--- -------->-<--------
|
|
|
|
// / \.
|
|
|
|
// y3---- / \.
|
|
|
|
// | | | | |
|
|
|
|
// x1 x2 x3 x4 x5
|
|
|
|
|
|
|
|
int const x1 = x;
|
|
|
|
int const x5 = x + dim.wid;
|
|
|
|
int const x3 = x + dim.wid / 2;
|
|
|
|
int const x2 = std::max(x1, x3 - arrow_size);
|
|
|
|
int const x4 = std::min(x5, x3 + arrow_size);
|
|
|
|
|
|
|
|
int const y2 = y + (dim.des - dim.asc) / 2;
|
|
|
|
int const y1 = y2 - arrow_size;
|
|
|
|
int const y3 = y2 + arrow_size;
|
|
|
|
|
|
|
|
// left arrow
|
|
|
|
pi.pain.line(x2, y3, x3, y2, Color_added_space);
|
|
|
|
pi.pain.line(x2, y1, x3, y2, Color_added_space);
|
|
|
|
|
|
|
|
// right arrow
|
|
|
|
pi.pain.line(x4, y3, x3, y2, Color_added_space);
|
|
|
|
pi.pain.line(x4, y1, x3, y2, Color_added_space);
|
|
|
|
|
|
|
|
// joining line
|
|
|
|
pi.pain.line(x1, y2, x5, y2, Color_added_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (kind_ == mathllap) {
|
|
|
|
// y1---- \.
|
|
|
|
// \.
|
|
|
|
// y2--- ------------------>
|
|
|
|
// /
|
|
|
|
// y3---- /
|
|
|
|
// | | |
|
|
|
|
// x1 x2 x3
|
|
|
|
|
|
|
|
int const x1 = x;
|
|
|
|
int const x3 = x + dim.wid;
|
|
|
|
int const x2 = std::max(x1, x3 - arrow_size);
|
|
|
|
|
|
|
|
int const y2 = y + (dim.des - dim.asc) / 2;
|
|
|
|
int const y1 = y2 - arrow_size;
|
|
|
|
int const y3 = y2 + arrow_size;
|
|
|
|
|
|
|
|
// right arrow
|
|
|
|
pi.pain.line(x3, y2, x2, y3, Color_added_space);
|
|
|
|
pi.pain.line(x3, y2, x2, y1, Color_added_space);
|
|
|
|
|
|
|
|
// joining line
|
|
|
|
pi.pain.line(x1, y2, x3, y2, Color_added_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (kind_ == mathrlap) {
|
|
|
|
// y1---- /
|
|
|
|
// /
|
|
|
|
// y2--- <------------------
|
|
|
|
// \.
|
|
|
|
// y3---- \.
|
|
|
|
// | | |
|
|
|
|
// x1 x2 x3
|
|
|
|
|
|
|
|
int const x1 = x;
|
|
|
|
int const x3 = x + dim.wid;
|
|
|
|
int const x2 = std::min(x3, x + arrow_size);
|
|
|
|
|
|
|
|
int const y2 = y + (dim.des - dim.asc) / 2;
|
|
|
|
int const y1 = y2 - arrow_size;
|
|
|
|
int const y3 = y2 + arrow_size;
|
|
|
|
|
|
|
|
// left arrow
|
|
|
|
pi.pain.line(x1, y2, x2, y3, Color_added_space);
|
|
|
|
pi.pain.line(x1, y2, x2, y1, Color_added_space);
|
|
|
|
|
|
|
|
// joining line
|
|
|
|
pi.pain.line(x1, y2, x3, y2, Color_added_space);
|
|
|
|
}
|
|
|
|
|
2014-05-27 20:10:02 +00:00
|
|
|
else if (kind_ == smash || kind_ == smasht || kind_ == smashb) {
|
2012-01-08 12:34:12 +00:00
|
|
|
// y1---------
|
|
|
|
// |
|
|
|
|
// y2----- \ | /
|
|
|
|
// \ /
|
|
|
|
// y3-------- |
|
|
|
|
// / \.
|
|
|
|
// y4----- / | \.
|
|
|
|
// |
|
|
|
|
// y5---------
|
|
|
|
// | | |
|
|
|
|
// / | \.
|
|
|
|
// x1 x2 x3
|
|
|
|
|
|
|
|
int const x2 = x + dim.wid / 2;
|
|
|
|
int const x1 = x2 - arrow_size;
|
|
|
|
int const x3 = x2 + arrow_size;
|
|
|
|
|
|
|
|
int const y1 = y - dim.asc;
|
|
|
|
int const y5 = y + dim.des;
|
|
|
|
int const y3 = y;
|
|
|
|
int const y2 = std::max(y1, y3 - arrow_size);
|
|
|
|
int const y4 = std::min(y5, y3 + arrow_size);
|
|
|
|
|
|
|
|
// top arrow
|
2014-05-27 20:10:02 +00:00
|
|
|
if (kind_ != smashb) {
|
|
|
|
pi.pain.line(x1, y2, x2, y3, Color_added_space);
|
|
|
|
pi.pain.line(x3, y2, x2, y3, Color_added_space);
|
|
|
|
}
|
2012-01-08 12:34:12 +00:00
|
|
|
|
|
|
|
// bottom arrow
|
2014-05-27 20:10:02 +00:00
|
|
|
if (kind_ != smasht) {
|
|
|
|
pi.pain.line(x1, y4, x2, y3, Color_added_space);
|
|
|
|
pi.pain.line(x3, y4, x2, y3, Color_added_space);
|
|
|
|
}
|
2012-01-08 12:34:12 +00:00
|
|
|
|
|
|
|
// joining line
|
2014-05-27 20:10:02 +00:00
|
|
|
if (kind_ == smasht)
|
|
|
|
pi.pain.line(x2, y1, x2, y3, Color_added_space);
|
|
|
|
else if (kind_ == smashb)
|
|
|
|
pi.pain.line(x2, y3, x2, y5, Color_added_space);
|
|
|
|
else
|
|
|
|
pi.pain.line(x2, y1, x2, y5, Color_added_space);
|
2012-01-08 12:34:12 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 09:54:24 +00:00
|
|
|
drawMarkers(pi, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathPhantom::write(WriteStream & os) const
|
2006-04-15 09:54:24 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2014-02-22 15:30:55 +00:00
|
|
|
if (os.fragile())
|
|
|
|
os << "\\protect";
|
2006-04-15 09:54:24 +00:00
|
|
|
switch (kind_) {
|
|
|
|
case phantom:
|
|
|
|
os << "\\phantom{";
|
|
|
|
break;
|
|
|
|
case vphantom:
|
|
|
|
os << "\\vphantom{";
|
|
|
|
break;
|
|
|
|
case hphantom:
|
|
|
|
os << "\\hphantom{";
|
|
|
|
break;
|
2012-01-08 12:34:12 +00:00
|
|
|
case smash:
|
|
|
|
os << "\\smash{";
|
|
|
|
break;
|
2014-05-27 20:10:02 +00:00
|
|
|
case smasht:
|
|
|
|
os << "\\smash[t]{";
|
|
|
|
break;
|
|
|
|
case smashb:
|
|
|
|
os << "\\smash[b]{";
|
|
|
|
break;
|
2012-01-08 12:34:12 +00:00
|
|
|
case mathclap:
|
|
|
|
os << "\\mathclap{";
|
|
|
|
break;
|
|
|
|
case mathllap:
|
|
|
|
os << "\\mathllap{";
|
|
|
|
break;
|
|
|
|
case mathrlap:
|
|
|
|
os << "\\mathrlap{";
|
|
|
|
break;
|
2006-04-15 09:54:24 +00:00
|
|
|
}
|
|
|
|
os << cell(0) << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathPhantom::normalize(NormalStream & os) const
|
2006-04-15 09:54:24 +00:00
|
|
|
{
|
|
|
|
switch (kind_) {
|
|
|
|
case phantom:
|
|
|
|
os << "[phantom ";
|
|
|
|
break;
|
|
|
|
case vphantom:
|
|
|
|
os << "[vphantom ";
|
|
|
|
break;
|
|
|
|
case hphantom:
|
|
|
|
os << "[hphantom ";
|
|
|
|
break;
|
2012-01-08 12:34:12 +00:00
|
|
|
case smash:
|
|
|
|
os << "[smash ";
|
|
|
|
break;
|
2014-05-27 20:10:02 +00:00
|
|
|
case smasht:
|
|
|
|
os << "[smasht ";
|
|
|
|
break;
|
|
|
|
case smashb:
|
|
|
|
os << "[smashb ";
|
|
|
|
break;
|
2012-01-08 12:34:12 +00:00
|
|
|
case mathclap:
|
|
|
|
os << "[mathclap ";
|
|
|
|
break;
|
|
|
|
case mathllap:
|
|
|
|
os << "[mathllap ";
|
|
|
|
break;
|
|
|
|
case mathrlap:
|
|
|
|
os << "[mathrlap ";
|
|
|
|
break;
|
2006-04-15 09:54:24 +00:00
|
|
|
}
|
|
|
|
os << cell(0) << ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathPhantom::infoize(odocstream & os) const
|
2006-04-15 09:54:24 +00:00
|
|
|
{
|
|
|
|
switch (kind_) {
|
|
|
|
case phantom:
|
|
|
|
os << "Phantom";
|
|
|
|
break;
|
|
|
|
case vphantom:
|
|
|
|
os << "Vphantom";
|
|
|
|
break;
|
|
|
|
case hphantom:
|
|
|
|
os << "Hphantom";
|
|
|
|
break;
|
2012-01-08 12:34:12 +00:00
|
|
|
case smash:
|
|
|
|
os << "Smash";
|
|
|
|
break;
|
2014-05-27 20:10:02 +00:00
|
|
|
case smasht:
|
|
|
|
os << "Smashtop";
|
|
|
|
break;
|
|
|
|
case smashb:
|
|
|
|
os << "Smashbottom";
|
|
|
|
break;
|
2012-01-08 12:34:12 +00:00
|
|
|
case mathllap:
|
|
|
|
os << "Mathllap";
|
|
|
|
break;
|
|
|
|
case mathclap:
|
|
|
|
os << "Mathclap";
|
|
|
|
break;
|
|
|
|
case mathrlap:
|
|
|
|
os << "Mathrlap";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathPhantom::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
InsetMathNest::validate(features);
|
|
|
|
switch (kind_) {
|
|
|
|
case phantom:
|
|
|
|
case vphantom:
|
|
|
|
case hphantom:
|
|
|
|
case smash:
|
|
|
|
break;
|
2014-05-27 20:10:02 +00:00
|
|
|
case smasht:
|
|
|
|
case smashb:
|
|
|
|
features.require("amsmath");
|
|
|
|
break;
|
2012-01-08 12:34:12 +00:00
|
|
|
case mathclap:
|
|
|
|
case mathllap:
|
|
|
|
case mathrlap:
|
|
|
|
features.require("mathtools");
|
|
|
|
break;
|
2006-04-15 09:54:24 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2012-01-08 12:34:12 +00:00
|
|
|
bool InsetMathPhantom::visibleContents() const
|
|
|
|
{
|
2014-04-04 19:53:27 +00:00
|
|
|
return kind_ == phantom || kind_ == vphantom || kind_ == hphantom;
|
2012-01-08 12:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|