2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_decorationinset.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_parser.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
#include "math_streamstr.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
2001-09-03 15:22:55 +00:00
|
|
|
MathDecorationInset::MathDecorationInset(string const & name)
|
|
|
|
: MathNestInset(1), name_(name)
|
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathDecorationInset::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-02-20 10:49:48 +00:00
|
|
|
return new MathDecorationInset(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
bool MathDecorationInset::upper() const
|
|
|
|
{
|
2002-01-11 10:26:13 +00:00
|
|
|
return
|
|
|
|
name_ != "underbar" &&
|
|
|
|
name_ != "underline" &&
|
2002-02-08 08:08:11 +00:00
|
|
|
name_ != "underbrace" &&
|
|
|
|
name_ != "underleftarrow" &&
|
|
|
|
name_ != "underrightarrow";
|
2001-08-15 06:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
bool MathDecorationInset::isScriptable() const
|
|
|
|
{
|
2001-09-12 13:23:39 +00:00
|
|
|
return
|
|
|
|
name_ == "overbrace" ||
|
|
|
|
name_ == "underbrace" ||
|
|
|
|
name_ == "overleftarrow" ||
|
2002-02-08 08:08:11 +00:00
|
|
|
name_ == "overrightarrow" ||
|
|
|
|
name_ == "underleftarrow" ||
|
|
|
|
name_ == "underrightarrow";
|
2001-09-11 10:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
bool MathDecorationInset::protect() const
|
|
|
|
{
|
|
|
|
return
|
2001-09-03 15:22:55 +00:00
|
|
|
name_ == "overbrace" ||
|
|
|
|
name_ == "underbrace" ||
|
|
|
|
name_ == "overleftarrow" ||
|
2002-02-08 08:08:11 +00:00
|
|
|
name_ == "overrightarrow" ||
|
|
|
|
name_ == "underleftarrow" ||
|
|
|
|
name_ == "underrightarrow";
|
2001-08-15 06:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-09-12 15:56:09 +00:00
|
|
|
bool MathDecorationInset::wide() const
|
|
|
|
{
|
|
|
|
return
|
2001-10-13 14:39:18 +00:00
|
|
|
name_ == "overline" ||
|
|
|
|
name_ == "underline" ||
|
2001-09-12 15:56:09 +00:00
|
|
|
name_ == "overbrace" ||
|
|
|
|
name_ == "underbrace" ||
|
|
|
|
name_ == "overleftarrow" ||
|
|
|
|
name_ == "overrightarrow" ||
|
|
|
|
name_ == "widehat" ||
|
2002-02-08 08:08:11 +00:00
|
|
|
name_ == "widetilde" ||
|
|
|
|
name_ == "underleftarrow" ||
|
|
|
|
name_ == "underrightarrow";
|
2001-09-12 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
void MathDecorationInset::metrics(MathMetricsInfo const & st) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
xcell(0).metrics(st);
|
2001-07-10 17:21:26 +00:00
|
|
|
size_ = st;
|
2001-06-25 00:06:33 +00:00
|
|
|
width_ = xcell(0).width();
|
|
|
|
ascent_ = xcell(0).ascent();
|
|
|
|
descent_ = xcell(0).descent();
|
|
|
|
|
2002-02-01 15:53:34 +00:00
|
|
|
dh_ = 6; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
if (upper()) {
|
2001-07-10 17:21:26 +00:00
|
|
|
dy_ = -ascent_ - dh_;
|
2001-07-06 12:09:32 +00:00
|
|
|
ascent_ += dh_ + 1;
|
2001-02-13 13:28:32 +00:00
|
|
|
} else {
|
2001-07-06 12:09:32 +00:00
|
|
|
dy_ = descent_ + 1;
|
|
|
|
descent_ += dh_ + 2;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-03 15:22:55 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathDecorationInset::draw(Painter & pain, int x, int y) const
|
2001-07-05 14:48:45 +00:00
|
|
|
{
|
|
|
|
xcell(0).draw(pain, x, y);
|
2001-09-12 15:56:09 +00:00
|
|
|
if (wide())
|
|
|
|
mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
|
|
|
|
else {
|
2002-02-01 15:53:34 +00:00
|
|
|
int w = mathed_char_width(LM_TC_VAR, size_, 'x');
|
2001-09-12 15:56:09 +00:00
|
|
|
mathed_draw_deco(pain, x + (width_ - w) / 2, y + dy_, w, dh_, name_);
|
|
|
|
}
|
2001-07-05 14:48:45 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathDecorationInset::write(WriteStream & os) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
if (os.fragile() && protect())
|
2001-02-13 13:28:32 +00:00
|
|
|
os << "\\protect";
|
2001-12-05 08:04:20 +00:00
|
|
|
os << '\\' << name_ << '{' << cell(0) << '}';
|
2001-07-13 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathDecorationInset::normalize(NormalStream & os) const
|
2001-07-13 07:55:55 +00:00
|
|
|
{
|
2001-12-05 08:04:20 +00:00
|
|
|
os << "[deco " << name_ << ' ' << cell(0) << ']';
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|