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-06-27 15:57:57 +00:00
|
|
|
using std::max;
|
|
|
|
using std::min;
|
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-07-26 06:46:50 +00:00
|
|
|
void MathXArray::Metrics(MathStyles st)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (data_.empty()) {
|
|
|
|
mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ascent_ = 0;
|
|
|
|
descent_ = 0;
|
|
|
|
width_ = 0;
|
|
|
|
style_ = st;
|
|
|
|
|
|
|
|
for (int pos = 0; pos < data_.size(); data_.next(pos)) {
|
2001-07-26 06:46:50 +00:00
|
|
|
int asc;
|
|
|
|
int des;
|
|
|
|
int wid;
|
2001-07-12 07:18:29 +00:00
|
|
|
MathInset * p = data_.nextInset(pos);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (p) {
|
2001-07-26 06:46:50 +00:00
|
|
|
p->Metrics(st);
|
2001-07-12 07:18:29 +00:00
|
|
|
asc = p->ascent();
|
|
|
|
des = p->descent();
|
|
|
|
wid = p->width();
|
2001-06-25 00:06:33 +00:00
|
|
|
} else {
|
|
|
|
char cx = data_.GetChar(pos);
|
|
|
|
MathTextCodes fc = data_.GetCode(pos);
|
|
|
|
mathed_char_dim(fc, style_, cx, asc, des, wid);
|
|
|
|
}
|
2001-07-12 07:18:29 +00:00
|
|
|
ascent_ = max(ascent_, asc);
|
|
|
|
descent_ = max(descent_, des);
|
|
|
|
width_ += wid;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathXArray::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
|
|
|
xo_ = x;
|
|
|
|
yo_ = y;
|
|
|
|
|
|
|
|
if (data_.empty()) {
|
|
|
|
pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int pos = 0; pos < data_.size(); data_.next(pos)) {
|
2001-07-12 07:18:29 +00:00
|
|
|
MathInset * p = data_.nextInset(pos);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (p) {
|
|
|
|
p->draw(pain, x, y);
|
|
|
|
x += p->width();
|
|
|
|
} else {
|
|
|
|
char cx = data_.GetChar(pos);
|
|
|
|
MathTextCodes fc = data_.GetCode(pos);
|
|
|
|
string s;
|
|
|
|
s += cx;
|
|
|
|
drawStr(pain, fc, style_, x, y, s);
|
|
|
|
x += mathed_char_width(fc, style_, cx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathXArray::pos2x(int targetpos) const
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
targetpos = min(targetpos, data_.size());
|
|
|
|
for (int pos = 0; pos < targetpos; data_.next(pos))
|
|
|
|
x += width(pos);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathXArray::x2pos(int targetx) const
|
|
|
|
{
|
2001-07-24 16:39:55 +00:00
|
|
|
int pos = 0;
|
|
|
|
int lastx = 0;
|
|
|
|
int currx = 0;
|
|
|
|
while (currx < targetx && pos < data_.size()) {
|
|
|
|
lastx = currx;
|
|
|
|
currx += width(pos);
|
|
|
|
data_.next(pos);
|
|
|
|
}
|
|
|
|
if (abs(lastx - targetx) < abs(currx - targetx))
|
|
|
|
data_.prev(pos);
|
2001-06-25 00:06:33 +00:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MathXArray::width(int pos) const
|
|
|
|
{
|
|
|
|
if (pos >= data_.size())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (data_.isInset(pos))
|
2001-07-12 07:18:29 +00:00
|
|
|
return data_.nextInset(pos)->width();
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
|
|
|
return mathed_char_width(data_.GetCode(pos), style_, data_.GetChar(pos));
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|