2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathXArrow.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2002-02-05 13:27:34 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2014-09-02 22:07:26 +00:00
|
|
|
#include "support/lassert.h"
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathXArrow.h"
|
2016-06-04 08:41:13 +00:00
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathStream.h"
|
|
|
|
#include "MathSupport.h"
|
2002-02-05 13:27:34 +00:00
|
|
|
|
2006-04-13 10:31:32 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2016-06-04 08:41:13 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
2006-04-13 10:31:32 +00:00
|
|
|
|
2015-12-10 00:15:16 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2002-02-05 13:27:34 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathXArrow::InsetMathXArrow(Buffer * buf, docstring const & name)
|
|
|
|
: InsetMathFracBase(buf), name_(name)
|
2002-02-05 13:27:34 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathXArrow::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathXArrow(*this);
|
2002-02-05 13:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-02-05 13:27:34 +00:00
|
|
|
{
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer dummy2 = mi.base.changeEnsureMath();
|
2016-05-23 21:30:23 +00:00
|
|
|
Changer dummy = mi.base.changeScript();
|
2007-09-24 13:52:04 +00:00
|
|
|
Dimension dim0;
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
Dimension dim1;
|
|
|
|
cell(1).metrics(mi, dim1);
|
2007-12-12 19:28:07 +00:00
|
|
|
dim.wid = max(dim0.width(), dim1.width()) + 10;
|
2007-09-24 13:52:04 +00:00
|
|
|
dim.asc = dim0.height() + 10;
|
|
|
|
dim.des = dim1.height();
|
2002-02-05 13:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer dummy2 = pi.base.changeEnsureMath();
|
2016-05-23 21:30:23 +00:00
|
|
|
Changer dummy = pi.base.changeScript();
|
2014-02-17 01:11:57 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
2014-02-17 00:23:16 +00:00
|
|
|
// center the cells with the decoration
|
2014-02-17 01:11:57 +00:00
|
|
|
cell(0).draw(pi, x + dim.width()/2 - dim0.width()/2, y - 10);
|
2007-09-24 13:52:04 +00:00
|
|
|
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
|
2014-02-17 01:11:57 +00:00
|
|
|
cell(1).draw(pi, x + dim.width()/2 - dim1.width()/2, y + dim1.height());
|
2017-01-06 08:52:10 +00:00
|
|
|
mathed_draw_deco(pi, x, y - 7, dim.wid, 5, name_);
|
2002-02-05 13:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathXArrow::write(WriteStream & os) const
|
2002-02-05 13:27:34 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2003-02-05 11:44:14 +00:00
|
|
|
os << '\\' << name_;
|
2012-10-21 19:14:16 +00:00
|
|
|
if (!cell(1).empty())
|
2003-02-05 11:44:14 +00:00
|
|
|
os << '[' << cell(1) << ']';
|
|
|
|
os << '{' << cell(0) << '}';
|
2002-02-05 13:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathXArrow::normalize(NormalStream & os) const
|
2002-02-05 13:27:34 +00:00
|
|
|
{
|
2003-02-05 11:44:14 +00:00
|
|
|
os << "[xarrow " << name_ << ' ' << cell(0) << ' ' << cell(1) << ']';
|
2002-02-05 13:27:34 +00:00
|
|
|
}
|
2006-04-13 10:31:32 +00:00
|
|
|
|
|
|
|
|
2009-12-31 22:02:19 +00:00
|
|
|
void InsetMathXArrow::mathmlize(MathStream & ms) const
|
|
|
|
{
|
2014-08-24 22:44:09 +00:00
|
|
|
char const * arrow;
|
|
|
|
|
|
|
|
if (name_ == "xleftarrow")
|
|
|
|
arrow = "←";
|
|
|
|
else if (name_ == "xrightarrow")
|
|
|
|
arrow = "→";
|
|
|
|
else if (name_ == "xhookleftarrow")
|
|
|
|
arrow = "↩";
|
|
|
|
else if (name_ == "xhookrightarrow")
|
|
|
|
arrow = "↪";
|
|
|
|
else if (name_ == "xLeftarrow")
|
|
|
|
arrow = "⇐";
|
|
|
|
else if (name_ == "xRightarrow")
|
|
|
|
arrow = "⇒";
|
|
|
|
else if (name_ == "xleftrightarrow")
|
|
|
|
arrow = "↔";
|
|
|
|
else if (name_ == "xLeftrightarrow")
|
|
|
|
arrow = "⇔";
|
|
|
|
else if (name_ == "xleftharpoondown")
|
|
|
|
arrow = "↽";
|
|
|
|
else if (name_ == "xleftharpoonup")
|
|
|
|
arrow = "↼";
|
|
|
|
else if (name_ == "xleftrightharpoons")
|
|
|
|
arrow = "⇋";
|
|
|
|
else if (name_ == "xrightharpoondown")
|
|
|
|
arrow = "⇁";
|
|
|
|
else if (name_ == "xrightharpoonup")
|
|
|
|
arrow = "⇀";
|
|
|
|
else if (name_ == "xrightleftharpoons")
|
|
|
|
arrow = "⇌";
|
|
|
|
else if (name_ == "xmapsto")
|
|
|
|
arrow = "↦";
|
2014-09-02 22:07:26 +00:00
|
|
|
else {
|
|
|
|
lyxerr << "mathmlize conversion for '" << name_ << "' not implemented" << endl;
|
|
|
|
LASSERT(false, arrow = "→");
|
|
|
|
}
|
2009-12-31 22:02:19 +00:00
|
|
|
ms << "<munderover accent='false' accentunder='false'>"
|
|
|
|
<< arrow << cell(1) << cell(0)
|
|
|
|
<< "</munderover>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-29 15:44:17 +00:00
|
|
|
void InsetMathXArrow::htmlize(HtmlStream & os) const
|
|
|
|
{
|
2014-08-24 22:44:09 +00:00
|
|
|
char const * arrow;
|
|
|
|
|
|
|
|
if (name_ == "xleftarrow")
|
|
|
|
arrow = "←";
|
|
|
|
else if (name_ == "xrightarrow")
|
|
|
|
arrow = "→";
|
|
|
|
else if (name_ == "xhookleftarrow")
|
|
|
|
arrow = "↩";
|
|
|
|
else if (name_ == "xhookrightarrow")
|
|
|
|
arrow = "↪";
|
|
|
|
else if (name_ == "xLeftarrow")
|
|
|
|
arrow = "⇐";
|
|
|
|
else if (name_ == "xRightarrow")
|
|
|
|
arrow = "⇒";
|
|
|
|
else if (name_ == "xleftrightarrow")
|
|
|
|
arrow = "↔";
|
|
|
|
else if (name_ == "xLeftrightarrow")
|
|
|
|
arrow = "⇔";
|
|
|
|
else if (name_ == "xleftharpoondown")
|
|
|
|
arrow = "↽";
|
|
|
|
else if (name_ == "xleftharpoonup")
|
|
|
|
arrow = "↼";
|
|
|
|
else if (name_ == "xleftrightharpoons")
|
|
|
|
arrow = "⇋";
|
|
|
|
else if (name_ == "xrightharpoondown")
|
|
|
|
arrow = "⇁";
|
|
|
|
else if (name_ == "xrightharpoonup")
|
|
|
|
arrow = "⇀";
|
|
|
|
else if (name_ == "xrightleftharpoons")
|
|
|
|
arrow = "⇌";
|
|
|
|
else if (name_ == "xmapsto")
|
|
|
|
arrow = "↦";
|
2014-09-02 22:07:26 +00:00
|
|
|
else {
|
|
|
|
lyxerr << "htmlize conversion for '" << name_ << "' not implemented" << endl;
|
|
|
|
LASSERT(false, arrow = "→");
|
|
|
|
}
|
2010-07-29 15:44:17 +00:00
|
|
|
os << MTag("span", "class='xarrow'")
|
|
|
|
<< MTag("span", "class='xatop'") << cell(0) << ETag("span")
|
|
|
|
<< MTag("span", "class='xabottom'") << arrow << ETag("span")
|
|
|
|
<< ETag("span");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathXArrow::validate(LaTeXFeatures & features) const
|
2006-04-13 10:31:32 +00:00
|
|
|
{
|
2014-08-24 22:44:09 +00:00
|
|
|
if (name_ == "xleftarrow" || name_ == "xrightarrow")
|
|
|
|
features.require("amsmath");
|
|
|
|
else
|
|
|
|
features.require("mathtools");
|
2010-07-29 15:44:17 +00:00
|
|
|
if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
|
|
|
// CSS adapted from eLyXer
|
2011-12-06 22:17:13 +00:00
|
|
|
features.addCSSSnippet(
|
2010-07-29 15:44:17 +00:00
|
|
|
"span.xarrow{display: inline-block; vertical-align: middle; text-align:center;}\n"
|
|
|
|
"span.xatop{display: block;}\n"
|
2011-12-06 22:17:13 +00:00
|
|
|
"span.xabottom{display: block;}");
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathNest::validate(features);
|
2006-04-13 10:31:32 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|