]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_data.C
architectural changes to tex2lyx
[lyx.git] / src / mathed / math_data.C
index 1f65cd705a856566805f3e6dae92b72cabdd5179..60d9833f4acc9a4b011169f873ac5e0004084875 100644 (file)
@@ -1,6 +1,5 @@
 #include <config.h>
 
-
 #include "math_data.h"
 #include "math_inset.h"
 #include "math_cursor.h"
 #include "math_replace.h"
 #include "debug.h"
 #include "support/LAssert.h"
-#include "math_metricsinfo.h"
+#include "metricsinfo.h"
+#include "math_data.h"
 #include "frontends/Painter.h"
 #include "textpainter.h"
 
+using namespace lyx::support;
 
 using std::max;
 using std::min;
 using std::abs;
-
+using std::endl;
 
 
 MathArray::MathArray()
@@ -40,16 +41,16 @@ void MathArray::substitute(MathMacro const & m)
 }
 
 
-MathAtom & MathArray::operator[](size_type pos)
+MathAtom & MathArray::operator[](pos_type pos)
 {
-       lyx::Assert(pos < size());
+       Assert(pos < size());
        return base_type::operator[](pos);
 }
 
 
-MathAtom const & MathArray::operator[](size_type pos) const
+MathAtom const & MathArray::operator[](pos_type pos) const
 {
-       lyx::Assert(pos < size());
+       Assert(pos < size());
        return base_type::operator[](pos);
 }
 
@@ -62,7 +63,7 @@ void MathArray::insert(size_type pos, MathAtom const & t)
 
 void MathArray::insert(size_type pos, MathArray const & ar)
 {
-       lyx::Assert(pos <= size());
+       Assert(pos <= size());
        base_type::insert(begin() + pos, ar.begin(), ar.end());
 }
 
@@ -144,7 +145,7 @@ void MathArray::replace(ReplaceData & rep)
        for (size_type i = 0; i < size(); ++i) {
                if (find1(rep.from, i)) {
                        // match found
-                       lyxerr << "match found!\n";
+                       lyxerr << "match found!" << endl;
                        erase(i, i + rep.from.size());
                        insert(i, rep.to);
                }
@@ -160,7 +161,7 @@ void MathArray::replace(ReplaceData & rep)
 
 bool MathArray::find1(MathArray const & ar, size_type pos) const
 {
-       //lyxerr << "finding '" << ar << "' in '" << *this << "'\n";
+       //lyxerr << "finding '" << ar << "' in '" << *this << "'" << endl;
        for (size_type i = 0, n = ar.size(); i < n; ++i)
                if (!operator[](pos + i)->match(ar[i]))
                        return false;
@@ -204,7 +205,14 @@ void MathArray::touch() const
 }
 
 
-Dimension const & MathArray::metrics(MathMetricsInfo & mi) const
+void MathArray::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       metrics(mi);
+       dim = dim_;
+}
+
+
+void MathArray::metrics(MetricsInfo & mi) const
 {
        //if (clean_)
        //      return;
@@ -212,19 +220,20 @@ Dimension const & MathArray::metrics(MathMetricsInfo & mi) const
        drawn_  = false;
 
        mathed_char_dim(mi.base.font, 'I', dim_);
-       if (empty())
-               return dim_;
 
-       dim_.w = 0;
-       for (const_iterator it = begin(), et = end(); it != et; ++it) {
-               (*it)->metrics(mi);
-               dim_ += (*it)->dimensions();
+       if (!empty()) {
+               dim_.wid = 0;
+               Dimension d;
+               for (const_iterator it = begin(), et = end(); it != et; ++it) {
+                       (*it)->metrics(mi, d);
+                       dim_ += d;
+                       it->width_ = d.wid;
+               }
        }
-       return dim_;
 }
 
 
-void MathArray::draw(MathPainterInfo & pi, int x, int y) const
+void MathArray::draw(PainterInfo & pi, int x, int y) const
 {
        //if (drawn_ && x == xo_ && y == yo_)
        //      return;
@@ -249,22 +258,23 @@ void MathArray::draw(MathPainterInfo & pi, int x, int y) const
        }
 
        for (const_iterator it = begin(), et = end(); it != et; ++it) {
+               pi.width = it->width_;
                (*it)->draw(pi, x, y);
-               x += (*it)->width();
+               x += it->width_;
        }
 }
 
 
-Dimension const & MathArray::metricsT(TextMetricsInfo const & mi) const
+void MathArray::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
 {
        //if (clean_)
        //      return;
-       dim_.clear();
+       dim.clear();
+       Dimension d;
        for (const_iterator it = begin(); it != end(); ++it) {
-               (*it)->metricsT(mi);
-               dim_ += (*it)->dimensions();
+               (*it)->metricsT(mi, d);
+               dim += d;
        }
-       return dim_;
 }
 
 
@@ -279,26 +289,26 @@ void MathArray::drawT(TextPainter & pain, int x, int y) const
 
        for (const_iterator it = begin(), et = end(); it != et; ++it) {
                (*it)->drawT(pain, x, y);
-               x += (*it)->width();
+               x += it->width_;
        }
 }
 
 
 int MathArray::pos2x(size_type pos) const
 {
-       return pos2x(0, pos, 0);
+       return pos2x(pos, 0);
 }
 
 
-int MathArray::pos2x(size_type pos1, size_type pos2, int glue) const
+int MathArray::pos2x(size_type pos, int glue) const
 {
        int x = 0;
-       size_type target = min(pos2, size());
-       for (size_type i = pos1; i < target; ++i) {
+       size_type target = min(pos, size());
+       for (size_type i = 0; i < target; ++i) {
                const_iterator it = begin() + i;
                if ((*it)->getChar() == ' ')
                        x += glue;
-               x += (*it)->width();
+               x += it->width_;
        }
        return x;
 }
@@ -306,23 +316,22 @@ int MathArray::pos2x(size_type pos1, size_type pos2, int glue) const
 
 MathArray::size_type MathArray::x2pos(int targetx) const
 {
-       return x2pos(0, targetx, 0);
+       return x2pos(targetx, 0);
 }
 
 
-MathArray::size_type MathArray::x2pos(size_type startpos, int targetx,
-       int glue) const
+MathArray::size_type MathArray::x2pos(int targetx, int glue) const
 {
-       const_iterator it = begin() + startpos;
+       const_iterator it = begin();
        int lastx = 0;
        int currx = 0;
        for (; currx < targetx && it < end(); ++it) {
                lastx = currx;
                if ((*it)->getChar() == ' ')
                        currx += glue;
-               currx += (*it)->width();
+               currx += it->width_;
        }
-       if (abs(lastx - targetx) < abs(currx - targetx) && it != begin() + startpos)
+       if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
                --it;
        return it - begin();
 }