-#include <config.h>
+/**
+ * \file math_data.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+#include <config.h>
#include "math_data.h"
-#include "math_inset.h"
#include "math_cursor.h"
-#include "math_deliminset.h"
#include "math_fontinset.h"
#include "math_scriptinset.h"
#include "math_mathmlstream.h"
#include "math_support.h"
#include "math_replace.h"
#include "debug.h"
-#include "support/LAssert.h"
-#include "metricsinfo.h"
+#include "LColor.h"
+
#include "frontends/Painter.h"
-#include "textpainter.h"
+#include <boost/assert.hpp>
-using std::max;
-using std::min;
using std::abs;
-
+using std::endl;
+using std::min;
+using std::ostringstream;
MathArray::MathArray()
}
-MathAtom & MathArray::operator[](size_type pos)
+MathAtom & MathArray::operator[](pos_type pos)
{
- lyx::Assert(pos < size());
+ BOOST_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());
+ BOOST_ASSERT(pos < size());
return base_type::operator[](pos);
}
void MathArray::insert(size_type pos, MathArray const & ar)
{
- lyx::Assert(pos <= size());
+ BOOST_ASSERT(pos <= size());
base_type::insert(begin() + pos, ar.begin(), ar.end());
}
return false;
const_iterator it = begin() + pos;
for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
- if (!(*jt)->match(*it))
+ if (asString(*it) != asString(*jt))
return false;
return true;
}
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);
}
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]))
+ if (asString(operator[](pos + i)) != asString(ar[i]))
return false;
return true;
}
}
-Dimension const & MathArray::metrics(MetricsInfo & mi) const
+void MathArray::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+ metrics(mi);
+ dim = dim_;
+}
+
+
+void MathArray::metrics(MetricsInfo & mi) const
{
//if (clean_)
// return;
drawn_ = false;
mathed_char_dim(mi.base.font, 'I', dim_);
- if (empty())
- return dim_;
- dim_.wid = 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_;
}
}
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_;
}
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->drawT(pain, x, y);
- x += (*it)->width();
+ x += it->width_;
}
}
const_iterator it = begin() + i;
if ((*it)->getChar() == ' ')
x += glue;
- x += (*it)->width();
+ x += it->width_;
}
return x;
}
lastx = currx;
if ((*it)->getChar() == ' ')
currx += glue;
- currx += (*it)->width();
+ currx += it->width_;
}
if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
--it;