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>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathXArrow.h"
|
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"
|
|
|
|
|
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
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
ScriptChanger dummy(mi.base);
|
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();
|
2004-04-08 15:59:34 +00:00
|
|
|
metricsMarkers(dim);
|
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
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
ScriptChanger dummy(pi.base);
|
2003-02-05 11:44:14 +00:00
|
|
|
cell(0).draw(pi, x + 5, y - 10);
|
2007-09-24 13:52:04 +00:00
|
|
|
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
|
|
|
|
cell(1).draw(pi, x + 5, y + dim1.height());
|
2007-09-23 22:39:49 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
|
2004-04-08 15:59:34 +00:00
|
|
|
drawMarkers(pi, x, y);
|
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
|
|
|
|
{
|
|
|
|
char const * const arrow = name_ == "xleftarrow"
|
|
|
|
? "←" : "→";
|
|
|
|
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
|
|
|
|
{
|
|
|
|
char const * const arrow = name_ == "xleftarrow"
|
|
|
|
? "←" : "→";
|
|
|
|
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
|
|
|
{
|
|
|
|
features.require("amsmath");
|
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
|