From: André Pönitz Date: Thu, 8 Nov 2001 12:55:58 +0000 (+0000) Subject: cosmetics: rename (x)array.[Ch] into math_(x)data.[Ch] X-Git-Tag: 1.6.10~20377 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f34e4919f71ca3af1a56b7b24134254481539249;p=features.git cosmetics: rename (x)array.[Ch] into math_(x)data.[Ch] git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2988 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index ee2683fc12..e3962acf03 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -8,10 +8,6 @@ BOOST_INCLUDES = -I$(top_srcdir)/boost INCLUDES = -I${srcdir}/../ $(SIGC_CFLAGS) $(BOOST_INCLUDES) libmathed_la_SOURCES = \ - array.C \ - array.h \ - xarray.C \ - xarray.h \ formulabase.C \ formulabase.h \ formula.C \ @@ -34,6 +30,8 @@ libmathed_la_SOURCES = \ math_charinset.h \ math_cursor.C \ math_cursor.h \ + math_data.C \ + math_data.h \ math_decorationinset.C \ math_decorationinset.h \ math_defs.h \ @@ -107,4 +105,6 @@ libmathed_la_SOURCES = \ math_support.C \ math_support.h \ math_symbolinset.C \ - math_symbolinset.h + math_symbolinset.h \ + math_xdata.C \ + math_xdata.h diff --git a/src/mathed/array.C b/src/mathed/array.C deleted file mode 100644 index 6fa0b879b6..0000000000 --- a/src/mathed/array.C +++ /dev/null @@ -1,337 +0,0 @@ -#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 << ""; - 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(); -} - - diff --git a/src/mathed/array.h b/src/mathed/array.h deleted file mode 100644 index 007d75850e..0000000000 --- a/src/mathed/array.h +++ /dev/null @@ -1,143 +0,0 @@ -// -*- C++ -*- -/* - * Purpose: A general purpose resizable array. - * Author: Alejandro Aguilar Sierra - * 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 - -#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 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 diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C new file mode 100644 index 0000000000..30821404d1 --- /dev/null +++ b/src/mathed/math_data.C @@ -0,0 +1,337 @@ +#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 << ""; + 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(); +} + + diff --git a/src/mathed/math_data.h b/src/mathed/math_data.h new file mode 100644 index 0000000000..007d75850e --- /dev/null +++ b/src/mathed/math_data.h @@ -0,0 +1,143 @@ +// -*- C++ -*- +/* + * Purpose: A general purpose resizable array. + * Author: Alejandro Aguilar Sierra + * 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 + +#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 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 diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 5d8098e8bd..a710af65d7 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -28,7 +28,7 @@ #pragma interface #endif -#include "xarray.h" +#include "math_xdata.h" #include "math_defs.h" /** Abstract base class for all math objects. diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 5bada3e06f..707548ec2d 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -19,7 +19,6 @@ #endif #include "math_macro.h" -#include "array.h" #include "support/lstrings.h" #include "support/LAssert.h" #include "debug.h" diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 4da7787d9c..5384cb5625 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -53,7 +53,6 @@ point to write some macros: #endif #include "math_parser.h" -#include "array.h" #include "math_inset.h" #include "math_arrayinset.h" #include "math_braceinset.h" @@ -72,9 +71,9 @@ point to write some macros: #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; diff --git a/src/mathed/math_xdata.C b/src/mathed/math_xdata.C new file mode 100644 index 0000000000..f0deef476e --- /dev/null +++ b/src/mathed/math_xdata.C @@ -0,0 +1,117 @@ +#include + +#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(); +} diff --git a/src/mathed/math_xdata.h b/src/mathed/math_xdata.h new file mode 100644 index 0000000000..d59caa04f4 --- /dev/null +++ b/src/mathed/math_xdata.h @@ -0,0 +1,74 @@ +// -*- C++ -*- + +#ifndef MATHEDXARRAY_H +#define MATHEDXARRAY_H + +#include + +#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 diff --git a/src/mathed/xarray.C b/src/mathed/xarray.C deleted file mode 100644 index 5e848f119d..0000000000 --- a/src/mathed/xarray.C +++ /dev/null @@ -1,118 +0,0 @@ -#include - -#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(); -} diff --git a/src/mathed/xarray.h b/src/mathed/xarray.h deleted file mode 100644 index b67d3b9681..0000000000 --- a/src/mathed/xarray.h +++ /dev/null @@ -1,73 +0,0 @@ -// -*- C++ -*- - -#ifndef MATHEDXARRAY_H -#define MATHEDXARRAY_H - -#include -#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