2001-06-25 00:06:33 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "xarray.h"
|
|
|
|
#include "math_inset.h"
|
|
|
|
#include "mathed/support.h"
|
|
|
|
#include "math_defs.h"
|
|
|
|
#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-06-25 00:06:33 +00:00
|
|
|
MathXArray::MathXArray()
|
|
|
|
: width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), style_(LM_ST_TEXT)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathXArray::metrics(MathStyles st) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-03 08:55:56 +00:00
|
|
|
style_ = st;
|
|
|
|
mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
|
|
|
|
|
|
|
|
if (data_.empty())
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
2001-09-03 11:38:04 +00:00
|
|
|
|
2001-09-24 14:03:48 +00:00
|
|
|
math_font_max_dim(LM_TC_TEXTRM, st, ascent_, descent_);
|
2001-06-25 00:06:33 +00:00
|
|
|
width_ = 0;
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
//lyxerr << "MathXArray::metrics(): '" << data_ << "'\n";
|
2001-09-14 14:05:57 +00:00
|
|
|
for (size_type pos = 0; pos < data_.size(); ++pos) {
|
2001-09-11 10:58:17 +00:00
|
|
|
MathAtom const * p = data_.at(pos);
|
2001-08-03 17:10:22 +00:00
|
|
|
p->metrics(st);
|
2001-09-11 10:58:17 +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-09-14 14:05:57 +00:00
|
|
|
for (size_type pos = 0; pos < data_.size(); ++pos) {
|
2001-09-11 10:58:17 +00:00
|
|
|
MathAtom const * p = data_.at(pos);
|
2001-08-03 17:10:22 +00:00
|
|
|
p->draw(pain, x, y);
|
|
|
|
x += p->width();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
int MathXArray::pos2x(size_type targetpos) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
int x = 0;
|
2001-09-11 10:58:17 +00:00
|
|
|
targetpos = std::min(targetpos, data_.size());
|
2001-09-14 14:05:57 +00:00
|
|
|
for (size_type pos = 0; pos < targetpos; ++pos)
|
2001-06-25 00:06:33 +00:00
|
|
|
x += width(pos);
|
|
|
|
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-09-14 14:05:57 +00:00
|
|
|
size_type pos = 0;
|
|
|
|
int lastx = 0;
|
|
|
|
int currx = 0;
|
2001-08-03 17:10:22 +00:00
|
|
|
for ( ; currx < targetx && pos < data_.size(); ++pos) {
|
2001-07-24 16:39:55 +00:00
|
|
|
lastx = currx;
|
|
|
|
currx += width(pos);
|
|
|
|
}
|
2001-08-06 17:20:26 +00:00
|
|
|
if (abs(lastx - targetx) < abs(currx - targetx) && pos > 0)
|
|
|
|
--pos;
|
2001-06-25 00:06:33 +00:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
int MathXArray::width(size_type pos) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-11 10:58:17 +00:00
|
|
|
MathAtom const * t = data_.at(pos);
|
|
|
|
return t ? t->width() : 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-07-04 17:17:32 +00:00
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2001-07-04 17:17:32 +00:00
|
|
|
std::ostream & operator<<(std::ostream & os, MathXArray const & ar)
|
|
|
|
{
|
|
|
|
os << ar.data_;
|
2001-07-06 12:09:32 +00:00
|
|
|
return os;
|
2001-07-04 17:17:32 +00:00
|
|
|
}
|