2001-06-25 00:06:33 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
#include "math_scriptinset.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "Painter.h"
|
2001-08-06 17:20:26 +00:00
|
|
|
#include "debug.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
extern MathScriptInset const * asScript(MathArray::const_iterator it);
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathXArray::MathXArray()
|
2001-10-19 17:46:13 +00:00
|
|
|
: width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_()
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-11-13 12:51:43 +00:00
|
|
|
void MathXArray::metrics(MathMetricsInfo const & mi) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-11-13 12:51:43 +00:00
|
|
|
size_ = mi;
|
|
|
|
mathed_char_dim(LM_TC_VAR, mi, 'I', ascent_, descent_, width_);
|
2001-09-03 08:55:56 +00:00
|
|
|
|
|
|
|
if (data_.empty())
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
2001-09-03 11:38:04 +00:00
|
|
|
|
2001-11-13 12:51:43 +00:00
|
|
|
math_font_max_dim(LM_TC_TEXTRM, mi, ascent_, descent_);
|
2001-10-19 17:46:13 +00:00
|
|
|
width_ = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
//lyxerr << "MathXArray::metrics(): '" << data_ << "'\n";
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
for (const_iterator it = begin(); it != end(); ++it) {
|
|
|
|
MathInset const * p = it->nucleus();
|
2001-11-09 08:35:57 +00:00
|
|
|
MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
|
|
|
|
if (q) {
|
2001-11-13 12:51:43 +00:00
|
|
|
q->metrics(p, mi);
|
2002-01-08 11:03:34 +00:00
|
|
|
ascent_ = std::max(ascent_, q->ascent2(p));
|
|
|
|
descent_ = std::max(descent_, q->descent2(p));
|
|
|
|
width_ += q->width2(p);
|
2001-10-12 12:02:49 +00:00
|
|
|
++it;
|
|
|
|
} else {
|
2001-11-13 12:51:43 +00:00
|
|
|
p->metrics(mi);
|
2001-10-12 12:02:49 +00:00
|
|
|
ascent_ = std::max(ascent_, p->ascent());
|
|
|
|
descent_ = std::max(descent_, p->descent());
|
|
|
|
width_ += p->width();
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-09-11 14:15:30 +00:00
|
|
|
//lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
|
|
|
|
// << descent_ << " " << width_ << "'\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathXArray::draw(Painter & pain, int x, int y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
xo_ = x;
|
|
|
|
yo_ = y;
|
|
|
|
|
|
|
|
if (data_.empty()) {
|
|
|
|
pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it) {
|
|
|
|
MathInset const * p = it->nucleus();
|
2001-11-09 08:35:57 +00:00
|
|
|
MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
|
|
|
|
if (q) {
|
2001-10-12 12:02:49 +00:00
|
|
|
q->draw(p, pain, x, y);
|
2002-01-08 11:03:34 +00:00
|
|
|
x += q->width2(p);
|
2001-10-12 12:02:49 +00:00
|
|
|
++it;
|
|
|
|
} else {
|
|
|
|
p->draw(pain, x, y);
|
|
|
|
x += p->width();
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
int MathXArray::pos2x(size_type targetpos) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
int x = 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
const_iterator target = std::min(begin() + targetpos, end());
|
|
|
|
for (const_iterator it = begin(); it < target; ++it) {
|
|
|
|
MathInset const * p = it->nucleus();
|
2001-11-09 08:35:57 +00:00
|
|
|
MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
|
|
|
|
if (q) {
|
2001-10-12 12:02:49 +00:00
|
|
|
++it;
|
|
|
|
if (it < target)
|
2002-01-08 11:03:34 +00:00
|
|
|
x += q->width2(p);
|
2001-10-12 12:02:49 +00:00
|
|
|
else // "half" position
|
|
|
|
x += q->dxx(p) + q->nwid(p);
|
|
|
|
} else
|
|
|
|
x += p->width();
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
MathArray::size_type MathXArray::x2pos(int targetx) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
const_iterator it = begin();
|
|
|
|
int lastx = 0;
|
|
|
|
int currx = 0;
|
|
|
|
for ( ; currx < targetx && it < end(); ++it) {
|
2001-07-24 16:39:55 +00:00
|
|
|
lastx = currx;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
int wid = 0;
|
|
|
|
MathInset const * p = it->nucleus();
|
2001-11-09 08:35:57 +00:00
|
|
|
MathScriptInset const * q = 0;
|
|
|
|
if (it + 1 != end())
|
|
|
|
q = asScript(it);
|
|
|
|
if (q) {
|
2002-01-08 11:03:34 +00:00
|
|
|
wid = q->width2(p);
|
2001-10-12 12:02:49 +00:00
|
|
|
++it;
|
|
|
|
} else
|
|
|
|
wid = p->width();
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
currx += wid;
|
|
|
|
}
|
|
|
|
if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
|
|
|
|
--it;
|
|
|
|
return it - begin();
|
2001-10-10 13:20:51 +00:00
|
|
|
}
|
2001-11-22 10:14:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
int MathXArray::dist(int x, int y) const
|
|
|
|
{
|
|
|
|
int xx = 0;
|
|
|
|
int yy = 0;
|
|
|
|
|
|
|
|
if (x < xo_)
|
|
|
|
xx = xo_ - x;
|
|
|
|
else if (x > xo_ + width_)
|
|
|
|
xx = x - xo_ - width_;
|
|
|
|
|
|
|
|
if (y < yo_ - ascent_)
|
|
|
|
yy = yo_ - ascent_ - y;
|
|
|
|
else if (y > yo_ + descent_)
|
|
|
|
yy = y - yo_ - descent_;
|
|
|
|
|
|
|
|
return xx + yy;
|
|
|
|
}
|
2001-11-26 13:35:08 +00:00
|
|
|
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
|
|
|
|
{
|
|
|
|
x1 = xo_;
|
|
|
|
x2 = xo_ + width_;
|
|
|
|
y1 = yo_ - ascent_;
|
|
|
|
y2 = yo_ + descent_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
void MathXArray::findPos(MathPosFinder & f) const
|
|
|
|
{
|
|
|
|
double x = xo_;
|
|
|
|
double y = yo_;
|
|
|
|
for (const_iterator it = begin(); it < end(); ++it) {
|
|
|
|
// check this position in the cell first
|
|
|
|
f.visit(x, y);
|
|
|
|
f.nextPos();
|
|
|
|
|
|
|
|
// check inset
|
|
|
|
MathInset const * p = it->nucleus();
|
|
|
|
p->findPos(f);
|
|
|
|
|
|
|
|
// move on
|
|
|
|
MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
|
|
|
|
if (q) {
|
|
|
|
x += q->width(p);
|
|
|
|
f.nextPos();
|
|
|
|
++it;
|
|
|
|
} else {
|
|
|
|
x += p->width();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|