8 #include "math_inset.h"
9 #include "mathed/support.h"
10 #include "math_defs.h"
17 MathXArray::MathXArray()
18 : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), style_(LM_ST_TEXT)
22 void MathXArray::metrics(MathStyles st)
25 mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
34 for (int pos = 0; pos < data_.size(); data_.next(pos)) {
38 MathInset * p = data_.nextInset(pos);
45 char cx = data_.getChar(pos);
46 MathTextCodes fc = data_.getCode(pos);
47 mathed_char_dim(fc, style_, cx, asc, des, wid);
49 ascent_ = max(ascent_, asc);
50 descent_ = max(descent_, des);
56 void MathXArray::draw(Painter & pain, int x, int y)
62 pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
66 for (int pos = 0; pos < data_.size(); data_.next(pos)) {
67 MathInset * p = data_.nextInset(pos);
72 char cx = data_.getChar(pos);
73 MathTextCodes fc = data_.getCode(pos);
76 drawStr(pain, fc, style_, x, y, s);
77 x += mathed_char_width(fc, style_, cx);
83 int MathXArray::pos2x(int targetpos) const
86 targetpos = min(targetpos, data_.size());
87 for (int pos = 0; pos < targetpos; data_.next(pos))
93 int MathXArray::x2pos(int targetx) const
98 while (currx < targetx && pos < data_.size()) {
103 if (abs(lastx - targetx) < abs(currx - targetx))
108 int MathXArray::width(int pos) const
110 if (pos >= data_.size())
113 if (data_.isInset(pos))
114 return data_.nextInset(pos)->width();
116 return mathed_char_width(data_.getCode(pos), style_, data_.getChar(pos));
119 std::ostream & operator<<(std::ostream & os, MathXArray const & ar)