2001-06-25 00:06:33 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_scriptinset.h"
|
|
|
|
#include "support/LOstream.h"
|
2001-08-09 09:19:18 +00:00
|
|
|
#include "support.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
MathScriptInset::MathScriptInset()
|
2001-08-03 17:10:22 +00:00
|
|
|
: MathNestInset(2), up_(false), down_(false), limits_(0), symbol_(0)
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
MathScriptInset::MathScriptInset(bool up, bool down, MathInset * symbol)
|
2001-08-03 17:10:22 +00:00
|
|
|
: MathNestInset(2), up_(up), down_(down), limits_(0), symbol_(symbol)
|
2001-07-26 06:46:50 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
MathScriptInset::MathScriptInset(MathScriptInset const & p)
|
2001-08-03 17:10:22 +00:00
|
|
|
: MathNestInset(p), up_(p.up_), down_(p.down_),
|
2001-07-26 06:46:50 +00:00
|
|
|
limits_(p.limits_), symbol_(p.symbol_ ? p.symbol_->clone() : 0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
MathScriptInset::~MathScriptInset()
|
|
|
|
{
|
|
|
|
delete symbol_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathScriptInset::clone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return new MathScriptInset(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
bool MathScriptInset::up() const
|
|
|
|
{
|
|
|
|
return up_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::down() const
|
|
|
|
{
|
|
|
|
return down_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::up(bool b)
|
|
|
|
{
|
|
|
|
up_ = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::down(bool b)
|
|
|
|
{
|
|
|
|
down_ = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::idxRight(int &, int &) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:46:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::idxLeft(int &, int &) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::idxUp(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
if (idx == 0 || !up())
|
|
|
|
return false;
|
|
|
|
idx = 0;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathScriptInset::idxDown(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
if (idx == 1 || !down())
|
|
|
|
return false;
|
|
|
|
idx = 1;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathScriptInset::idxFirst(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
idx = up() ? 0 : 1;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathScriptInset::idxLast(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
idx = down() ? 1 : 0;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::idxFirstUp(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
if (!up())
|
|
|
|
return false;
|
|
|
|
idx = 0;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::idxFirstDown(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
if (!down())
|
|
|
|
return false;
|
|
|
|
idx = 1;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::idxLastUp(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
if (!up())
|
|
|
|
return false;
|
|
|
|
idx = 0;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::idxLastDown(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
if (!down())
|
|
|
|
return false;
|
|
|
|
idx = 1;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathScriptInset::write(std::ostream & os, bool fragile) const
|
2001-07-26 06:46:50 +00:00
|
|
|
{
|
|
|
|
if (symbol_) {
|
2001-07-26 06:56:43 +00:00
|
|
|
symbol_->write(os, fragile);
|
2001-07-26 06:46:50 +00:00
|
|
|
if (limits())
|
|
|
|
os << (limits() == 1 ? "\\limits" : "\\nolimits");
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
if (up()) {
|
2001-07-26 06:46:50 +00:00
|
|
|
os << "^{";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(0).write(os, fragile);
|
2001-07-26 06:46:50 +00:00
|
|
|
os << "}";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
if (down()) {
|
2001-07-26 06:46:50 +00:00
|
|
|
os << "_{";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(1).write(os, fragile);
|
2001-07-26 06:46:50 +00:00
|
|
|
os << "}";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-07-26 06:46:50 +00:00
|
|
|
os << " ";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2001-07-09 16:59:57 +00:00
|
|
|
if (idx == 0)
|
2001-06-27 14:10:35 +00:00
|
|
|
up(false);
|
2001-07-09 16:59:57 +00:00
|
|
|
else
|
2001-06-27 14:10:35 +00:00
|
|
|
down(false);
|
2001-07-09 16:59:57 +00:00
|
|
|
popit = true;
|
|
|
|
deleteit = !(up() || down());
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
2001-07-26 06:46:50 +00:00
|
|
|
|
|
|
|
|
2001-08-20 13:45:02 +00:00
|
|
|
bool MathScriptInset::isActive() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
int MathScriptInset::limits() const
|
|
|
|
{
|
|
|
|
return limits_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::limits(int limits)
|
|
|
|
{
|
|
|
|
limits_ = limits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::hasLimits() const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
symbol_ && (limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathScriptInset::writeNormal(std::ostream & os) const
|
2001-07-26 06:46:50 +00:00
|
|
|
{
|
|
|
|
if (limits() && symbol_)
|
|
|
|
os << "[" << (limits() ? "limits" : "nolimits") << "]";
|
|
|
|
if (up()) {
|
|
|
|
os << "[superscript ";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(0).writeNormal(os);
|
2001-07-26 06:46:50 +00:00
|
|
|
os << "] ";
|
|
|
|
}
|
|
|
|
if (down()) {
|
|
|
|
os << "[subscript ";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(1).writeNormal(os);
|
2001-07-26 06:46:50 +00:00
|
|
|
os << "] ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathScriptInset::metrics(MathStyles st) const
|
2001-07-26 06:46:50 +00:00
|
|
|
{
|
|
|
|
size_ = st;
|
|
|
|
MathStyles tt = smallerStyleScript(st);
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
xcell(0).metrics(tt);
|
|
|
|
xcell(1).metrics(tt);
|
2001-07-26 06:46:50 +00:00
|
|
|
|
|
|
|
width_ = std::max(xcell(0).width(), xcell(1).width());
|
|
|
|
|
|
|
|
if (hasLimits()) {
|
2001-07-26 06:56:43 +00:00
|
|
|
symbol_->metrics(st);
|
2001-07-26 06:46:50 +00:00
|
|
|
int wid = symbol_->width();
|
|
|
|
ascent_ = symbol_->ascent();
|
|
|
|
descent_ = symbol_->descent();
|
|
|
|
width_ = std::max(width_, wid);
|
|
|
|
if (up()) {
|
|
|
|
ascent_ += xcell(0).height() + 2;
|
|
|
|
dy0_ = - (ascent_ - xcell(0).ascent());
|
|
|
|
}
|
|
|
|
if (down()) {
|
|
|
|
descent_ += xcell(1).height() + 2;
|
|
|
|
dy1_ = descent_ - xcell(1).descent();
|
|
|
|
}
|
|
|
|
dxx_ = (width_ - wid) / 2;
|
|
|
|
dx0_ = (width_ - xcell(0).width()) / 2;
|
|
|
|
dx1_ = (width_ - xcell(1).width()) / 2;
|
|
|
|
} else {
|
2001-08-09 09:19:18 +00:00
|
|
|
int asc = 0;
|
|
|
|
int des = 0;
|
2001-07-26 06:46:50 +00:00
|
|
|
int wid = 0;
|
|
|
|
mathed_char_height(LM_TC_VAR, st, 'I', asc, des);
|
|
|
|
if (symbol_) {
|
2001-07-26 06:56:43 +00:00
|
|
|
symbol_->metrics(st);
|
2001-07-26 06:46:50 +00:00
|
|
|
wid = symbol_->width();
|
|
|
|
asc = symbol_->ascent();
|
2001-08-08 16:25:30 +00:00
|
|
|
des = symbol_->descent();
|
2001-07-26 06:46:50 +00:00
|
|
|
}
|
|
|
|
ascent_ = up() ? xcell(0).height() + asc : 0;
|
|
|
|
descent_ = down() ? xcell(1).height() + des : 0;
|
|
|
|
width_ += wid;
|
|
|
|
dy0_ = - asc - xcell(0).descent();
|
|
|
|
dy1_ = des + xcell(1).ascent();
|
|
|
|
dx0_ = wid;
|
|
|
|
dx1_ = wid;
|
|
|
|
dxx_ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathScriptInset::draw(Painter & pain, int x, int y) const
|
2001-07-26 06:46:50 +00:00
|
|
|
{
|
|
|
|
xo(x);
|
|
|
|
yo(y);
|
|
|
|
|
|
|
|
if (symbol_)
|
|
|
|
symbol_->draw(pain, x + dxx_, y);
|
|
|
|
if (up())
|
|
|
|
xcell(0).draw(pain, x + dx0_, y + dy0_);
|
|
|
|
if (down())
|
|
|
|
xcell(1).draw(pain, x + dx1_, y + dy1_);
|
|
|
|
}
|
2001-08-20 13:45:02 +00:00
|
|
|
|