]> git.lyx.org Git - features.git/commitdiff
split super/subscript handling in new base class MathUpDownInset and
authorAndré Pönitz <poenitz@gmx.net>
Thu, 12 Jul 2001 07:18:29 +0000 (07:18 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 12 Jul 2001 07:18:29 +0000 (07:18 +0000)
MathScriptInset/MathBigOpInset

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2220 a592a061-630c-0410-9148-cb99ea01b6c8

49 files changed:
src/mathed/ChangeLog
src/mathed/Makefile.am
src/mathed/array.C
src/mathed/array.h
src/mathed/formulabase.C
src/mathed/math_accentinset.C
src/mathed/math_accentinset.h
src/mathed/math_bigopinset.C
src/mathed/math_bigopinset.h
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_decorationinset.C
src/mathed/math_decorationinset.h
src/mathed/math_deliminset.C
src/mathed/math_deliminset.h
src/mathed/math_dotsinset.C
src/mathed/math_dotsinset.h
src/mathed/math_fracinset.C
src/mathed/math_fracinset.h
src/mathed/math_funcinset.C
src/mathed/math_funcinset.h
src/mathed/math_grid.C
src/mathed/math_grid.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_macro.C
src/mathed/math_macro.h
src/mathed/math_macroarg.C
src/mathed/math_macroarg.h
src/mathed/math_macrotable.C
src/mathed/math_macrotemplate.C
src/mathed/math_macrotemplate.h
src/mathed/math_matrixinset.C
src/mathed/math_matrixinset.h
src/mathed/math_parser.C
src/mathed/math_root.C
src/mathed/math_root.h
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h
src/mathed/math_sizeinset.C
src/mathed/math_sizeinset.h
src/mathed/math_spaceinset.C
src/mathed/math_spaceinset.h
src/mathed/math_sqrtinset.C
src/mathed/math_sqrtinset.h
src/mathed/math_updowninset.C [new file with mode: 0644]
src/mathed/math_updowninset.h [new file with mode: 0644]
src/mathed/xarray.C
src/mathed/xarray.h

index 7cf5a8f7ba80f9d49544fe88e6fc79bfceb628e6..5e61a363b88c4d4d569050f22bd1c03e0b41a7e0 100644 (file)
@@ -1,4 +1,11 @@
 
+2001-07-12 André Pönitz  <poenitz@htwm.de>
+
+       * math_updowninset.[hC]: new base class for script and bigop insets
+               *.[hC]: subsequnet changes to all Metric() functions
+       
+       * math_parser.C: small changes (\sqrt0 is read properly now)
+       
 2001-07-10 André Pönitz  <poenitz@htwm.de>
        
        * math_accentinset.[hC]: rewrite
index 34af4fca287b9b12e7a46ad2a2f816bc9af9cd0b..2f8dc71aabfdff7bcecffc6a2b9dbbf61088b02b 100644 (file)
@@ -66,6 +66,8 @@ libmathed_la_SOURCES = \
        math_spaceinset.h \
        math_sqrtinset.C \
        math_sqrtinset.h \
+       math_updowninset.C \
+       math_updowninset.h \
        math_utils.C \
        math_utils.h \
        matriz.C \
index 76e078e7b38058d859336d773850f9ca7874877e..7141bb79dc7281d3529086f4617c64721fb8637e 100644 (file)
@@ -23,7 +23,7 @@ MathArray::~MathArray()
 {
        for (int pos = 0; pos < size(); next(pos)) 
                if (MathIsInset(pos)) 
-                       delete GetInset(pos);
+                       delete nextInset(pos);
 }
 
 
@@ -32,7 +32,7 @@ MathArray::MathArray(MathArray const & array)
 {
        for (int pos = 0; pos < size(); next(pos)) 
                if (isInset(pos)) 
-                       replace(pos, GetInset(pos)->clone());
+                       replace(pos, nextInset(pos)->clone());
 }
 
 
@@ -75,7 +75,7 @@ void MathArray::substitute(MathMacro const & m)
        MathArray tmp;
        for (int pos = 0; pos < size(); next(pos)) {
                if (isInset(pos)) 
-                       GetInset(pos)->substitute(tmp, m);
+                       nextInset(pos)->substitute(tmp, m);
                else 
                        tmp.push_back(GetChar(pos), GetCode(pos));
        }
@@ -91,7 +91,7 @@ MathArray & MathArray::operator=(MathArray const & array)
 }
 
 
-MathInset * MathArray::GetInset(int pos) const
+MathInset * MathArray::nextInset(int pos) const
 {
        if (!isInset(pos))
                return 0;
@@ -100,6 +100,14 @@ MathInset * MathArray::GetInset(int pos) const
        return p;
 }
 
+MathInset * MathArray::prevInset(int pos) const
+{
+       if (!pos)
+               return 0;
+       prev(pos);
+       return nextInset(pos);
+}
+
 byte MathArray::GetChar(int pos) const
 {
        return pos < size() ? bf_[pos + 1] : '\0';
@@ -157,7 +165,7 @@ void MathArray::insert(int pos, MathArray const & array)
        bf_.insert(bf_.begin() + pos, array.bf_.begin(), array.bf_.end());
        for (int p = pos; p < pos + array.size(); next(p)) 
                if (isInset(p)) 
-                       replace(p, GetInset(p)->clone());
+                       replace(p, nextInset(p)->clone());
 }
 
 
@@ -230,35 +238,12 @@ MathInset * MathArray::back_inset() const
                int pos = size();
                prev(pos);
                if (isInset(pos))
-                       return GetInset(pos);
+                       return nextInset(pos);
        }
        return 0;
 }
 
 
-MathScriptInset * MathArray::prevScriptInset(int pos) const
-{
-       if (!pos)
-               return 0;
-       prev(pos);
-
-       MathInset * inset = GetInset(pos);
-       if (inset && inset->isScriptInset()) 
-               return static_cast<MathScriptInset *>(inset);
-
-       return 0;
-}
-
-MathScriptInset * MathArray::nextScriptInset(int pos) const
-{
-       MathInset * inset = GetInset(pos);
-       if (inset && inset->isScriptInset()) 
-               return static_cast<MathScriptInset *>(inset);
-
-       return 0;
-}
-
-
 void MathArray::dump2(ostream & os) const
 {
        for (buffer_type::const_iterator it = bf_.begin(); it != bf_.end(); ++it)
@@ -272,7 +257,7 @@ void MathArray::dump(ostream & os) const
 {
        for (int pos = 0; pos < size(); next(pos)) {
                if (isInset(pos)) 
-                       os << "<inset: " << GetInset(pos) << ">";
+                       os << "<inset: " << nextInset(pos) << ">";
                else 
                        os << "<" << int(bf_[pos]) << " " << int(bf_[pos+1]) << ">";
        }
@@ -296,7 +281,7 @@ void MathArray::Write(ostream & os, bool fragile) const
        for (int pos = 0; pos < size(); next(pos)) {
                if (isInset(pos)) {
 
-                       GetInset(pos)->Write(os, fragile);
+                       nextInset(pos)->Write(os, fragile);
 
                } else {
 
index c5ec80b7870b1628bb57d45493c0a8e34a53a10d..4e8a351974a020de690a1d1f346a0711f7948f77 100644 (file)
@@ -24,7 +24,6 @@
 #include "LString.h"
 
 class MathInset;
-class MathScriptInset;
 class MathMacro;
 class Painter;
 
@@ -33,9 +32,7 @@ class Painter;
 #endif
 
 /** \class MathArray
-    \brief A resizable array.
-    
-    A general purpose resizable array.
+    \brief Low level container for math insets
     
     \author Alejandro Aguilar Sierra
     \author André Pönitz
@@ -101,11 +98,9 @@ public:
        ///
 
        ///
-       MathInset * GetInset(int pos) const;
-       ///
-       MathScriptInset * prevScriptInset(int pos) const;
+       MathInset * nextInset(int pos) const;
        ///
-       MathScriptInset * nextScriptInset(int pos) const;
+       MathInset * prevInset(int pos) const;
        ///
        byte GetChar(int pos) const;
        /// read subsequent chars of the same kind.
index b048f29c46db02b4a74f440326277d682dc46160..91e1fd6c2f7d0243af03218415ed20daec0f6405 100644 (file)
@@ -147,6 +147,7 @@ LyXFont WhichFont(short type, int size)
 
        case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
        case LM_TC_TEXTRM:
+       case LM_TC_TEX:
        case LM_TC_RM:
                f = Math_Fonts[6];
                break;
@@ -184,6 +185,9 @@ LyXFont WhichFont(short type, int size)
        if (type != LM_TC_TEXTRM)
                f.setColor(LColor::math);
 
+       if (type == LM_TC_TEX)
+               f.setColor(LColor::latex);
+
        return f;
 }
 
index 3bfb5ca2ffecd7271095a88daf143611b146712d..2c12be4ad877d25d98abaa7e996d85ae44f72897 100644 (file)
@@ -17,7 +17,7 @@ MathInset * MathAccentInset::clone() const
        return new MathAccentInset(*this);
 }
 
-void MathAccentInset::Metrics(MathStyles st)
+void MathAccentInset::Metrics(MathStyles st, int, int)
 {
        xcell(0).Metrics(st);
        ascent_  = xcell(0).ascent();
index e75f69fe0df44d45163b01b376532e2d0e3037f0..dc7a9f071725c9a9572b525c55300c1ce2985ab3 100644 (file)
@@ -20,7 +20,7 @@ public:
        ///
        void WriteNormal(std::ostream &) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        int getAccentCode() const;
        ///
index 588a4cde9f724fb8559f2ff51212bbc8486fea9c..2da8735809af8d1acd700adc75f0802e8358d70d 100644 (file)
@@ -1,17 +1,15 @@
 #include <config.h>
 
-#include <functional>
-
 #include "math_bigopinset.h"
-#include "LColor.h"
 #include "Painter.h"
 #include "mathed/support.h"
 #include "support/LOstream.h"
 
+
 using std::ostream;
 
 MathBigopInset::MathBigopInset(string const & name, int id)
-       : MathScriptInset(false, true), lims_(0), sym_(id)
+       : MathUpDownInset(false, false), sym_(id), limits_(0)
 {
        SetName(name);
 }
@@ -23,132 +21,116 @@ MathInset * MathBigopInset::clone() const
 }
 
 
+int MathBigopInset::limits() const 
+{
+       return limits_; 
+} 
+
+
+void MathBigopInset::limits(int limits) 
+{  
+       limits_ = limits;
+}
+
+
+bool MathBigopInset::hasLimits() const
+{
+       return limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY);
+}
+
 
 void MathBigopInset::Write(ostream & os, bool fragile) const
 {
        //bool f = sym_ != LM_int && sym_ != LM_oint && size() == LM_ST_DISPLAY;
        os << '\\' << name();
-       if (limits() == 1)
-               os << "\\limits ";
-       else if (limits() == -1)
-               os << "\\nolimits ";
-       else 
-               os << ' ';
-       MathScriptInset::Write(os, fragile);
+       MathUpDownInset::Write(os, fragile);
 }
 
 
 void MathBigopInset::WriteNormal(ostream & os) const
 {
-       os << "[bigop " << name();
-       if (limits() == 1)
-               os << "\\limits ";
-       else if (limits() == -1)
-               os << "\\nolimits ";
-       else 
-               os << ' ';
-       MathScriptInset::WriteNormal(os);
-       os << "] ";
+       os << "[bigop " << name() << "] ";
 }
 
-void MathBigopInset::Metrics(MathStyles st)
+
+void MathBigopInset::Metrics(MathStyles st, int, int)
 {
-       MathScriptInset::Metrics(st);
+       //cerr << "\nBigopDraw\n";
        size(st);
-       string s;
-       short t;
        
        if (sym_ < 256 || sym_ == LM_oint) {
-               char const c = (sym_ == LM_oint) ? LM_int : sym_;
-               s += c;
-               t = LM_TC_BSYM;
+               ssym_ = string();
+               ssym_ += (sym_ == LM_oint) ? LM_int : sym_;
+               code_ = LM_TC_BSYM;
        } else {
-               s = name();
-               t = LM_TC_TEXTRM;
+               ssym_ = name();
+               code_ = LM_TC_TEXTRM;
        }
 
-       int asc, des, wid;
-       mathed_string_dim(t, size(), s, asc, des, wid);
+       int wid;
+       mathed_string_dim(code_, size(), ssym_, ascent_, descent_, wid);
        if (sym_ == LM_oint)
                wid += 2;
+       //cerr << "  asc: " << ascent_ << " des: " << descent_
+       //      << " wid: " << wid << "\n";
+       //cerr << "  hasLimits: " << hasLimits() << " up: "
+       //      << up() << " down: " << down() << "\n";
+       
+       width_ = wid;
 
        if (hasLimits()) {
-               ascent_  = asc + xcell(0).height() + 2;
-               descent_ = des + xcell(1).height() + 2;
-               width_   = std::max(width_, wid);
+               xcell(0).Metrics(st);
+               xcell(1).Metrics(st);
+               //cerr << "  0: ascent_: " << xcell(0).ascent() << " descent_: " <<
+               //      xcell(0).descent() << " width_: " << xcell(0).width() << "\n";
+               //cerr << "  1: ascent_: " << xcell(1).ascent() << " descent_: " <<
+               //      xcell(1).descent() << " width_: " << xcell(1).width() << "\n";
+               if (up()) {
+                       ascent_  += xcell(0).height() + 1;
+                       width_   = std::max(width_, xcell(0).width());
+                       dy0_     = - (ascent_ - xcell(0).ascent());
+               }
+               if (down()) {
+                       descent_ += xcell(1).height() + 1;
+                       width_   = std::max(width_, xcell(1).width());
+                       dy1_     = descent_ - xcell(1).descent();
+               }
+               dxx_  = (width_ - wid) / 2;
+               dx0_  = (width_ - xcell(0).width()) / 2;
+               dx1_  = (width_ - xcell(1).width()) / 2;
+               //cerr << "  ascent_: " << ascent_ << " descent_: "
+               //      << descent_ << " width_: " << width_ << "\n";
+               //cerr << "  dx0_: " << dx0_ << " dx1_: " << dx1_
+               //      << " dxx_: " << dxx_ << "\n";
+               //cerr << "  dy0_: " << dy0_ << " dy1_: " << dy1_
+               //      << "\n";
        } else {
-               ascent_  = std::max(ascent_, asc);
-               descent_ = std::max(descent_, des);
-               width_  += wid;
+               MathUpDownInset::Metrics(st, ascent_, descent_);
+               width_   += wid;
+               dx0_     = wid;
+               dx1_     = wid;
+               dxx_     = 0;
        }
-
 }
 
 
 void MathBigopInset::draw(Painter & pain, int x, int y)
-{
+{  
        xo(x);
        yo(y);
 
-       string s;
-       short t;
-       
-       if (sym_ < 256 || sym_ == LM_oint) {
-               s += (sym_ == LM_oint) ? LM_int : sym_;
-               t = LM_TC_BSYM;
-       } else {
-               s = name();
-               t = LM_TC_TEXTRM;
-       }
-       if (sym_ == LM_oint) {
-               int wid;
-               int asc;
-               int des;
-               mathed_char_dim(t, size(), LM_int, asc, des, wid);
-               wid += 2;
-               pain.arc(x - 1, y - (asc - des) / 2, wid, wid, 0, 360 * 64, LColor::mathline);
-       }
+       pain.text(x + dxx_, y, ssym_, mathed_get_font(code_, size()));
 
-       int asc, des, wid;
-       mathed_string_dim(t, size(), s, asc, des, wid);
+       if (up())
+               xcell(0).draw(pain, x + dx0_, y + dy0_);
+       if (down())
+               xcell(1).draw(pain, x + dx1_, y + dy1_);
 
-       if (hasLimits()) {
-               int w = width();
-               pain.text(x + (w - wid)/2, y, s, mathed_get_font(t, size()));
-               xcell(0).draw
-                       (pain, x + (w - xcell(0).width())/2, y - asc - xcell(0).descent() - 1);
-               xcell(1).draw
-                       (pain, x + (w - xcell(1).width())/2, y + des + xcell(1).ascent()  + 1);
-       } else {
-               pain.text(x, y, s, mathed_get_font(t, size()));
-               MathScriptInset::draw(pain, x + wid, y);
+       if (sym_ == LM_oint) {
+               int xx = x - 1;
+               int yy = y - (ascent_ - descent_) / 2;
+               pain.arc(xx, yy, width_, width_, 0, 360 * 64, LColor::mathline);
        }
 }
 
 
-int MathBigopInset::limits() const 
-{
-       return lims_;   
-} 
-
-
-void MathBigopInset::limits(int limit) 
-{  
-       lims_ = limit;
-}
-
-bool MathBigopInset::hasLimits() const
-{
-       return limits() == 1 || (limits() == 0 && size() == LM_ST_DISPLAY);
-}
-
-
-void MathBigopInset::idxDelete(int & idx, bool & popit, bool & deleteit)
-{
-       if (idx == 0)
-               up(false);
-       else
-               down(false);
-       popit    = true;
-       deleteit = true;
-}
index e0409aeb5aa0bbdeb8da86851dad7a9bf74225f7..c347e35166941967b5167ab0b70a2348d8edca41 100644 (file)
@@ -2,35 +2,45 @@
 #ifndef MATH_BIGOPINSET_H
 #define MATH_BIGOPINSET_H
 
-#include "math_scriptinset.h"
+#include "math_updowninset.h"
 
 /// big operators
-class MathBigopInset : public MathScriptInset {
+class MathBigopInset : public MathUpDownInset {
 public:
        ///
        MathBigopInset(string const &, int);
        ///
        MathInset * clone() const;
        ///
-       void draw(Painter &, int, int);
-       ///
        void Write(std::ostream &, bool fragile) const;
        ///
        void WriteNormal(std::ostream &) const;
        ///
-       void Metrics(MathStyles st);
-       ///
-       int limits() const;
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
-       bool hasLimits() const;
+       void draw(Painter &, int, int);
        ///
        void limits(int);
        ///
-       void idxDelete(int & idx, bool & popit, bool & deleteit);
+       int limits() const;
+       /// Identifies BigopInsets
+       bool isBigopInset() const { return true; }
 private:
-       /// 1: \limits, -1: \nolimits, 0: use default
-       int lims_;
+       ///
+       bool hasLimits() const;
        ///
        int sym_;
+       ///
+       string ssym_;
+       ///
+       short code_;
+       /// 1: \limits, -1: \nolimits, 0: use default
+       int limits_;
+       /// x offset for drawing the superscript
+       int dx0_;
+       /// x offset for drawing the subscript
+       int dx1_;
+       /// x offset for drawing the inner symbol
+       int dxx_;
 };
 #endif
index 558f398accc397edd3e53067220dc1a7b4422807..02281183672bd73b22502f1764c2d8d63baa3361 100644 (file)
@@ -306,9 +306,9 @@ void MathCursor::SetPos(int x, int y)
                lyxerr << "found idx: " << idx_ << " cursor: " << cursor_  << "\n";
                MathInset * n = nextInset();
                MathInset * p = prevInset();
-               if (n && (n->isActive() || n->isScriptInset()) && n->covers(x, y))
+               if (n && (n->isActive() || n->isUpDownInset()) && n->covers(x, y))
                        push(n, true);
-               else if (p && (p->isActive() || p->isScriptInset()) && p->covers(x, y)) {
+               else if (p && (p->isActive() || p->isUpDownInset()) && p->covers(x, y)) {
                        array().prev(cursor_);
                        push(p, false);
                } else 
@@ -536,7 +536,7 @@ bool MathCursor::toggleLimits()
                return false;
        MathInset * p = prevInset();
        int old = p->limits();
-       p->limits(old == -1 ? 1 : -1);
+       p->limits(old < 0 ? 1 : -1);
        return old != p->limits();
 }
 
@@ -554,29 +554,27 @@ void MathCursor::Interpret(string const & s)
 in_word_set(s) << " \n";
 
        if (s[0] == '^') {
-               MathScriptInset * p = nearbyScriptInset();
+               MathUpDownInset * p = nearbyUpDownInset();
                if (!p) {
-                       p = new MathScriptInset;
+                       p = new MathScriptInset(true, false);
                        insert(p);
                        array().prev(cursor_);
                }
                push(p, true);
-               if (!p->up())
-                       p->up(true);
+               p->up(true);
                idx_ = 0;
                return;
        }
 
        if (s[0] == '_') {
-               MathScriptInset * p = nearbyScriptInset();
+               MathUpDownInset * p = nearbyUpDownInset();
                if (!p) {
-                       p = new MathScriptInset;
+                       p = new MathScriptInset(false, true);
                        insert(p);
                        array().prev(cursor_);
                }
                push(p, true);
-               if (!p->down())
-                       p->down(true);
+               p->down(true);
                idx_ = 1;
                return;
        }
@@ -1064,28 +1062,30 @@ MathInset * MathCursor::prevInset() const
        int c = cursor_;
        if (!array().prev(c))
                return 0;
-       return array().GetInset(c);
+       return array().nextInset(c);
 }
 
 
 MathInset * MathCursor::nextInset() const
 {
        normalize();
-       return array().GetInset(cursor_);
+       return array().nextInset(cursor_);
 }
 
 
-MathScriptInset * MathCursor::nearbyScriptInset() const
+MathUpDownInset * MathCursor::nearbyUpDownInset() const
 {
        normalize();
-       MathScriptInset * p = array().prevScriptInset(cursor_);
-       if (p)
-               return p;
-       return array().nextScriptInset(cursor_);
+       MathInset * p = array().prevInset(cursor_);
+       if (p && p->isUpDownInset())
+               return static_cast<MathUpDownInset *>(p);
+       p = array().nextInset(cursor_);
+       if (p && p->isUpDownInset())
+               return static_cast<MathUpDownInset *>(p);
+       return 0;
 }
 
 
-
 MathArray & MathCursor::array() const
 {
        static MathArray dummy;
index 3f316d96b72486b73af99883229c26ae0e101a9c..22779c881d8b9176854ed694f32c3d8ef021a340 100644 (file)
@@ -25,7 +25,7 @@
 
 class MathInset;
 class MathFuncInset;
-class MathScriptInset;
+class MathUpDownInset;
 class InsetFormulaBase;
 class MathArray;
 class MathXArray;
@@ -217,7 +217,7 @@ private:
        ///
        MathInset * prevInset() const;
        ///
-       MathScriptInset * nearbyScriptInset() const;
+       MathUpDownInset * nearbyUpDownInset() const;
 
        ///
        MathFuncInset * imacro;
index 1cef8d83c059324e92b90c89f5b982edc5e6a1fa..c76cd1d8fe3b6356df2c016221710d60e48e6448 100644 (file)
@@ -28,7 +28,7 @@ MathInset * MathDecorationInset::clone() const
 
 
 
-void MathDecorationInset::Metrics(MathStyles st)
+void MathDecorationInset::Metrics(MathStyles st, int, int)
 {
        xcell(0).Metrics(st);
        size_    = st;
index 34b5f47438799a1ce8bff69a5031e6beb55696d0..6f189c9ab473247de72eb5a494211064a25becc1 100644 (file)
@@ -22,7 +22,7 @@ public:
        ///
        void Write(std::ostream &, bool fragile) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
 private:
        ///
        int deco_;
index bea47553368dd309ea97e9aaf205fa6935b4cc4f..44a0a0c403b811b20f97b50862e5feaf579445ca 100644 (file)
@@ -89,7 +89,7 @@ int MathDelimInset::dw() const
 }
 
 
-void MathDelimInset::Metrics(MathStyles st)
+void MathDelimInset::Metrics(MathStyles st, int, int)
 {
        xcell(0).Metrics(st);
        size_    = st;
index 8ab72b17d145c2c78f53dbd6cbbad093cd6b91c5..cd25fe6f1b94e4d896ecca827d51bb68468352fa 100644 (file)
@@ -22,7 +22,7 @@ public:
        ///
        void Write(std::ostream &, bool fragile) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
 private:
        int dw() const;
        ///
index d173a3bb71e16ef4181f24f2452a97469e323901..e08ef4f789bb7c04c5269df661c4cbe33e8e2ab9 100644 (file)
@@ -33,7 +33,7 @@ void MathDotsInset::draw(Painter & pain, int x, int y)
 }
 
 
-void MathDotsInset::Metrics(MathStyles st)
+void MathDotsInset::Metrics(MathStyles st, int, int)
 {
        size(st);
        mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_);
index 7f1b29e276c8bebfb9ca40393c6210beb3691a75..d6d973a820a43861e23ddf7d387bd97bd4349cb0 100644 (file)
@@ -23,7 +23,7 @@ public:
        ///
        void WriteNormal(std::ostream &) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
 protected:
        ///
        int dh_;
index 6376eeab4d3d98d4d7d0b77b37b4d61850e50b9c..7e6a166d9d11744a5e74ed6875a181b08b756dbb 100644 (file)
@@ -24,7 +24,7 @@ MathInset * MathFracInset::clone() const
 }
 
 
-void MathFracInset::Metrics(MathStyles st)
+void MathFracInset::Metrics(MathStyles st, int, int)
 {
        size_    = smallerStyleFrac(st);
        xcell(0).Metrics(size_);
index 4a3e7ab8e841b24e51f9fd2d84c08ac7c4ad1a4f..10da11aae86e044150701de50ae86a8a893a9848 100644 (file)
@@ -22,7 +22,7 @@ public:
        ///
        virtual void WriteNormal(std::ostream &) const;
        ///
-       virtual void Metrics(MathStyles st);
+       virtual void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        virtual void draw(Painter &, int x, int baseline);
        ///
index 22ba8210899ba98db12e94fd3ead0089fecd9ccc..c2e7f61df3c2edf925512a3efa3da5a7a3f80b50 100644 (file)
@@ -55,7 +55,7 @@ void MathFuncInset::WriteNormal(std::ostream & os) const
 }
 
 
-void MathFuncInset::Metrics(MathStyles st) 
+void MathFuncInset::Metrics(MathStyles st, int, int
 {
        LyXFont font = WhichFont(LM_TC_TEXTRM, size());
 #ifndef NO_LATEX
index 5c7dcf0c1e817a625ec8919256548ec3c5daa810..9b386b274ddde6a2457a261eeaf9e2f393d2fd42 100644 (file)
@@ -25,7 +25,7 @@ public:
        ///
        void WriteNormal(std::ostream &) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
 private:
        ///
        bool lims_;
index d6dad817c7f46905eee1614ac0f59c632bad2506..28bb8208d2736ca71dc582b17ed06cf5af351175 100644 (file)
@@ -7,7 +7,6 @@
 #include "math_grid.h"
 #include "support/LOstream.h"
 #include "debug.h"
-#include "Painter.h"
 
 
 namespace {
@@ -77,7 +76,7 @@ char MathGridInset::valign() const
        return v_align_;
 }
 
-void MathGridInset::Metrics(MathStyles st)
+void MathGridInset::Metrics(MathStyles st, int, int)
 {
        // let the cells adjust themselves
        MathInset::Metrics(st);
index b3e14e36f42aadaa2424632c662f05e83eef5b9e..9948bdc300bf56cf7cdd8233a47e9010a7712383 100644 (file)
@@ -58,7 +58,7 @@ public:
        ///
        void Write(std::ostream &, bool fragile) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        void draw(Painter &, int, int);
        ///
index c17c9644f9a7b71bb6d10a12acfe14597b16dace..bc635a3a7b00917d3943e60c12dedaf916d87e4f 100644 (file)
@@ -70,12 +70,6 @@ void MathInset::limits(int)
 {
 }
 
-bool MathInset::hasLimits() const
-{
-       return false;
-}
-
-
 string const & MathInset::name() const
 {
        return name_;
@@ -172,12 +166,6 @@ MathArray const & MathInset::cell(int i) const
 }
 
 
-void MathInset::setData(MathArray const & a, int idx)
-{
-       cells_[idx].data_ = a;
-}
-
-
 void MathInset::substitute(MathArray & array, MathMacro const & m) const
 {
        MathInset * p = clone();
@@ -186,7 +174,7 @@ void MathInset::substitute(MathArray & array, MathMacro const & m) const
        array.push_back(p);
 }
 
-void MathInset::Metrics(MathStyles st)
+void MathInset::Metrics(MathStyles st, int, int)
 {
        size_ = st;
        for (int i = 0; i < nargs(); ++i)
@@ -373,4 +361,3 @@ bool MathInset::covers(int x, int y) const
                y >= yo_ - ascent_ &&
                y <= yo_ + descent_;
 }
-
index f8c6e4c117ce8ae64c957da2de9eda276a3d4804..a2c53cc5e598d6559ca8477f4279ea545d7daacb 100644 (file)
@@ -60,7 +60,7 @@ public:
        /// Appends itself with macro arguments substituted
        virtual void substitute(MathArray & array, MathMacro const & macro) const;
        /// Compute the size of the object
-       virtual void Metrics(MathStyles st) = 0;
+       virtual void Metrics(MathStyles st, int = 0, int = 0) = 0;
        /// 
        virtual int ascent() const;
        ///
@@ -70,8 +70,6 @@ public:
        ///
        virtual int height() const;
        ///
-       virtual bool hasLimits() const;
-       ///
        virtual int limits() const;
        ///
        virtual void limits(int);
@@ -136,8 +134,6 @@ public:
        MathXArray & xcell(int);
        ///
        MathXArray const & xcell(int) const;
-       ///
-       void setData(MathArray const &, int);
                        
        ///
        int xo() const;
@@ -174,9 +170,11 @@ public:
        ///
        bool covers(int x, int y) const;
        /// Identifies ScriptInsets
-       virtual bool isScriptInset() const { return false; }
+       virtual bool isUpDownInset() const { return false; }
        /// Identifies AccentInsets
        virtual bool isAccentInset() const { return false; }
+       /// Identifies BigopInsets
+       virtual bool isBigopInset() const { return false; }
        ///
        virtual bool isActive() const { return nargs() > 0; }
 
index fae542145cdbb9bec142edc2d02912d6046bb422..988809f25f6a5fbc4b12072fa4bf833847b76482 100644 (file)
@@ -44,7 +44,7 @@ MathInset * MathMacro::clone() const
 }
 
 
-void MathMacro::Metrics(MathStyles st)
+void MathMacro::Metrics(MathStyles st, int, int)
 {
        if (mathcursor && mathcursor->isInside(this)) {
                expanded_ = tmplate_->xcell(0);
index 094efe14f9ee8a459c2b10e979000e87450daef9..1e82f961254710e0e91e4116d12a590c2597eb16 100644 (file)
@@ -41,7 +41,7 @@ public:
        ///
        void draw(Painter &, int, int);
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        MathInset * clone() const;
        ///
index beb04af035439803ff27e4f00d8c56f1ce62ba41..553aaef9f59405d79edb8ec1fd1086c57f56f39b 100644 (file)
@@ -38,7 +38,7 @@ void MathMacroArgument::draw(Painter & pain, int x, int y)
 }
 
 
-void MathMacroArgument::Metrics(MathStyles st)
+void MathMacroArgument::Metrics(MathStyles st, int, int)
 {
        char str[] = "#0";
        str[1] += number_; 
index 594b7100e4ef3b70d3f79e26c89896794b832816..f089bf3c9e2da5ea2e6a4c4a453269e2cb0573aa 100644 (file)
@@ -18,7 +18,7 @@ public:
        ///
        MathInset * clone() const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        void draw(Painter &, int x, int baseline);
        ///
index 4f3368fa07fdf23a658a86c3932a4da122f9b7ec..9f384dff823ded0079ff29b0a77fc79498a5f5d1 100644 (file)
@@ -114,7 +114,7 @@ void MathMacroTable::builtinMacros()
        {
                MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
                MathAccentInset * p = new MathAccentInset(LM_not);
-               p->cell(0).push_back('0', LM_TC_VAR);
+               p->cell(0).push_back('O', LM_TC_VAR);
                t->push_back(p);
                insertTemplate(t);
        }
index 5277073473168a29dde36a29b321ee3714580363..e3846aa0ca08d304328d193c67191a1a743000e3 100644 (file)
@@ -51,7 +51,7 @@ void MathMacroTemplate::Write(std::ostream & os, bool fragile) const
 }
 
 
-void MathMacroTemplate::Metrics(MathStyles st)
+void MathMacroTemplate::Metrics(MathStyles st, int, int)
 {
        xcell(0).Metrics(st);
        size_    = st;
index 8f8d709c42f5d728e15c809e8237df4c198fb62b..324af9b11392ac3c6c6c11ef8ef45bc16c587008 100644 (file)
@@ -34,7 +34,7 @@ public:
        ///
        void draw(Painter &, int, int);
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
 private:
        ///
        int numargs_;
index d2c4629f7bf8f44979a146a94cdf1c0f2878f774..231415091596ef13de183b180f0385fe3939eece 100644 (file)
@@ -97,7 +97,7 @@ MathInset * MathMatrixInset::clone() const
 }
 
 
-void MathMatrixInset::Metrics(MathStyles /* st */)
+void MathMatrixInset::Metrics(MathStyles /* st */, int, int)
 {
        size_ = (GetType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
 
@@ -245,7 +245,7 @@ void MathMatrixInset::Validate1(LaTeXFeatures & features)
        MathIter it(cell());
 
        while (it.OK() && !(features.binom && features.boldsymbol)) {
-               MathInset * p = it.GetInset();
+               MathInset * p = it.nextInset();
                if (p) {
                        p = it.GetActiveInset();
                        if (p) {
index 4795d07716186267e5563474d0a068eb8e0281c2..379555763f4904ab397acc1caa59ac7076bdfbb4 100644 (file)
@@ -29,7 +29,7 @@ public:
        ///
        void Write(std::ostream &, bool fragile) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        void draw(Painter &, int, int);
        ///
index a00cbb681bb6980e97806f2fa68380261614fc89..ab8f50af33976cca095e43a57d133737ddcb15dd 100644 (file)
@@ -15,6 +15,8 @@
  *   the GNU General Public Licence version 2 or later.
  */
 
+// {[(
+
 #include <config.h>
 
 #include <cctype>
@@ -38,6 +40,7 @@
 #include "math_funcinset.h"
 #include "math_spaceinset.h"
 #include "math_sizeinset.h"
+#include "math_scriptinset.h"
 #include "math_dotsinset.h"
 #include "math_fracinset.h"
 #include "math_deliminset.h"
@@ -75,12 +78,10 @@ lexcode_enum lexcode[256];
 char const * latex_special_chars = "#$%&_{}";
 
 
-/// Read TeX into data, flags give stop conditions
-void mathed_parse(MathArray & data, unsigned flags);
-
-
 namespace {
 
+void mathed_parse(MathArray & array, unsigned flags);
+
 unsigned char getuchar(std::istream * is)
 {
        char c;
@@ -93,17 +94,22 @@ const unsigned char LM_TK_CLOSE = '}';
 
 enum {
        FLAG_BRACE      = 1 << 0,  //  A { needed              //}
-       FLAG_BRACE_OPT  = 1 << 2,  //  Optional {              
-       FLAG_BRACE_LAST = 1 << 3,  //  Last } ends the parsing process
-       FLAG_BRACK_ARG  = 1 << 4,  //  Optional [     
+       FLAG_BRACE_OPT  = 1 << 2,  //  Optional {              //}
+       FLAG_BRACE_LAST = 1 << 3,  //  // { Last } ends the parsing process
+       FLAG_BRACK_ARG  = 1 << 4,  //  Optional [              //]
        FLAG_RIGHT      = 1 << 5,  //  Next right ends the parsing process
        FLAG_END        = 1 << 6,  //  Next end ends the parsing process
-       FLAG_BRACE_FONT = 1 << 7,  //  Next } closes a font
-       FLAG_BRACK_END  = 1 << 9,  //  Next ] ends the parsing process
+       FLAG_BRACE_FONT = 1 << 7,  //  // { Next } closes a font
+       FLAG_BRACK_END  = 1 << 9,  //  // [ Next ] ends the parsing process
        FLAG_AMPERSAND  = 1 << 10, //  Next & ends the parsing process
-       FLAG_NEWLINE    = 1 << 11  //  Next \\ ends the parsing process
+       FLAG_NEWLINE    = 1 << 11, //  Next \\ ends the parsing process
+
+       //  Read a (possibly braced token)
+       FLAG_ITEM       = FLAG_BRACE_OPT | FLAG_BRACE_LAST
 };
 
+}
+
 
 ///
 union {
@@ -114,6 +120,7 @@ union {
 } yylval;
 
 
+
 string yytext;
 int yylineno;
 istream * yyis;
@@ -302,9 +309,9 @@ int yylex()
                                yylval.i = (i < 4) ? i : 0; 
                                return LM_TK_SPACE; 
                        }
-                       if (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
+                       if (lexcode[c] == LexAlpha) {
                                yytext.erase();
-                               while (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
+                               while (lexcode[c] == LexAlpha) {
                                        yytext += c;
                                        c = getuchar(yyis);
                                }
@@ -333,25 +340,26 @@ int yylex()
 }
 
 
-void handle_frac(MathArray & dat, string const & name)
-{
-       MathFracInset * p = new MathFracInset(name);
-       mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
-       mathed_parse(p->cell(1), FLAG_BRACE | FLAG_BRACE_LAST);
-       dat.push_back(p);
-}
-
-
-MathScriptInset * lastScriptInset(MathArray & array)
+MathInset * lastUpDownInset(MathArray & array, bool up, bool down)
 {
        MathInset * p = array.back_inset();
-       if (!p || !p->isScriptInset()) {
-               p = new MathScriptInset;
+       if (!p || !p->isUpDownInset()) {
+               p = new MathScriptInset(up, down);
                array.push_back(p);
        }
-       return static_cast<MathScriptInset *>(p);
+       MathUpDownInset * q = static_cast<MathScriptInset *>(p);
+       if (up)
+               q->up(true);
+       if (down)
+               q->down(down);
+       return p;
 }
 
+
+MathBigopInset * lastBigopInset(MathArray & array)
+{
+       MathInset * p = array.back_inset();
+       return (p && p->isBigopInset()) ? static_cast<MathBigopInset *>(p) : 0;
 }
 
 
@@ -480,10 +488,21 @@ MathInset * mathed_parse()
 }
 
 
+
+namespace {
+
+void handle_frac(MathArray & array, string const & name)
+{
+       MathFracInset * p = new MathFracInset(name);
+       mathed_parse(p->cell(0), FLAG_ITEM);
+       mathed_parse(p->cell(1), FLAG_ITEM);
+       array.push_back(p);
+}
+
+
 void mathed_parse(MathArray & array, unsigned flags)
 {
        int  t = yylex();
-       int  tprev = 0;
        bool panic = false;
        static int plevel = -1;
        yyvarcode = LM_TC_VAR;
@@ -577,28 +596,16 @@ void mathed_parse(MathArray & array, unsigned flags)
                        break;
                
                case '^':
-               {
-                       MathArray ar;
-                       mathed_parse(ar, FLAG_BRACE_OPT | FLAG_BRACE_LAST);
-                       MathScriptInset * p = lastScriptInset(array);
-                       p->setData(ar, 0);
-                       p->up(true);
+                       mathed_parse(lastUpDownInset(array, true, false)->cell(0), FLAG_ITEM);
                        break;
-               }
                
                case '_':
-               {
-                       MathArray ar;
-                       mathed_parse(ar, FLAG_BRACE_OPT | FLAG_BRACE_LAST);
-                       MathScriptInset * p = lastScriptInset(array);
-                       p->setData(ar, 1);
-                       p->down(true);
+                       mathed_parse(lastUpDownInset(array, false, true)->cell(1), FLAG_ITEM);
                        break;
-               }
                
                case LM_TK_LIMIT:
                {
-                       MathScriptInset * p = lastScriptInset(array);
+                       MathBigopInset * p = lastBigopInset(array);
                        if (p) 
                                p->limits(yylval.l->id ? 1 : -1);
                        break;
@@ -669,15 +676,13 @@ void mathed_parse(MathArray & array, unsigned flags)
                {           
                        unsigned char c = getuchar(yyis);
                        if (c == '[') {
-                               MathRootInset * rt = new MathRootInset;
-                               mathed_parse(rt->cell(0), FLAG_BRACK_END);
-                               mathed_parse(rt->cell(1), FLAG_BRACE | FLAG_BRACE_LAST);
-                               array.push_back(rt);
+                               array.push_back(new MathRootInset);
+                               mathed_parse(array.back_inset()->cell(0), FLAG_BRACK_END);
+                               mathed_parse(array.back_inset()->cell(1), FLAG_ITEM);
                        } else {
                                yyis->putback(c);
-                               MathSqrtInset * sq = new MathSqrtInset;
-                               mathed_parse(sq->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
-                               array.push_back(sq);
+                               array.push_back(new MathSqrtInset);
+                               mathed_parse(array.back_inset()->cell(0), FLAG_ITEM);
                        }
                        break;
                }
@@ -700,7 +705,7 @@ void mathed_parse(MathArray & array, unsigned flags)
                                rd = yylval.i;   
 
                        MathDelimInset * dl = new MathDelimInset(ld, rd);
-                       dl->setData(ar, 0);
+                       dl->cell(0) = ar;
                        array.push_back(dl);
                        break;
                }
@@ -766,7 +771,7 @@ void mathed_parse(MathArray & array, unsigned flags)
                        if (MathMacroTable::hasTemplate(yytext)) {
                                MathMacro * m = MathMacroTable::cloneTemplate(yytext);
                                for (int i = 0; i < m->nargs(); ++i) 
-                                       mathed_parse(m->cell(i), FLAG_BRACE_OPT | FLAG_BRACE_LAST);
+                                       mathed_parse(m->cell(i), FLAG_ITEM);
                                array.push_back(m);
                                m->Metrics(LM_ST_TEXT);
                        } else
@@ -831,7 +836,6 @@ void mathed_parse(MathArray & array, unsigned flags)
 
                } // end of big switch
                
-               tprev = t;
                if (panic) {
                        lyxerr << " Math Panic, expect problems!" << endl;
                        //   Search for the end command. 
@@ -849,6 +853,8 @@ void mathed_parse(MathArray & array, unsigned flags)
        --plevel;
 }
 
+}
+
 
 MathInset * mathed_parse(istream & is)
 {
@@ -879,3 +885,5 @@ MathInset * mathed_parse(LyXLex & lex)
 
        return p;
 }
+
+//]})
index da68d2536efe28d15c2845bc6a2ab1c5189837bc..19e3cbd442ba502b8707a30857482f5107b1b61d 100644 (file)
@@ -34,7 +34,7 @@ MathInset * MathRootInset::clone() const
 }
 
 
-void MathRootInset::Metrics(MathStyles st)
+void MathRootInset::Metrics(MathStyles st, int, int)
 {
        MathInset::Metrics(st);
        size_    = st;
index 1b1fb2e360b2ea048ba80b0f6f7a911fc5800383..cae5cfb93ac622136cf2a8ead6e0b4c7cc3cdf82 100644 (file)
@@ -39,7 +39,7 @@ public:
        ///
        void WriteNormal(std::ostream &) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        bool idxUp(int & idx, int & pos) const;
        ///
index be9972a0061ebf3a09931099f7d869939f1c98f0..3cf77fbcd647904c2b1130175ec05691e1a29b03 100644 (file)
@@ -4,22 +4,12 @@
 #pragma implementation
 #endif
 
-#include <functional>
-
 #include "math_scriptinset.h"
-#include "LColor.h"
-#include "Painter.h"
-#include "debug.h"
-#include "mathed/support.h"
 #include "support/LOstream.h"
 
 
-MathScriptInset::MathScriptInset()
-       : MathInset(2), up_(false), down_(false)
-{}
-
 MathScriptInset::MathScriptInset(bool up, bool down)
-       : MathInset(2), up_(up), down_(down)
+       : MathUpDownInset(up, down)
 {}
 
 
@@ -29,67 +19,6 @@ MathInset * MathScriptInset::clone() const
 }
 
 
-void MathScriptInset::Metrics(MathStyles st)
-{
-       size_ = smallerStyleScript(st);
-       xcell(0).Metrics(size_);
-       xcell(1).Metrics(size_);
-
-       width_   = std::max(xcell(0).width(), xcell(1).width()) + 2; 
-       if (up())
-               ascent_  = std::max(ascent_, xcell(0).height() + 9);
-       if (down())
-               descent_ = std::max(descent_, xcell(1).height());
-}
-
-
-bool MathScriptInset::up() const
-{
-       return up_;
-}
-
-bool MathScriptInset::down() const
-{
-       return down_;
-}
-
-void MathScriptInset::up(bool b)
-{
-       up_ = b;
-}
-
-void MathScriptInset::down(bool b)
-{
-       down_ = b;
-}
-
-
-void MathScriptInset::draw(Painter & pain, int x, int y)
-{ 
-       xo(x);
-       yo(y);
-       if (up())
-               xcell(0).draw(pain, x, y - xcell(0).descent() - 9);
-       if (down())
-               xcell(1).draw(pain, x, y + xcell(1).ascent());
-}
-
-
-void MathScriptInset::Write(std::ostream & os, bool fragile) const
-{
-       if (up()) {
-               os << "^{";
-               cell(0).Write(os, fragile);
-               os << "}";
-       }
-       if (down()) {
-               os << "_{";
-               cell(1).Write(os, fragile);
-               os << "}";
-       }
-}
-
-
 void MathScriptInset::WriteNormal(std::ostream & os) const
 {
        if (up()) {
@@ -104,86 +33,6 @@ void MathScriptInset::WriteNormal(std::ostream & os) const
        }
 }
 
-bool MathScriptInset::idxRight(int &, int &) const
-{
-       return false;
-}
-
-bool MathScriptInset::idxLeft(int &, int &) const
-{
-       return false;
-}
-
-
-bool MathScriptInset::idxUp(int & idx, int & pos) const
-{
-       if (idx == 0 || !up()) 
-               return false;
-       idx = 0;
-       pos = 0;
-       return true;
-}
-
-bool MathScriptInset::idxDown(int & idx, int & pos) const
-{
-       if (idx == 1 || !down()) 
-               return false;
-       idx = 1;
-       pos = 0;
-       return true;
-}
-
-bool MathScriptInset::idxFirst(int & idx, int & pos) const
-{
-       idx = up() ? 0 : 1;
-       pos = 0;
-       return true;
-}
-
-bool MathScriptInset::idxLast(int & idx, int & pos) const
-{
-       idx = down() ? 1 : 0;
-       pos = cell(idx).size();
-       return true;
-}
-
-
-bool MathScriptInset::idxFirstUp(int & idx, int & pos) const
-{
-       if (!up()) 
-               return false;
-       idx = 0;
-       pos = 0;
-       return true;
-}
-
-bool MathScriptInset::idxFirstDown(int & idx, int & pos) const
-{
-       if (!down()) 
-               return false;
-       idx = 1;
-       pos = 0;
-       return true;
-}
-
-bool MathScriptInset::idxLastUp(int & idx, int & pos) const
-{
-       if (!up()) 
-               return false;
-       idx = 0;
-       pos = cell(idx).size();
-       return true;
-}
-
-bool MathScriptInset::idxLastDown(int & idx, int & pos) const
-{
-       if (!down()) 
-               return false;
-       idx = 1;
-       pos = cell(idx).size();
-       return true;
-}
-
 
 void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
 {
index 2fa10b6e0140a621339daa32f58124fd26d23b49..7f589e953b67d38ed5b4f140aa41bcee872cf915 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_SCRIPTINSET_H
 #define MATH_SCRIPTINSET_H
 
-#include "math_inset.h"
+#include "math_updowninset.h"
 
 #ifdef __GNUG__
 #pragma interface
     \author André Pönitz
  */
 
-class MathScriptInset : public MathInset {
+class MathScriptInset : public MathUpDownInset {
 public:
-       ///
-       MathScriptInset();
        ///
        MathScriptInset(bool up, bool down);
        ///
        MathInset * clone() const;
        ///
-       void Write(std::ostream &, bool fragile) const;
-       ///
        void WriteNormal(std::ostream &) const;
-       ///
-       void Metrics(MathStyles st);
-       ///
-       void draw(Painter &, int x, int baseline);
-       ///
-       bool idxUp(int & idx, int & pos) const;
-       ///
-       bool idxDown(int & idx, int & pos) const;
-       ///
-       bool idxLeft(int & idx, int & pos) const;
-       ///
-       bool idxRight(int & idx, int & pos) const;
-       ///
-       bool idxFirst(int & idx, int & pos) const;
-       ///
-       bool idxFirstUp(int & idx, int & pos) const;
-       ///
-       bool idxFirstDown(int & idx, int & pos) const;
-       ///
-       bool idxLast(int & idx, int & pos) const;
-       ///
-       bool idxLastUp(int & idx, int & pos) const;
-       ///
-       bool idxLastDown(int & idx, int & pos) const;
-       ///
-       bool up() const;
-       ///
-       bool down() const;
-       ///
-       void up(bool);
-       ///
-       void down(bool);
-       ///
-       bool isActive() const { return false; }
        /// Identifies ScriptInsets
-       bool isScriptInset() const { return true; }
+       bool isUpDownInset() const { return true; }
        ///
        void idxDelete(int & idx, bool & popit, bool & deleteit);
-private:
-       ///
-       bool up_;
-       ///
-       bool down_;
 };
 
 #endif
index 707248a13178585148b4d0d83ddd470bcdf24b73..f6dc71f82cfed4a74bed03fc98f5920a600b7455 100644 (file)
@@ -45,7 +45,7 @@ void MathSizeInset::draw(Painter & pain, int x, int y)
 }
 
 
-void MathSizeInset::Metrics(MathStyles /* st */)
+void MathSizeInset::Metrics(MathStyles /* st */, int, int)
 {
        xcell(0).Metrics(style_);
        ascent_   = xcell(0).ascent_;
index 98d209e5e161f4d347582d8f803d4122df900be3..d581be7320276db1adbc6a9b1c20f1393a68914e 100644 (file)
@@ -20,7 +20,7 @@ public:
        ///
        virtual MathInset * clone() const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        void draw(Painter &, int x, int baseline);
        ///
index 85cb73146010f5291efd83fd285f5ca4a36fe180..8c6d91369c26ae96b5be6ad51d19a330d5cb6dd7 100644 (file)
@@ -55,7 +55,7 @@ void MathSpaceInset::WriteNormal(std::ostream & os) const
 }
 
 
-void MathSpaceInset::Metrics(MathStyles st)
+void MathSpaceInset::Metrics(MathStyles st, int, int)
 {
        size_ = st;
        width_ = space_ ? space_ * 2 : 2;
index 9983f4945b7a79d1f312ec884346c5f4b22cd33c..620f4d2bdd4ae1c83e8c11f8331890bafde0e8ec 100644 (file)
@@ -23,7 +23,7 @@ public:
        ///
        void WriteNormal(std::ostream &) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        void SetSpace(int sp);
        ///
index b201df05457e58715d5c6bb5c50db7a7c8b63544..e802a4e0c7facb2a3b21748e822047f3f639bd3b 100644 (file)
@@ -22,7 +22,7 @@ MathInset * MathSqrtInset::clone() const
 }
 
 
-void MathSqrtInset::Metrics(MathStyles st)
+void MathSqrtInset::Metrics(MathStyles st, int, int)
 {
        xcell(0).Metrics(st);
        size_    = st;
@@ -51,7 +51,7 @@ void MathSqrtInset::draw(Painter & pain, int x, int y)
 
 void MathSqrtInset::Write(std::ostream & os, bool fragile) const
 {
-       os << '\\' << name_ << '{';
+       os << "\\sqrt{";
        cell(0).Write(os, fragile); 
        os << '}';
 }
index 18019df49def899c25f0d99e49e0fbd113d7b2a7..e3e153de39c82e81a702e2e8e73ab5e81c85699f 100644 (file)
@@ -24,6 +24,6 @@ public:
        ///
        void WriteNormal(std::ostream &) const;
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
 };
 #endif
diff --git a/src/mathed/math_updowninset.C b/src/mathed/math_updowninset.C
new file mode 100644 (file)
index 0000000..57c2ba9
--- /dev/null
@@ -0,0 +1,178 @@
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_updowninset.h"
+#include "support/LOstream.h"
+
+
+MathUpDownInset::MathUpDownInset()
+       : MathInset(2), up_(false), down_(false)
+{}
+
+MathUpDownInset::MathUpDownInset(bool up, bool down)
+       : MathInset(2), up_(up), down_(down)
+{}
+
+
+MathInset * MathUpDownInset::clone() const
+{   
+       return new MathUpDownInset(*this);
+}
+
+
+bool MathUpDownInset::up() const
+{
+       return up_;
+}
+
+bool MathUpDownInset::down() const
+{
+       return down_;
+}
+
+void MathUpDownInset::up(bool b)
+{
+       up_ = b;
+}
+
+void MathUpDownInset::down(bool b)
+{
+       down_ = b;
+}
+
+
+bool MathUpDownInset::idxRight(int &, int &) const
+{
+       return false;
+}
+
+bool MathUpDownInset::idxLeft(int &, int &) const
+{
+       return false;
+}
+
+
+bool MathUpDownInset::idxUp(int & idx, int & pos) const
+{
+       if (idx == 0 || !up()) 
+               return false;
+       idx = 0;
+       pos = 0;
+       return true;
+}
+
+bool MathUpDownInset::idxDown(int & idx, int & pos) const
+{
+       if (idx == 1 || !down()) 
+               return false;
+       idx = 1;
+       pos = 0;
+       return true;
+}
+
+bool MathUpDownInset::idxFirst(int & idx, int & pos) const
+{
+       idx = up() ? 0 : 1;
+       pos = 0;
+       return true;
+}
+
+bool MathUpDownInset::idxLast(int & idx, int & pos) const
+{
+       idx = down() ? 1 : 0;
+       pos = cell(idx).size();
+       return true;
+}
+
+
+bool MathUpDownInset::idxFirstUp(int & idx, int & pos) const
+{
+       if (!up()) 
+               return false;
+       idx = 0;
+       pos = 0;
+       return true;
+}
+
+bool MathUpDownInset::idxFirstDown(int & idx, int & pos) const
+{
+       if (!down()) 
+               return false;
+       idx = 1;
+       pos = 0;
+       return true;
+}
+
+bool MathUpDownInset::idxLastUp(int & idx, int & pos) const
+{
+       if (!up()) 
+               return false;
+       idx = 0;
+       pos = cell(idx).size();
+       return true;
+}
+
+bool MathUpDownInset::idxLastDown(int & idx, int & pos) const
+{
+       if (!down()) 
+               return false;
+       idx = 1;
+       pos = cell(idx).size();
+       return true;
+}
+
+
+void MathUpDownInset::idxDelete(int & idx, bool & popit, bool & deleteit)
+{
+       if (idx == 0) 
+               up(false);
+       else
+               down(false);
+       popit = true;
+       deleteit = !(up() || down());
+}
+
+void MathUpDownInset::Write(std::ostream & os, bool fragile) const
+{
+       if (up()) {
+               os << "^{";
+               cell(0).Write(os, fragile);
+               os << "}";
+       }
+       if (down()) {
+               os << "_{";
+               cell(1).Write(os, fragile);
+               os << "}";
+       }
+}
+
+void MathUpDownInset::Metrics(MathStyles st, int asc, int des)
+{
+       if (up())
+               xcell(0).Metrics(st);
+       if (down())
+               xcell(1).Metrics(st);
+
+       // we assume that asc, des, wid are the metrics of the item in front
+       // of this MathScriptInset
+       width_   = std::max(xcell(0).width(), xcell(1).width());
+       ascent_  = up()   ? xcell(0).height() + 9 : 0;
+       descent_ = down() ? xcell(1).height() : 0;
+       dy0_     = - asc  - xcell(0).descent();
+       dy1_     =   des + xcell(1).ascent();
+}
+
+
+void MathUpDownInset::draw(Painter & pain, int x, int y)
+{ 
+       xo(x);
+       yo(y);
+       if (up())
+               xcell(0).draw(pain, x, y + dy0_);
+       if (down())
+               xcell(1).draw(pain, x, y + dy1_);
+}
+
diff --git a/src/mathed/math_updowninset.h b/src/mathed/math_updowninset.h
new file mode 100644 (file)
index 0000000..325f068
--- /dev/null
@@ -0,0 +1,75 @@
+// -*- C++ -*-
+#ifndef MATH_UPDOWNINSET_H
+#define MATH_UPDOWNINSET_H
+
+#include "math_inset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** Abstract base class for super- and subscripts and mathop inset
+    \author André Pönitz
+ */
+
+class MathUpDownInset : public MathInset {
+public:
+       ///
+       MathUpDownInset();
+       ///
+       MathUpDownInset(bool up, bool down);
+       ///
+       MathInset * clone() const;
+       ///
+       void Write(std::ostream &, bool fragile) const;
+       ///
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
+       ///
+       void draw(Painter &, int x, int baseline);
+       ///
+       bool idxUp(int & idx, int & pos) const;
+       ///
+       bool idxDown(int & idx, int & pos) const;
+       ///
+       bool idxLeft(int & idx, int & pos) const;
+       ///
+       bool idxRight(int & idx, int & pos) const;
+       ///
+       bool idxFirst(int & idx, int & pos) const;
+       ///
+       bool idxFirstUp(int & idx, int & pos) const;
+       ///
+       bool idxFirstDown(int & idx, int & pos) const;
+       ///
+       bool idxLast(int & idx, int & pos) const;
+       ///
+       bool idxLastUp(int & idx, int & pos) const;
+       ///
+       bool idxLastDown(int & idx, int & pos) const;
+       ///
+       bool up() const;
+       ///
+       bool down() const;
+       ///
+       void up(bool);
+       ///
+       void down(bool);
+       ///
+       bool isActive() const { return false; }
+       /// Identifies ScriptInsets
+       bool isUpDownInset() const { return true; }
+       ///
+       void idxDelete(int & idx, bool & popit, bool & deleteit);
+private:
+       ///
+       bool up_;
+       ///
+       bool down_;
+protected:
+       ///
+       int dy0_;
+       ///
+       int dy1_;
+};
+
+#endif
index 688ef4b83ba22a044380d65ba4afd122dc941f01..8d3c9c11a719e8492943c0f55b121b5e7f896867 100644 (file)
 using std::max;
 using std::min;
 
+
 MathXArray::MathXArray()
        : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), style_(LM_ST_TEXT)
 {}
 
 
-void MathXArray::Metrics(MathStyles st)
+void MathXArray::Metrics(MathStyles st, int, int)
 {
        if (data_.empty()) {
                mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_); 
@@ -31,24 +32,28 @@ void MathXArray::Metrics(MathStyles st)
        width_   = 0;
        style_    = st;
 
+       // keep last values for scriptInset's need to look back
+       int asc = 0;
+       int des = 0;
+       int wid = 0;
+       mathed_char_height(LM_TC_VAR, st, 'I', asc, des);
+
        for (int pos = 0; pos < data_.size(); data_.next(pos)) {
-               MathInset * p = data_.GetInset(pos);
+               MathInset * p = data_.nextInset(pos);
                if (p) {
-                       p->Metrics(st);
-                       ascent_  = max(ascent_,  p->ascent());
-                       descent_ = max(descent_, p->descent());
-                       width_   += p->width();
+                       // only MathUpDownInsets will use the asc/des information...
+                       p->Metrics(st, asc, des);
+                       asc = p->ascent();
+                       des = p->descent();
+                       wid = p->width();
                } else {
                        char cx = data_.GetChar(pos); 
                        MathTextCodes fc = data_.GetCode(pos); 
-                       int asc;
-                       int des;
-                       int wid;
                        mathed_char_dim(fc, style_, cx, asc, des, wid);
-                       ascent_  = max(ascent_, asc);
-                       descent_ = max(descent_, des);
-                       width_   += wid;
                }
+               ascent_  = max(ascent_, asc);
+               descent_ = max(descent_, des);
+               width_   += wid;
        }
 }
 
@@ -64,7 +69,7 @@ void MathXArray::draw(Painter & pain, int x, int y)
        }
 
        for (int pos = 0; pos < data_.size(); data_.next(pos)) {
-               MathInset * p = data_.GetInset(pos);
+               MathInset * p = data_.nextInset(pos);
                if (p) {
                        p->draw(pain, x, y);
                        x += p->width();
@@ -104,7 +109,7 @@ int MathXArray::width(int pos) const
                return 0;
 
        if (data_.isInset(pos)) 
-               return data_.GetInset(pos)->width();
+               return data_.nextInset(pos)->width();
        else 
                return mathed_char_width(data_.GetCode(pos), style_, data_.GetChar(pos));
 }
index 7bc0bc826914eba521c18792adfcf7f1c8b47b74..abd9a3d3e907dffa890597f42b07c2022b77feac 100644 (file)
@@ -18,7 +18,7 @@ public:
        ///
        MathXArray();
        ///
-       void Metrics(MathStyles st);
+       void Metrics(MathStyles st, int asc = 0, int des = 0);
        ///
        void draw(Painter & pain, int x, int y);