]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/xarray.C
further code uglification to make Jean-Marc's compiler happy
[lyx.git] / src / mathed / xarray.C
index ae078a1921c1867e66be240a79f2b9233008ae5c..f90008e817a4e025744caac7e0e7c9fe3f5900cc 100644 (file)
@@ -9,9 +9,7 @@
 #include "mathed/support.h"
 #include "math_defs.h"
 #include "Painter.h"
-
-using std::max;
-using std::min;
+#include "debug.h"
 
 
 MathXArray::MathXArray()
@@ -19,41 +17,31 @@ MathXArray::MathXArray()
 {}
 
 
-void MathXArray::metrics(MathStyles st)
+void MathXArray::metrics(MathStyles st) const
 {
-       if (data_.empty()) {
-               mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_); 
+       style_   = st;
+       mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
+
+       if (data_.empty()) 
                return;
-       }
-       
-       ascent_  = 0;
-       descent_ = 0;
+
+       math_font_max_dim(LM_TC_TEXTRM, st, ascent_, descent_); 
        width_   = 0;
-       style_    = st;
-
-       for (int pos = 0; pos < data_.size(); data_.next(pos)) {
-               int asc;
-               int des;
-               int wid;
-               MathInset * p = data_.nextInset(pos);
-               if (p) {
-                       p->metrics(st);
-                       asc = p->ascent();
-                       des = p->descent();
-                       wid = p->width();
-               } else {
-                       char cx = data_.GetChar(pos); 
-                       MathTextCodes fc = data_.GetCode(pos); 
-                       mathed_char_dim(fc, style_, cx, asc, des, wid);
-               }
-               ascent_  = max(ascent_, asc);
-               descent_ = max(descent_, des);
-               width_   += wid;
+
+       //lyxerr << "MathXArray::metrics(): '" << data_ << "'\n";
+       for (size_type pos = 0; pos < data_.size(); ++pos) {
+               MathAtom const * p = data_.at(pos);
+               p->metrics(st);
+               ascent_  = std::max(ascent_,  p->ascent());
+               descent_ = std::max(descent_, p->descent());
+               width_  += p->width();
        }
+       //lyxerr << "MathXArray::metrics(): '" << ascent_ << " " 
+       //      << descent_ << " " << width_ << "'\n";
 }
 
 
-void MathXArray::draw(Painter & pain, int x, int y)
+void MathXArray::draw(Painter & pain, int x, int y) const
 {
        xo_ = x;
        yo_ = y;
@@ -63,62 +51,48 @@ void MathXArray::draw(Painter & pain, int x, int y)
                return;
        }
 
-       for (int pos = 0; pos < data_.size(); data_.next(pos)) {
-               MathInset * p = data_.nextInset(pos);
-               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);
-               }
+       for (size_type pos = 0; pos < data_.size(); ++pos) {
+               MathAtom const * p = data_.at(pos);
+               p->draw(pain, x, y);
+               x += p->width();
        }
 }
 
 
-int MathXArray::pos2x(int targetpos) const
+int MathXArray::pos2x(size_type targetpos) const
 {
        int x = 0;
-       targetpos = min(targetpos, data_.size());
-       for (int pos = 0; pos < targetpos; data_.next(pos)
+       targetpos = std::min(targetpos, data_.size());
+       for (size_type pos = 0; pos < targetpos; ++pos
                x += width(pos);
        return x;
 }
 
 
-int MathXArray::x2pos(int targetx) const
+MathArray::size_type MathXArray::x2pos(int targetx) const
 {
-       int pos   = 0;
-       int lastx = 0;
-       int currx = 0;
-       while (currx < targetx && pos < data_.size()) {
+       size_type pos  = 0;
+       int lastx      = 0;
+       int currx      = 0;
+       for ( ; currx < targetx && pos < data_.size(); ++pos) {
                lastx = currx;
                currx += width(pos);
-               data_.next(pos);
        }
-       if (abs(lastx - targetx) < abs(currx - targetx))
-               data_.prev(pos);
+       if (abs(lastx - targetx) < abs(currx - targetx) && pos > 0)
+               --pos;
        return pos;
 }
 
-int MathXArray::width(int pos) const
-{
-       if (pos >= data_.size())
-               return 0;
 
-       if (data_.isInset(pos)) 
-               return data_.nextInset(pos)->width();
-       else 
-               return mathed_char_width(data_.GetCode(pos), style_, data_.GetChar(pos));
+int MathXArray::width(size_type pos) const
+{
+       MathAtom const * t = data_.at(pos);
+       return t ? t->width() : 0;
 }
 
+
 std::ostream & operator<<(std::ostream & os, MathXArray const & ar)
 {
        os << ar.data_;
        return os;
 }
-