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-10-19 11:25:48 +00:00
|
|
|
void MathXArray::metrics(MathMetricsInfo const & st) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-10-19 17:46:13 +00:00
|
|
|
size_ = st;
|
|
|
|
mathed_char_dim(LM_TC_VAR, st, '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-10-19 17:46:13 +00:00
|
|
|
math_font_max_dim(LM_TC_TEXTRM, st, ascent_, descent_);
|
|
|
|
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-10-12 12:02:49 +00:00
|
|
|
q->metrics(p, st);
|
|
|
|
ascent_ = std::max(ascent_, q->ascent(p));
|
|
|
|
descent_ = std::max(descent_, q->descent(p));
|
|
|
|
width_ += q->width(p);
|
|
|
|
++it;
|
|
|
|
} else {
|
|
|
|
p->metrics(st);
|
|
|
|
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);
|
|
|
|
x += q->width(p);
|
|
|
|
++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)
|
|
|
|
x += q->width(p);
|
|
|
|
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) {
|
2001-10-12 12:02:49 +00:00
|
|
|
wid = q->width(p);
|
|
|
|
++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
|
|
|
}
|