]> git.lyx.org Git - features.git/commitdiff
revert part of the "grid unification" to prevent random crashs...
authorAndré Pönitz <poenitz@gmx.net>
Fri, 2 May 2003 07:52:15 +0000 (07:52 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 2 May 2003 07:52:15 +0000 (07:52 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6919 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_ertinset.C
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_hullinset.C

index 7bc02997767b2cf0e1ccebdee8c5d0e0f6123921..eeeca0c9e4ba06904c1c0e835564b9166a1b7d69 100644 (file)
@@ -16,7 +16,7 @@ void MathErtInset::metrics(MetricsInfo & mi) const
 {
        FontSetChanger dummy(mi.base, "lyxert");
        MathTextInset::metrics(mi);
-       cache_.colinfo_[0].align = 'l';
+       cache_.colinfo_[0].align_ = 'l';
        metricsMarkers2();
 }
 
index 9ed369df2a473f0305351a743e3c278f6fb94835..61729990cbd7b51307c2c768ac7a80a340ab27d2 100644 (file)
@@ -68,6 +68,25 @@ int extractInt(istream & is)
 }
 
 
+//////////////////////////////////////////////////////////////
+
+
+MathGridInset::CellInfo::CellInfo()
+       : dummy_(false)
+{}
+
+
+
+
+//////////////////////////////////////////////////////////////
+
+
+MathGridInset::RowInfo::RowInfo()
+       : lines_(0), skip_(0)
+{}
+
+
+
 int MathGridInset::RowInfo::skipPixels() const
 {
        return crskip_.inBP();
@@ -75,11 +94,22 @@ int MathGridInset::RowInfo::skipPixels() const
 
 
 
+//////////////////////////////////////////////////////////////
+
+
+MathGridInset::ColInfo::ColInfo()
+       : align_('c'), leftline_(false), rightline_(false), lines_(0)
+{}
+
+
 //////////////////////////////////////////////////////////////
 
 
 MathGridInset::MathGridInset(char v, string const & h)
-       : MathNestInset(1), rowinfo_(1), colinfo_(1), cellinfo_(1)
+       : MathNestInset(guessColumns(h)),
+         rowinfo_(2),
+         colinfo_(guessColumns(h) + 1),
+         cellinfo_(1 * guessColumns(h))
 {
        setDefaults();
        valign(v);
@@ -89,7 +119,11 @@ MathGridInset::MathGridInset(char v, string const & h)
 
 
 MathGridInset::MathGridInset()
-       : MathNestInset(1), rowinfo_(1), colinfo_(1), cellinfo_(1), v_align_('c')
+       : MathNestInset(1),
+         rowinfo_(1 + 1),
+               colinfo_(1 + 1),
+               cellinfo_(1),
+               v_align_('c')
 {
        setDefaults();
 }
@@ -97,7 +131,10 @@ MathGridInset::MathGridInset()
 
 MathGridInset::MathGridInset(col_type m, row_type n)
        : MathNestInset(m * n),
-         rowinfo_(n), colinfo_(m), cellinfo_(m * n), v_align_('c')
+         rowinfo_(n + 1),
+               colinfo_(m + 1),
+               cellinfo_(m * n),
+               v_align_('c')
 {
        setDefaults();
 }
@@ -105,7 +142,10 @@ MathGridInset::MathGridInset(col_type m, row_type n)
 
 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
        : MathNestInset(m * n),
-         rowinfo_(n), colinfo_(m), cellinfo_(m * n), v_align_(v)
+         rowinfo_(n + 1),
+         colinfo_(m + 1),
+               cellinfo_(m * n),
+               v_align_(v)
 {
        setDefaults();
        valign(v);
@@ -139,8 +179,8 @@ void MathGridInset::setDefaults()
        //if (nrows() <= 0)
        //      lyxerr << "positive number of rows expected\n";
        for (col_type col = 0; col < ncols(); ++col) {
-               colinfo_[col].align = defaultColAlign(col);
-                       colinfo_[col].skip_ = defaultColSpace(col);
+               colinfo_[col].align_ = defaultColAlign(col);
+               colinfo_[col].skip_  = defaultColSpace(col);
        }
 }
 
@@ -149,14 +189,13 @@ void MathGridInset::halign(string const & hh)
 {
        col_type col = 0;
        for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
-               if (col == ncols())
-                       addCol(ncols() - 1);
-               char const c = *it;
-               lyxerr << "handle column separator: '" << c << "'\n";
+               if (col >= ncols())
+                       break;
+               char c = *it;
                if (c == '|') {
                        colinfo_[col].lines_++;
                } else if (c == 'c' || c == 'l' || c == 'r') {
-                       colinfo_[col].align = c;
+                       colinfo_[col].align_ = c;
                        ++col;
                        colinfo_[col].lines_ = 0;
                } else {
@@ -164,24 +203,39 @@ void MathGridInset::halign(string const & hh)
                }
        }
 
+/*
        col_type n = hh.size();
-       if (n >= ncols())
-               n = ncols() - 1;
+       if (n > ncols())
+               n = ncols();
        for (col_type col = 0; col < n; ++col)
-               colinfo_[col].align = hh[col];
+               colinfo_[col].align_ = hh[col];
+*/
 }
 
 
+MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
+{
+       col_type col = 0;
+       for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
+               if (*it == 'c' || *it == 'l' || *it == 'r')
+                       ++col;
+       // let's have at least one column, even if we did not recognize its
+       // alignment
+       if (col == 0)
+               col = 1;
+       return col;
+}
+
 
 void MathGridInset::halign(char h, col_type col)
 {
-       colinfo_[col].align = h;
+       colinfo_[col].align_ = h;
 }
 
 
 char MathGridInset::halign(col_type col) const
 {
-       return colinfo_[col].align;
+       return colinfo_[col].align_;
 }
 
 
@@ -190,9 +244,9 @@ string MathGridInset::halign() const
        string res;
        for (col_type col = 0; col < ncols(); ++col) {
                res += string(colinfo_[col].lines_, '|');
-               res += colinfo_[col].align;
+               res += colinfo_[col].align_;
        }
-       return res
+       return res + string(colinfo_[ncols()].lines_, '|');
 }
 
 
@@ -210,13 +264,13 @@ char MathGridInset::valign() const
 
 MathGridInset::col_type MathGridInset::ncols() const
 {
-       return colinfo_.size();
+       return colinfo_.size() - 1;
 }
 
 
 MathGridInset::row_type MathGridInset::nrows() const
 {
-       return rowinfo_.size();
+       return rowinfo_.size() - 1;
 }
 
 
@@ -262,10 +316,12 @@ void MathGridInset::metrics(MetricsInfo & mi) const
                rowinfo_[row].descent_ = desc;
        }
        rowinfo_[0].ascent_       += hlinesep() * rowinfo_[0].lines_;
+       rowinfo_[nrows()].ascent_  = 0;
+       rowinfo_[nrows()].descent_ = 0;
 
        // compute vertical offsets
        rowinfo_[0].offset_ = 0;
-       for (row_type row = 1; row < nrows(); ++row) {
+       for (row_type row = 1; row <= nrows(); ++row) {
                rowinfo_[row].offset_  =
                        rowinfo_[row - 1].offset_  +
                        rowinfo_[row - 1].descent_ +
@@ -287,7 +343,7 @@ void MathGridInset::metrics(MetricsInfo & mi) const
                default:
                        h = rowinfo_[nrows() - 1].offset_ / 2;
        }
-       for (row_type row = 0; row < nrows(); ++row)
+       for (row_type row = 0; row <= nrows(); ++row)
                rowinfo_[row].offset_ -= h;
 
 
@@ -298,10 +354,11 @@ void MathGridInset::metrics(MetricsInfo & mi) const
                        wid = max(wid, cell(index(row, col)).width());
                colinfo_[col].width_ = wid;
        }
+       colinfo_[ncols()].width_  = 0;
 
        // compute horizontal offsets
        colinfo_[0].offset_ = border();
-       for (col_type col = 1; col < ncols(); ++col) {
+       for (col_type col = 1; col <= ncols(); ++col) {
                colinfo_[col].offset_ =
                        colinfo_[col - 1].offset_ +
                        colinfo_[col - 1].width_ +
@@ -311,19 +368,19 @@ void MathGridInset::metrics(MetricsInfo & mi) const
        }
 
 
-       dim_.w =   colinfo_[ncols() - 1].offset_
+       dim_.w   =   colinfo_[ncols() - 1].offset_
                       + colinfo_[ncols() - 1].width_
-                //+ vlinesep() * colinfo_[ncols()].lines_
+                + vlinesep() * colinfo_[ncols()].lines_
                       + border();
 
-       dim_.a = - rowinfo_[0].offset_
+       dim_.a  = - rowinfo_[0].offset_
                       + rowinfo_[0].ascent_
-                + hlinesep() * rowinfo_[0].lines_
+                + hlinesep() * rowinfo_[0].lines_
                       + border();
 
        dim_.d =   rowinfo_[nrows() - 1].offset_
                       + rowinfo_[nrows() - 1].descent_
-                //+ hlinesep() * rowinfo_[nrows()].lines_
+                + hlinesep() * rowinfo_[nrows()].lines_
                       + border();
 
 
@@ -385,14 +442,14 @@ void MathGridInset::draw(PainterInfo & pi, int x, int y) const
        for (idx_type idx = 0; idx < nargs(); ++idx)
                cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
 
-       for (row_type row = 0; row < nrows(); ++row)
+       for (row_type row = 0; row <= nrows(); ++row)
                for (int i = 0; i < rowinfo_[row].lines_; ++i) {
                        int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
                                - i * hlinesep() - hlinesep()/2 - rowsep()/2;
                        pi.pain.line(x + 1, yy, x + width() - 1, yy);
                }
 
-       for (col_type col = 0; col < ncols(); ++col)
+       for (col_type col = 0; col <= ncols(); ++col)
                for (int i = 0; i < colinfo_[col].lines_; ++i) {
                        int xx = x + colinfo_[col].offset_
                                - i * vlinesep() - vlinesep()/2 - colsep()/2;
@@ -421,10 +478,12 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
                rowinfo_[row].descent_ = desc;
        }
        //rowinfo_[0].ascent_       += hlinesep() * rowinfo_[0].lines_;
+       rowinfo_[nrows()].ascent_  = 0;
+       rowinfo_[nrows()].descent_ = 0;
 
        // compute vertical offsets
        rowinfo_[0].offset_ = 0;
-       for (row_type row = 1; row < nrows(); ++row) {
+       for (row_type row = 1; row <= nrows(); ++row) {
                rowinfo_[row].offset_  =
                        rowinfo_[row - 1].offset_  +
                        rowinfo_[row - 1].descent_ +
@@ -446,7 +505,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
                default:
                        h = rowinfo_[nrows() - 1].offset_ / 2;
        }
-       for (row_type row = 0; row < nrows(); ++row)
+       for (row_type row = 0; row <= nrows(); ++row)
                rowinfo_[row].offset_ -= h;
 
 
@@ -457,10 +516,11 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
                        wid = max(wid, cell(index(row, col)).width());
                colinfo_[col].width_ = wid;
        }
+       colinfo_[ncols()].width_  = 0;
 
        // compute horizontal offsets
        colinfo_[0].offset_ = border();
-       for (col_type col = 1; col < ncols(); ++col) {
+       for (col_type col = 1; col <= ncols(); ++col) {
                colinfo_[col].offset_ =
                        colinfo_[col - 1].offset_ +
                        colinfo_[col - 1].width_ +
@@ -599,8 +659,8 @@ void MathGridInset::addCol(col_type newcol)
        swap(cellinfo_, new_cellinfo);
 
        ColInfo inf;
-       inf.skip_ = defaultColSpace(newcol);
-       inf.align = defaultColAlign(newcol);
+       inf.skip_  = defaultColSpace(newcol);
+       inf.align_ = defaultColAlign(newcol);
        colinfo_.insert(colinfo_.begin() + newcol, inf);
 }
 
@@ -647,7 +707,7 @@ int MathGridInset::cellXOffset(idx_type idx) const
 {
        col_type c = col(idx);
        int x = colinfo_[c].offset_;
-       char align = colinfo_[c].align;
+       char align = colinfo_[c].align_;
        if (align == 'r' || align == 'R')
                x += colinfo_[c].width_ - cell(idx).width();
        if (align == 'c' || align == 'C')
@@ -901,12 +961,12 @@ void MathGridInset::write(WriteStream & os) const
                if (!emptyline && row + 1 < nrows())
                        os << "\n";
        }
-       //string const s = verboseHLine(rowinfo_[nrows()].lines_);
-       //if (!s.empty() && s != " ") {
-       //      if (os.fragile())
-       //              os << "\\protect";
-       //      os << "\\\\" << s;
-       //}
+       string const s = verboseHLine(rowinfo_[nrows()].lines_);
+       if (!s.empty() && s != " ") {
+               if (os.fragile())
+                       os << "\\protect";
+               os << "\\\\" << s;
+       }
 }
 
 
index 9fd17f07406dbbddb1a02d2b5c8e4df3cd275d94..1beffcb7c1e8c97fec72e1f73a98c59498f58623 100644 (file)
@@ -5,7 +5,6 @@
 #include "math_nestinset.h"
 #include "vspace.h"
 #include "LString.h"
-#include "math_gridinfo.h"
 
 
 /** Gridded math inset base class.
@@ -21,8 +20,15 @@ class MathGridInset : public MathNestInset {
 public:
 
        /// additional per-cell information
-       struct CellInfo : public ::CellInfo {
-               /// fixed glue
+       struct CellInfo {
+               ///
+               CellInfo();
+               /// a dummy cell before a multicolumn cell
+               int dummy_;
+               /// special multi colums alignment
+               string align_;
+               /// these should be a per-cell property, but ok to have it here
+               /// for single-column grids like paragraphs
                mutable int glue_;
                ///
                mutable pos_type begin_;
@@ -31,45 +37,45 @@ public:
        };
 
        /// additional per-row information
-       struct RowInfo : public ::RowInfo {
+       struct RowInfo {
                ///
-               RowInfo()
-                       : lines_(0), skip_(0)
-               {}
-
+               RowInfo();
                ///
                int skipPixels() const;
-               /// how many hlines above this row?
-               int lines_;
-               /// parameter to the line break
-               LyXLength crskip_;
-               /// extra distance between lines on screen
-               int skip_;
-
                /// cached descent
                mutable int descent_;
                /// cached ascent
                mutable int ascent_;
                /// cached offset
                mutable int offset_;
+               /// how many hlines above this row?
+               int lines_;
+               /// parameter to the line break
+               LyXLength crskip_;
+               /// extra distance between lines
+               int skip_;
        };
 
        // additional per-row information
-       struct ColInfo : public ::ColInfo {
+       struct ColInfo {
                ///
-               ColInfo()
-                       : lines_(0), skip_(0)
-               {}
-
+               ColInfo();
+               /// currently possible: 'l', 'c', 'r'
+               char align_;
                /// cache for drawing
-               int lines_;
-               /// additional amount to be skipped on screen
-               int skip_;
-
+               int h_offset;
                /// cached width
                mutable int width_;
                /// cached offset
                mutable int offset_;
+               /// do we need a line to the left?
+               bool leftline_;
+               /// do we need a line to the right?
+               bool rightline_;
+               /// how many lines to the left of this column?
+               int lines_;
+               /// additional amount to be skipped when drawing
+               int skip_;
        };
 
 public:
@@ -214,6 +220,8 @@ protected:
        virtual string eolString(row_type row, bool fragile = false) const;
        /// returns proper 'end of column' code for LaTeX
        virtual string eocString(col_type col, col_type lastcol) const;
+       /// extract number of columns from alignment string
+       col_type guessColumns(string const & halign) const;
        /// splits cells and shifts right part to the next cell
        void splitCell(idx_type &, pos_type & pos);
 
index ad5080ffc02b112ff700bdfeee05080561168ef4..14c7ff7bd4421e1947fcb278fdd51d8103856350 100644 (file)
@@ -69,16 +69,15 @@ namespace {
        {
                if (s == "none")      return 0;
                if (s == "simple")    return 1;
-               if (s == "chemistry") return 2;
-               if (s == "equation")  return 3;
-               if (s == "eqnarray")  return 4;
-               if (s == "align")     return 5;
-               if (s == "alignat")   return 6;
-               if (s == "xalignat")  return 7;
-               if (s == "xxalignat") return 8;
-               if (s == "multline")  return 9;
-               if (s == "gather")    return 10;
-               if (s == "flalign")   return 11;
+               if (s == "equation")  return 2;
+               if (s == "eqnarray")  return 3;
+               if (s == "align")     return 4;
+               if (s == "alignat")   return 5;
+               if (s == "xalignat")  return 6;
+               if (s == "xxalignat") return 7;
+               if (s == "multline")  return 8;
+               if (s == "gather")    return 9;
+               if (s == "flalign")   return 10;
                lyxerr << "unknown hull type '" << s << "'\n";
                return 0;
        }
@@ -163,8 +162,6 @@ char const * MathHullInset::standardFont() const
 {
        if (type_ == "none")
                return "lyxnochange";
-       if (type_ == "chemistry")
-               return "mathrm";
        return "mathnormal";
 }
 
@@ -293,7 +290,7 @@ bool MathHullInset::ams() const
 
 bool MathHullInset::display() const
 {
-       return type_ != "simple" && type_ != "none" && type_ != "chemistry";
+       return type_ != "simple" && type_ != "none";
 }
 
 
@@ -309,8 +306,6 @@ bool MathHullInset::numberedType() const
 {
        if (type_ == "none")
                return false;
-       if (type_ == "chemistry")
-               return false;
        if (type_ == "simple")
                return false;
        if (type_ == "xxalignat")
@@ -353,9 +348,6 @@ void MathHullInset::header_write(WriteStream & os) const
                        os << ' ';
        }
 
-       else if (type_ == "chemistry")
-               os << "$\\mathrm{";
-
        else if (type_ == "equation") {
                if (n)
                        os << "\\begin{equation" << star(n) << "}\n";
@@ -390,9 +382,6 @@ void MathHullInset::footer_write(WriteStream & os) const
        else if (type_ == "simple")
                os << '$';
 
-       else if (type_ == "chemistry")
-               os << "}$";
-
        else if (type_ == "equation")
                if (n)
                        os << "\\end{equation" << star(n) << "}\n";
@@ -506,22 +495,22 @@ void MathHullInset::mutate(string const & newtype)
                // done
        }
 
-       else if (newtype == "none" || newtype == "chemistry") {
-               mutate("simple");
+       else if (type_ == "none") {
+               setType("simple");
                numbered(0, false);
+               mutate(newtype);
        }
 
-       else if (newtype == "simple") {
-               if (type_ != "none" && type_ != "chemistry") {
-                       mutate("equation");
+       else if (type_ == "simple") {
+               if (newtype == "none") {
+                       setType("none");
+               } else {
+                       setType("equation");
                        numbered(0, false);
+                       mutate(newtype);
                }
        }
 
-       else if (newtype == "equation" && smaller(type_, newtype)) {
-               numbered(0, false);
-       }
-
        else if (type_ == "equation") {
                if (smaller(newtype, type_)) {
                        setType("simple");
@@ -625,8 +614,6 @@ void MathHullInset::mutate(string const & newtype)
                lyxerr << "mutation from '" << type_
                                         << "' to '" << newtype << "' not implemented" << endl;
        }
-
-       setType(newtype);
 }
 
 
@@ -859,7 +846,5 @@ dispatch_result MathHullInset::dispatch
 
 string MathHullInset::fileInsetLabel() const
 {
-       if (type_ == "chemistry")
-               return "Chemistry";
        return "Formula";
 }