2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathDecoration.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.
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
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.
|
|
|
|
*/
|
2001-12-05 08:04:20 +00:00
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
#include <config.h>
|
2001-02-26 12:53:35 +00:00
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathDecoration.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathParser.h"
|
2006-12-17 15:05:18 +00:00
|
|
|
#include "MathSupport.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathStream.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "MetricsInfo.h"
|
2004-04-08 15:20:05 +00:00
|
|
|
|
2005-01-08 20:28:29 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2004-08-14 14:03:42 +00:00
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathDecoration::InsetMathDecoration(Buffer * buf, latexkeys const * key)
|
|
|
|
: InsetMathNest(buf, 1), key_(key)
|
2004-08-14 14:03:42 +00:00
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
// lyxerr << " creating deco " << key->name << endl;
|
2004-08-14 14:03:42 +00:00
|
|
|
}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathDecoration::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathDecoration(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathDecoration::upper() const
|
2001-08-15 06:53:25 +00:00
|
|
|
{
|
2002-07-17 10:25:33 +00:00
|
|
|
return key_->name.substr(0, 5) != "under";
|
2001-08-15 06:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathDecoration::isScriptable() const
|
2001-09-11 10:58:17 +00:00
|
|
|
{
|
2001-09-12 13:23:39 +00:00
|
|
|
return
|
2002-07-17 10:25:33 +00:00
|
|
|
key_->name == "overbrace" ||
|
|
|
|
key_->name == "underbrace" ||
|
|
|
|
key_->name == "overleftarrow" ||
|
|
|
|
key_->name == "overrightarrow" ||
|
|
|
|
key_->name == "overleftrightarrow" ||
|
|
|
|
key_->name == "underleftarrow" ||
|
|
|
|
key_->name == "underrightarrow" ||
|
|
|
|
key_->name == "underleftrightarrow";
|
2001-09-11 10:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathDecoration::protect() const
|
2001-08-15 06:53:25 +00:00
|
|
|
{
|
|
|
|
return
|
2002-07-17 10:25:33 +00:00
|
|
|
key_->name == "overbrace" ||
|
|
|
|
key_->name == "underbrace" ||
|
|
|
|
key_->name == "overleftarrow" ||
|
|
|
|
key_->name == "overrightarrow" ||
|
|
|
|
key_->name == "overleftrightarrow" ||
|
|
|
|
key_->name == "underleftarrow" ||
|
|
|
|
key_->name == "underrightarrow" ||
|
|
|
|
key_->name == "underleftrightarrow";
|
2001-08-15 06:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathDecoration::wide() const
|
2001-09-12 15:56:09 +00:00
|
|
|
{
|
|
|
|
return
|
2002-07-17 10:25:33 +00:00
|
|
|
key_->name == "overline" ||
|
|
|
|
key_->name == "underline" ||
|
|
|
|
key_->name == "overbrace" ||
|
|
|
|
key_->name == "underbrace" ||
|
|
|
|
key_->name == "overleftarrow" ||
|
|
|
|
key_->name == "overrightarrow" ||
|
|
|
|
key_->name == "overleftrightarrow" ||
|
|
|
|
key_->name == "widehat" ||
|
|
|
|
key_->name == "widetilde" ||
|
|
|
|
key_->name == "underleftarrow" ||
|
|
|
|
key_->name == "underrightarrow" ||
|
|
|
|
key_->name == "underleftrightarrow";
|
2001-09-12 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
cell(0).metrics(mi, dim);
|
2003-05-28 13:22:36 +00:00
|
|
|
|
2002-07-11 11:27:24 +00:00
|
|
|
dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
|
|
|
|
dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
if (upper()) {
|
2004-01-30 11:41:12 +00:00
|
|
|
dy_ = -dim.asc - dh_;
|
|
|
|
dim.asc += dh_ + 1;
|
2001-02-13 13:28:32 +00:00
|
|
|
} else {
|
2004-01-30 11:41:12 +00:00
|
|
|
dy_ = dim.des + 1;
|
|
|
|
dim.des += dh_ + 2;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
metricsMarkers(dim);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
2001-09-03 15:22:55 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).draw(pi, x + 1, y);
|
2007-09-24 13:52:04 +00:00
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
2002-03-21 17:42:56 +00:00
|
|
|
if (wide())
|
2007-09-24 13:52:04 +00:00
|
|
|
mathed_draw_deco(pi, x + 1, y + dy_, dim0.wid, dh_, key_->name);
|
2002-03-19 16:55:58 +00:00
|
|
|
else
|
2007-09-24 13:52:04 +00:00
|
|
|
mathed_draw_deco(pi, x + 1 + (dim0.wid - dw_) / 2,
|
2003-05-28 13:22:36 +00:00
|
|
|
y + dy_, dw_, dh_, key_->name);
|
2002-06-24 15:37:14 +00:00
|
|
|
drawMarkers(pi, x, y);
|
2005-04-04 22:11:53 +00:00
|
|
|
setPosCache(pi, x, y);
|
2001-07-05 14:48:45 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathDecoration::write(WriteStream & os) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2001-12-03 16:24:50 +00:00
|
|
|
if (os.fragile() && protect())
|
2001-02-13 13:28:32 +00:00
|
|
|
os << "\\protect";
|
2002-07-17 10:25:33 +00:00
|
|
|
os << '\\' << key_->name << '{' << cell(0) << '}';
|
2001-07-13 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathDecoration::normalize(NormalStream & os) const
|
2001-07-13 07:55:55 +00:00
|
|
|
{
|
2002-07-17 10:25:33 +00:00
|
|
|
os << "[deco " << key_->name << ' ' << cell(0) << ']';
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathDecoration::infoize(odocstream & os) const
|
2002-06-24 15:37:14 +00:00
|
|
|
{
|
2002-07-17 10:25:33 +00:00
|
|
|
os << "Deco: " << key_->name;
|
2002-06-24 15:37:14 +00:00
|
|
|
}
|
2005-01-08 20:28:29 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathDecoration::validate(LaTeXFeatures & features) const
|
2005-01-08 20:28:29 +00:00
|
|
|
{
|
2009-06-18 20:04:27 +00:00
|
|
|
if (!key_->requires.empty())
|
|
|
|
features.require(to_utf8(key_->requires));
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathNest::validate(features);
|
2005-01-08 20:28:29 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|