INCLUDES = -I${srcdir}/../ $(SIGC_CFLAGS) $(BOOST_INCLUDES)
libmathed_la_SOURCES = \
- array.C \
- array.h \
- xarray.C \
- xarray.h \
formulabase.C \
formulabase.h \
formula.C \
math_charinset.h \
math_cursor.C \
math_cursor.h \
+ math_data.C \
+ math_data.h \
math_decorationinset.C \
math_decorationinset.h \
math_defs.h \
math_support.C \
math_support.h \
math_symbolinset.C \
- math_symbolinset.h
+ math_symbolinset.h \
+ math_xdata.C \
+ math_xdata.h
+++ /dev/null
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "math_inset.h"
-#include "math_charinset.h"
-#include "math_scriptinset.h"
-#include "math_stringinset.h"
-#include "math_mathmlstream.h"
-#include "math_support.h"
-#include "debug.h"
-#include "array.h"
-#include "support/LAssert.h"
-
-
-MathArray::MathArray()
-{}
-
-
-MathArray::MathArray(MathArray const & array, size_type from, size_type to)
- : bf_(array.begin() + from, array.begin() + to)
-{}
-
-
-void MathArray::substitute(MathMacro const & m)
-{
- for (iterator it = begin(); it != end(); ++it)
- it->nucleus()->substitute(m);
-}
-
-
-MathScriptInset const * MathArray::asScript(const_iterator it) const
-{
- if (it->nucleus()->asScriptInset())
- return 0;
- const_iterator jt = it + 1;
- if (jt == end())
- return 0;
- if (!jt->nucleus())
- return 0;
- return jt->nucleus()->asScriptInset();
-}
-
-
-MathAtom & MathArray::at(size_type pos)
-{
- lyx::Assert(pos < size());
- return bf_[pos];
-}
-
-
-MathAtom const & MathArray::at(size_type pos) const
-{
- lyx::Assert(pos < size());
- return bf_[pos];
-}
-
-
-void MathArray::insert(size_type pos, MathAtom const & t)
-{
- bf_.insert(begin() + pos, t);
-}
-
-
-void MathArray::insert(size_type pos, MathArray const & array)
-{
- bf_.insert(begin() + pos, array.begin(), array.end());
-}
-
-
-void MathArray::push_back(MathAtom const & t)
-{
- bf_.push_back(t);
-}
-
-
-void MathArray::push_back(MathArray const & array)
-{
- insert(size(), array);
-}
-
-
-void MathArray::clear()
-{
- erase();
-}
-
-
-void MathArray::swap(MathArray & array)
-{
- if (this != &array)
- bf_.swap(array.bf_);
-}
-
-
-bool MathArray::empty() const
-{
- return bf_.empty();
-}
-
-
-MathArray::size_type MathArray::size() const
-{
- return bf_.size();
-}
-
-
-void MathArray::erase()
-{
- erase(0, size());
-}
-
-
-void MathArray::erase(size_type pos)
-{
- if (pos < size())
- erase(pos, pos + 1);
-}
-
-
-void MathArray::erase(size_type pos1, size_type pos2)
-{
- bf_.erase(begin() + pos1, begin() + pos2);
-}
-
-
-MathAtom & MathArray::back()
-{
- return bf_.back();
-}
-
-
-void MathArray::dump2() const
-{
- NormalStream ns(lyxerr);
- for (const_iterator it = begin(); it != end(); ++it)
- ns << it->nucleus() << ' ';
-}
-
-
-void MathArray::dump() const
-{
- NormalStream ns(lyxerr);
- for (const_iterator it = begin(); it != end(); ++it)
- ns << "<" << it->nucleus() << ">";
-}
-
-
-// returns sequence of char with same code starting at it up to end
-// it might be less, though...
-string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
-{
- string s;
- MathCharInset const * p = it->nucleus()->asCharInset();
- if (!p)
- return s;
-
- for (MathTextCodes c = p->code(); it != end; ++it) {
- if (!it->nucleus())
- break;
- p = it->nucleus()->asCharInset();
- if (!p || p->code() != c)
- break;
- s += p->getChar();
- }
- return s;
-}
-
-
-MathArray MathArray::glueChars() const
-{
- MathArray ar;
- const_iterator it = begin();
- while (it != end()) {
- if (it->nucleus() && it->nucleus()->asCharInset()) {
- string s = charSequence(it, end());
- MathTextCodes c = it->nucleus()->asCharInset()->code();
- ar.push_back(MathAtom(new MathStringInset(s, c)));
- it += s.size();
- } else {
- ar.push_back(*it);
- ++it;
- }
- }
- return ar;
-}
-
-
-bool needAsterisk(MathAtom const &, MathAtom const &)
-{
- return false;
-}
-
-
-MathArray MathArray::guessAsterisks() const
-{
- if (size() <= 1)
- return *this;
- MathArray ar;
- ar.push_back(*begin());
- for (const_iterator it = begin(), jt = begin()+1 ; jt != end(); ++it, ++jt) {
- if (needAsterisk(*it, *jt))
- ar.push_back(MathAtom(new MathCharInset('*')));
- ar.push_back(*it);
- }
- ar.push_back(*end());
- return ar;
-}
-
-
-void MathArray::write(MathWriteInfo & wi) const
-{
- MathArray ar = glueChars();
- for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = ar.asScript(it)) {
- q->write(p, wi);
- ++it;
- } else {
- p->write(wi);
- }
- }
-}
-
-
-void MathArray::writeNormal(NormalStream & os) const
-{
- MathArray ar = glueChars();
- for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = ar.asScript(it)) {
- q->writeNormal(p, os);
- ++it;
- } else
- p->writeNormal(os);
- }
-}
-
-
-void MathArray::octavize(OctaveStream & os) const
-{
- MathArray ar = glueChars();
- for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = ar.asScript(it)) {
- q->octavize(p, os);
- ++it;
- } else
- p->octavize(os);
- }
-}
-
-
-void MathArray::maplize(MapleStream & os) const
-{
- MathArray ar = glueChars();
- for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = ar.asScript(it)) {
- q->maplize(p, os);
- ++it;
- } else
- p->maplize(os);
- }
-}
-
-
-void MathArray::mathmlize(MathMLStream & os) const
-{
- MathArray ar = glueChars();
- if (ar.size() == 0)
- os << "<mrow/>";
- else if (ar.size() == 1)
- os << ar.begin()->nucleus();
- else {
- os << MTag("mrow");
- for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = ar.asScript(it)) {
- q->mathmlize(p, os);
- ++it;
- } else
- p->mathmlize(os);
- }
- os << ETag("mrow");
- }
-}
-
-
-void MathArray::validate(LaTeXFeatures & features) const
-{
- for (const_iterator it = begin(); it != end(); ++it)
- if (it->nucleus())
- it->nucleus()->validate(features);
-}
-
-
-void MathArray::pop_back()
-{
- if (!size()) {
- lyxerr << "pop_back from empty array!\n";
- return;
- }
- bf_.pop_back();
-}
-
-
-MathArray::const_iterator MathArray::begin() const
-{
- return bf_.begin();
-}
-
-
-MathArray::const_iterator MathArray::end() const
-{
- return bf_.end();
-}
-
-
-MathArray::iterator MathArray::begin()
-{
- return bf_.begin();
-}
-
-
-MathArray::iterator MathArray::end()
-{
- return bf_.end();
-}
-
-
-bool MathArray::isMatrix() const
-{
- return size() == 1 && begin()->nucleus() && begin()->nucleus()->isMatrix();
-}
-
-
+++ /dev/null
-// -*- C++ -*-
-/*
- * Purpose: A general purpose resizable array.
- * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
- * Created: January 1996
- *
- * Dependencies: None (almost)
- *
- * Copyright: 1996, Alejandro Aguilar Sierra
- * 1997 The LyX Team!
- *
- * You are free to use and modify this code under the terms of
- * the GNU General Public Licence version 2 or later.
- */
-
-#ifndef MATHEDARRAY_H
-#define MATHEDARRAY_H
-
-#include <vector>
-
-#include "math_atom.h"
-#include "LString.h"
-
-class MathScriptInset;
-class MathMacro;
-class MathWriteInfo;
-class MathMetricsInfo;
-class LaTeXFeatures;
-class NormalStream;
-class MapleStream;
-class MathMLStream;
-class OctaveStream;
-
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-
-/** \class MathArray
- \brief Low level container for math insets
-
- \author Alejandro Aguilar Sierra
- \author André Pönitz
- \author Lars Gullik Bjønnes
- \version February 2001
- */
-
-class MathArray {
-public:
- ///
- typedef std::vector<MathAtom> buffer_type;
- ///
- typedef buffer_type::const_iterator const_iterator;
- ///
- typedef buffer_type::iterator iterator;
- ///
- typedef buffer_type::size_type size_type;
-
-public:
- ///
- MathArray();
- ///
- MathArray(MathArray const &, size_type from, size_type to);
-
- ///
- size_type size() const;
- ///
- bool empty() const;
- ///
- void clear();
- ///
- void swap(MathArray &);
-
- ///
- void insert(size_type pos, MathAtom const &);
- ///
- void insert(size_type pos, MathArray const &);
-
- ///
- void erase(size_type pos1, size_type pos2);
- ///
- void erase(size_type pos);
- ///
- void erase();
-
- ///
- void push_back(MathAtom const &);
- ///
- void push_back(MathArray const &);
- ///
- void pop_back();
- ///
- MathAtom & back();
-
- ///
- void dump() const;
- ///
- void dump2() const;
- ///
- void substitute(MathMacro const &);
-
- ///
- MathAtom & at(size_type pos);
- ///
- MathAtom const & at(size_type pos) const;
- /// glue chars if necessary
- void write(MathWriteInfo & os) const;
- ///
- void writeNormal(NormalStream &) const;
- ///
- void validate(LaTeXFeatures &) const;
- ///
- const_iterator begin() const;
- ///
- const_iterator end() const;
- ///
- iterator begin();
- ///
- iterator end();
- ///
- MathScriptInset const * asScript(const_iterator it) const;
- /// glues chars with the same attributes into MathStringInsets
- MathArray glueChars() const;
- /// insert asterisks in "suitable" places
- MathArray guessAsterisks() const;
-
- /// interface to Octave
- void octavize(OctaveStream &) const;
- /// interface to Maple
- void maplize(MapleStream &) const;
- /// interface to MathML
- void mathmlize(MathMLStream &) const;
-
- ///
- bool isMatrix() const;
-
-private:
- /// Buffer
- buffer_type bf_;
-};
-
-#endif
--- /dev/null
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_inset.h"
+#include "math_charinset.h"
+#include "math_scriptinset.h"
+#include "math_stringinset.h"
+#include "math_mathmlstream.h"
+#include "math_support.h"
+#include "math_data.h"
+#include "debug.h"
+#include "support/LAssert.h"
+
+
+MathArray::MathArray()
+{}
+
+
+MathArray::MathArray(MathArray const & ar, size_type from, size_type to)
+ : bf_(ar.begin() + from, ar.begin() + to)
+{}
+
+
+void MathArray::substitute(MathMacro const & m)
+{
+ for (iterator it = begin(); it != end(); ++it)
+ it->nucleus()->substitute(m);
+}
+
+
+MathScriptInset const * MathArray::asScript(const_iterator it) const
+{
+ if (it->nucleus()->asScriptInset())
+ return 0;
+ const_iterator jt = it + 1;
+ if (jt == end())
+ return 0;
+ if (!jt->nucleus())
+ return 0;
+ return jt->nucleus()->asScriptInset();
+}
+
+
+MathAtom & MathArray::at(size_type pos)
+{
+ lyx::Assert(pos < size());
+ return bf_[pos];
+}
+
+
+MathAtom const & MathArray::at(size_type pos) const
+{
+ lyx::Assert(pos < size());
+ return bf_[pos];
+}
+
+
+void MathArray::insert(size_type pos, MathAtom const & t)
+{
+ bf_.insert(begin() + pos, t);
+}
+
+
+void MathArray::insert(size_type pos, MathArray const & ar)
+{
+ bf_.insert(begin() + pos, ar.begin(), ar.end());
+}
+
+
+void MathArray::push_back(MathAtom const & t)
+{
+ bf_.push_back(t);
+}
+
+
+void MathArray::push_back(MathArray const & ar)
+{
+ insert(size(), ar);
+}
+
+
+void MathArray::clear()
+{
+ erase();
+}
+
+
+void MathArray::swap(MathArray & ar)
+{
+ if (this != &ar)
+ bf_.swap(ar.bf_);
+}
+
+
+bool MathArray::empty() const
+{
+ return bf_.empty();
+}
+
+
+MathArray::size_type MathArray::size() const
+{
+ return bf_.size();
+}
+
+
+void MathArray::erase()
+{
+ erase(0, size());
+}
+
+
+void MathArray::erase(size_type pos)
+{
+ if (pos < size())
+ erase(pos, pos + 1);
+}
+
+
+void MathArray::erase(size_type pos1, size_type pos2)
+{
+ bf_.erase(begin() + pos1, begin() + pos2);
+}
+
+
+MathAtom & MathArray::back()
+{
+ return bf_.back();
+}
+
+
+void MathArray::dump2() const
+{
+ NormalStream ns(lyxerr);
+ for (const_iterator it = begin(); it != end(); ++it)
+ ns << it->nucleus() << ' ';
+}
+
+
+void MathArray::dump() const
+{
+ NormalStream ns(lyxerr);
+ for (const_iterator it = begin(); it != end(); ++it)
+ ns << "<" << it->nucleus() << ">";
+}
+
+
+// returns sequence of char with same code starting at it up to end
+// it might be less, though...
+string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
+{
+ string s;
+ MathCharInset const * p = it->nucleus()->asCharInset();
+ if (!p)
+ return s;
+
+ for (MathTextCodes c = p->code(); it != end; ++it) {
+ if (!it->nucleus())
+ break;
+ p = it->nucleus()->asCharInset();
+ if (!p || p->code() != c)
+ break;
+ s += p->getChar();
+ }
+ return s;
+}
+
+
+MathArray MathArray::glueChars() const
+{
+ MathArray ar;
+ const_iterator it = begin();
+ while (it != end()) {
+ if (it->nucleus() && it->nucleus()->asCharInset()) {
+ string s = charSequence(it, end());
+ MathTextCodes c = it->nucleus()->asCharInset()->code();
+ ar.push_back(MathAtom(new MathStringInset(s, c)));
+ it += s.size();
+ } else {
+ ar.push_back(*it);
+ ++it;
+ }
+ }
+ return ar;
+}
+
+
+bool needAsterisk(MathAtom const &, MathAtom const &)
+{
+ return false;
+}
+
+
+MathArray MathArray::guessAsterisks() const
+{
+ if (size() <= 1)
+ return *this;
+ MathArray ar;
+ ar.push_back(*begin());
+ for (const_iterator it = begin(), jt = begin()+1 ; jt != end(); ++it, ++jt) {
+ if (needAsterisk(*it, *jt))
+ ar.push_back(MathAtom(new MathCharInset('*')));
+ ar.push_back(*it);
+ }
+ ar.push_back(*end());
+ return ar;
+}
+
+
+void MathArray::write(MathWriteInfo & wi) const
+{
+ MathArray ar = glueChars();
+ for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = ar.asScript(it)) {
+ q->write(p, wi);
+ ++it;
+ } else {
+ p->write(wi);
+ }
+ }
+}
+
+
+void MathArray::writeNormal(NormalStream & os) const
+{
+ MathArray ar = glueChars();
+ for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = ar.asScript(it)) {
+ q->writeNormal(p, os);
+ ++it;
+ } else
+ p->writeNormal(os);
+ }
+}
+
+
+void MathArray::octavize(OctaveStream & os) const
+{
+ MathArray ar = glueChars();
+ for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = ar.asScript(it)) {
+ q->octavize(p, os);
+ ++it;
+ } else
+ p->octavize(os);
+ }
+}
+
+
+void MathArray::maplize(MapleStream & os) const
+{
+ MathArray ar = glueChars();
+ for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = ar.asScript(it)) {
+ q->maplize(p, os);
+ ++it;
+ } else
+ p->maplize(os);
+ }
+}
+
+
+void MathArray::mathmlize(MathMLStream & os) const
+{
+ MathArray ar = glueChars();
+ if (ar.size() == 0)
+ os << "<mrow/>";
+ else if (ar.size() == 1)
+ os << ar.begin()->nucleus();
+ else {
+ os << MTag("mrow");
+ for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = ar.asScript(it)) {
+ q->mathmlize(p, os);
+ ++it;
+ } else
+ p->mathmlize(os);
+ }
+ os << ETag("mrow");
+ }
+}
+
+
+void MathArray::validate(LaTeXFeatures & features) const
+{
+ for (const_iterator it = begin(); it != end(); ++it)
+ if (it->nucleus())
+ it->nucleus()->validate(features);
+}
+
+
+void MathArray::pop_back()
+{
+ if (!size()) {
+ lyxerr << "pop_back from empty array!\n";
+ return;
+ }
+ bf_.pop_back();
+}
+
+
+MathArray::const_iterator MathArray::begin() const
+{
+ return bf_.begin();
+}
+
+
+MathArray::const_iterator MathArray::end() const
+{
+ return bf_.end();
+}
+
+
+MathArray::iterator MathArray::begin()
+{
+ return bf_.begin();
+}
+
+
+MathArray::iterator MathArray::end()
+{
+ return bf_.end();
+}
+
+
+bool MathArray::isMatrix() const
+{
+ return size() == 1 && begin()->nucleus() && begin()->nucleus()->isMatrix();
+}
+
+
--- /dev/null
+// -*- C++ -*-
+/*
+ * Purpose: A general purpose resizable array.
+ * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
+ * Created: January 1996
+ *
+ * Dependencies: None (almost)
+ *
+ * Copyright: 1996, Alejandro Aguilar Sierra
+ * 1997 The LyX Team!
+ *
+ * You are free to use and modify this code under the terms of
+ * the GNU General Public Licence version 2 or later.
+ */
+
+#ifndef MATHEDARRAY_H
+#define MATHEDARRAY_H
+
+#include <vector>
+
+#include "math_atom.h"
+#include "LString.h"
+
+class MathScriptInset;
+class MathMacro;
+class MathWriteInfo;
+class MathMetricsInfo;
+class LaTeXFeatures;
+class NormalStream;
+class MapleStream;
+class MathMLStream;
+class OctaveStream;
+
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+
+/** \class MathArray
+ \brief Low level container for math insets
+
+ \author Alejandro Aguilar Sierra
+ \author André Pönitz
+ \author Lars Gullik Bjønnes
+ \version February 2001
+ */
+
+class MathArray {
+public:
+ ///
+ typedef std::vector<MathAtom> buffer_type;
+ ///
+ typedef buffer_type::const_iterator const_iterator;
+ ///
+ typedef buffer_type::iterator iterator;
+ ///
+ typedef buffer_type::size_type size_type;
+
+public:
+ ///
+ MathArray();
+ ///
+ MathArray(MathArray const &, size_type from, size_type to);
+
+ ///
+ size_type size() const;
+ ///
+ bool empty() const;
+ ///
+ void clear();
+ ///
+ void swap(MathArray &);
+
+ ///
+ void insert(size_type pos, MathAtom const &);
+ ///
+ void insert(size_type pos, MathArray const &);
+
+ ///
+ void erase(size_type pos1, size_type pos2);
+ ///
+ void erase(size_type pos);
+ ///
+ void erase();
+
+ ///
+ void push_back(MathAtom const &);
+ ///
+ void push_back(MathArray const &);
+ ///
+ void pop_back();
+ ///
+ MathAtom & back();
+
+ ///
+ void dump() const;
+ ///
+ void dump2() const;
+ ///
+ void substitute(MathMacro const &);
+
+ ///
+ MathAtom & at(size_type pos);
+ ///
+ MathAtom const & at(size_type pos) const;
+ /// glue chars if necessary
+ void write(MathWriteInfo & os) const;
+ ///
+ void writeNormal(NormalStream &) const;
+ ///
+ void validate(LaTeXFeatures &) const;
+ ///
+ const_iterator begin() const;
+ ///
+ const_iterator end() const;
+ ///
+ iterator begin();
+ ///
+ iterator end();
+ ///
+ MathScriptInset const * asScript(const_iterator it) const;
+ /// glues chars with the same attributes into MathStringInsets
+ MathArray glueChars() const;
+ /// insert asterisks in "suitable" places
+ MathArray guessAsterisks() const;
+
+ /// interface to Octave
+ void octavize(OctaveStream &) const;
+ /// interface to Maple
+ void maplize(MapleStream &) const;
+ /// interface to MathML
+ void mathmlize(MathMLStream &) const;
+
+ ///
+ bool isMatrix() const;
+
+private:
+ /// Buffer
+ buffer_type bf_;
+};
+
+#endif
#pragma interface
#endif
-#include "xarray.h"
+#include "math_xdata.h"
#include "math_defs.h"
/** Abstract base class for all math objects.
#endif
#include "math_macro.h"
-#include "array.h"
#include "support/lstrings.h"
#include "support/LAssert.h"
#include "debug.h"
#endif
#include "math_parser.h"
-#include "array.h"
#include "math_inset.h"
#include "math_arrayinset.h"
#include "math_braceinset.h"
#include "math_specialcharinset.h"
#include "math_splitinset.h"
#include "math_sqrtinset.h"
-#include "debug.h"
#include "math_support.h"
#include "lyxlex.h"
+#include "debug.h"
#include "support/lstrings.h"
using std::istream;
--- /dev/null
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_inset.h"
+#include "math_scriptinset.h"
+#include "math_support.h"
+#include "math_defs.h"
+#include "Painter.h"
+#include "debug.h"
+
+
+MathXArray::MathXArray()
+ : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_()
+{}
+
+
+void MathXArray::metrics(MathMetricsInfo const & st) const
+{
+ size_ = st;
+ mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
+
+ if (data_.empty())
+ return;
+
+ math_font_max_dim(LM_TC_TEXTRM, st, ascent_, descent_);
+ width_ = 0;
+
+ //lyxerr << "MathXArray::metrics(): '" << data_ << "'\n";
+
+ for (const_iterator it = begin(); it != end(); ++it) {
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = data_.asScript(it)) {
+ q->metrics(p, st);
+ ascent_ = std::max(ascent_, q->ascent(p));
+ descent_ = std::max(descent_, q->descent(p));
+ width_ += q->width(p);
+ ++it;
+ } else {
+ 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) const
+{
+ xo_ = x;
+ yo_ = y;
+
+ if (data_.empty()) {
+ pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
+ return;
+ }
+
+ for (const_iterator it = begin(); it != end(); ++it) {
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = data_.asScript(it)) {
+ q->draw(p, pain, x, y);
+ x += q->width(p);
+ ++it;
+ } else {
+ p->draw(pain, x, y);
+ x += p->width();
+ }
+ }
+}
+
+
+int MathXArray::pos2x(size_type targetpos) const
+{
+ int x = 0;
+ const_iterator target = std::min(begin() + targetpos, end());
+ for (const_iterator it = begin(); it < target; ++it) {
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = data_.asScript(it)) {
+ ++it;
+ if (it < target)
+ x += q->width(p);
+ else // "half" position
+ x += q->dxx(p) + q->nwid(p);
+ } else
+ x += p->width();
+ }
+ return x;
+}
+
+
+MathArray::size_type MathXArray::x2pos(int targetx) const
+{
+ const_iterator it = begin();
+ int lastx = 0;
+ int currx = 0;
+ for ( ; currx < targetx && it < end(); ++it) {
+ lastx = currx;
+
+ int wid = 0;
+ MathInset const * p = it->nucleus();
+ if (MathScriptInset const * q = data_.asScript(it)) {
+ wid = q->width(p);
+ ++it;
+ } else
+ wid = p->width();
+
+ currx += wid;
+ }
+ if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
+ --it;
+ return it - begin();
+}
--- /dev/null
+// -*- C++ -*-
+
+#ifndef MATHEDXARRAY_H
+#define MATHEDXARRAY_H
+
+#include <iosfwd>
+
+#include "math_data.h"
+#include "math_metricsinfo.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+class Painter;
+
+class MathXArray
+{
+public:
+ ///
+ typedef MathArray::size_type size_type;
+ ///
+ typedef MathArray::const_iterator const_iterator;
+
+ ///
+ MathXArray();
+ ///
+ void metrics(MathMetricsInfo const & st) const;
+ ///
+ void draw(Painter & pain, int x, int y) const;
+
+ ///
+ int xo() const { return xo_; }
+ ///
+ int yo() const { return yo_; }
+ ///
+ int pos2x(size_type pos) const;
+ ///
+ size_type x2pos(int pos) const;
+
+ ///
+ int ascent() const { return ascent_; }
+ ///
+ int descent() const { return descent_; }
+ ///
+ int height() const { return ascent_ + descent_; }
+ ///
+ int width() const { return width_; }
+
+ ///
+ const_iterator begin() const { return data_.begin(); }
+ ///
+ const_iterator end() const { return data_.end(); }
+
+public:
+ ///
+ MathArray data_;
+ ///
+ mutable int width_;
+ ///
+ mutable int ascent_;
+ ///
+ mutable int descent_;
+ ///
+ mutable int xo_;
+ ///
+ mutable int yo_;
+ ///
+ mutable MathMetricsInfo size_;
+};
+
+std::ostream & operator<<(std::ostream & os, MathXArray const & ar);
+
+#endif
+++ /dev/null
-#include <config.h>
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "xarray.h"
-#include "math_inset.h"
-#include "math_scriptinset.h"
-#include "math_support.h"
-#include "math_defs.h"
-#include "Painter.h"
-#include "debug.h"
-
-
-MathXArray::MathXArray()
- : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_()
-{}
-
-
-void MathXArray::metrics(MathMetricsInfo const & st) const
-{
- size_ = st;
- mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
-
- if (data_.empty())
- return;
-
- math_font_max_dim(LM_TC_TEXTRM, st, ascent_, descent_);
- width_ = 0;
-
- //lyxerr << "MathXArray::metrics(): '" << data_ << "'\n";
-
- for (const_iterator it = begin(); it != end(); ++it) {
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = data_.asScript(it)) {
- q->metrics(p, st);
- ascent_ = std::max(ascent_, q->ascent(p));
- descent_ = std::max(descent_, q->descent(p));
- width_ += q->width(p);
- ++it;
- } else {
- 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) const
-{
- xo_ = x;
- yo_ = y;
-
- if (data_.empty()) {
- pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
- return;
- }
-
- for (const_iterator it = begin(); it != end(); ++it) {
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = data_.asScript(it)) {
- q->draw(p, pain, x, y);
- x += q->width(p);
- ++it;
- } else {
- p->draw(pain, x, y);
- x += p->width();
- }
- }
-}
-
-
-int MathXArray::pos2x(size_type targetpos) const
-{
- int x = 0;
- const_iterator target = std::min(begin() + targetpos, end());
- for (const_iterator it = begin(); it < target; ++it) {
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = data_.asScript(it)) {
- ++it;
- if (it < target)
- x += q->width(p);
- else // "half" position
- x += q->dxx(p) + q->nwid(p);
- } else
- x += p->width();
- }
- return x;
-}
-
-
-MathArray::size_type MathXArray::x2pos(int targetx) const
-{
- const_iterator it = begin();
- int lastx = 0;
- int currx = 0;
- for ( ; currx < targetx && it < end(); ++it) {
- lastx = currx;
-
- int wid = 0;
- MathInset const * p = it->nucleus();
- if (MathScriptInset const * q = data_.asScript(it)) {
- wid = q->width(p);
- ++it;
- } else
- wid = p->width();
-
- currx += wid;
- }
- if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
- --it;
- return it - begin();
-}
+++ /dev/null
-// -*- C++ -*-
-
-#ifndef MATHEDXARRAY_H
-#define MATHEDXARRAY_H
-
-#include <iosfwd>
-#include "array.h"
-#include "math_metricsinfo.h"
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-class Painter;
-
-class MathXArray
-{
-public:
- ///
- typedef MathArray::size_type size_type;
- ///
- typedef MathArray::const_iterator const_iterator;
-
- ///
- MathXArray();
- ///
- void metrics(MathMetricsInfo const & st) const;
- ///
- void draw(Painter & pain, int x, int y) const;
-
- ///
- int xo() const { return xo_; }
- ///
- int yo() const { return yo_; }
- ///
- int pos2x(size_type pos) const;
- ///
- size_type x2pos(int pos) const;
-
- ///
- int ascent() const { return ascent_; }
- ///
- int descent() const { return descent_; }
- ///
- int height() const { return ascent_ + descent_; }
- ///
- int width() const { return width_; }
-
- ///
- const_iterator begin() const { return data_.begin(); }
- ///
- const_iterator end() const { return data_.end(); }
-
-public:
- ///
- MathArray data_;
- ///
- mutable int width_;
- ///
- mutable int ascent_;
- ///
- mutable int descent_;
- ///
- mutable int xo_;
- ///
- mutable int yo_;
- ///
- mutable MathMetricsInfo size_;
-};
-
-std::ostream & operator<<(std::ostream & os, MathXArray const & ar);
-
-#endif