From: Georg Baum Date: Mon, 20 Aug 2007 17:30:45 +0000 (+0000) Subject: fix bug 4132: parse some more column specifiers X-Git-Tag: 1.6.10~8792 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=aff3772b34af8bd770cbb1ae5610cdfa6a71e032;p=features.git fix bug 4132: parse some more column specifiers git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19662 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index eaf6a40af9..3226d13111 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -63,7 +63,6 @@ class InsetMathGrid; class InsetMathHull; class InsetMathMatrix; class InsetMathNest; -class InsetMathParbox; class InsetMathScript; class InsetMathString; class InsetMathSpace; @@ -132,7 +131,6 @@ public: virtual InsetMathMatrix const * asMatrixInset() const { return 0; } virtual InsetMathNest * asNestInset() { return 0; } virtual InsetMathNest const * asNestInset() const { return 0; } - virtual InsetMathParbox * asParboxInset() { return 0; } virtual InsetMathScript * asScriptInset() { return 0; } virtual InsetMathScript const * asScriptInset() const { return 0; } virtual InsetMathSpace * asSpaceInset() { return 0; } diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index a3b680dd34..0a62b19cab 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -178,6 +178,7 @@ void InsetMathGrid::setDefaults() for (col_type col = 0; col < ncols(); ++col) { colinfo_[col].align_ = defaultColAlign(col); colinfo_[col].skip_ = defaultColSpace(col); + colinfo_[col].special_.clear(); } } @@ -189,13 +190,70 @@ void InsetMathGrid::halign(docstring const & hh) char_type c = *it; if (c == '|') { colinfo_[col].lines_++; + } else if ((c == 'p' || c == 'm' || c == 'b'|| + c == '!' || c == '@' || c == '>' || c == '<') && + it + 1 != hh.end() && *(it + 1) == '{') { + // @{decl.} and p{width} are standard LaTeX, the + // others are extensions by array.sty + bool const newcolumn = c == 'p' || c == 'm' || c == 'b'; + if (newcolumn) { + // this declares a new column + if (col >= ncols()) + // Only intercolumn stuff is allowed + // in the last dummy column + break; + colinfo_[col].align_ = 'l'; + } else { + // this is intercolumn stuff + if (colinfo_[col].special_.empty()) + // Overtake possible lines + colinfo_[col].special_ = docstring(colinfo_[col].lines_, '|'); + } + int brace_open = 0; + int brace_close = 0; + while (it != hh.end()) { + c = *it; + colinfo_[col].special_ += c; + if (c == '{') + ++brace_open; + else if (c == '}') + ++brace_close; + ++it; + if (brace_open > 0 && brace_open == brace_close) + break; + } + --it; + if (newcolumn) { + colinfo_[col].lines_ = std::count( + colinfo_[col].special_.begin(), + colinfo_[col].special_.end(), '|'); + LYXERR(Debug::MATHED) + << "special column separator: `" + << to_utf8(colinfo_[col].special_) + << '\'' << endl; + ++col; + colinfo_[col].lines_ = 0; + colinfo_[col].special_.clear(); + } } else if (col >= ncols()) { - // Only '|' is allowed in the last dummy column + // Only intercolumn stuff is allowed in the last + // dummy column break; } else if (c == 'c' || c == 'l' || c == 'r') { - colinfo_[col].align_ = (char)c; + colinfo_[col].align_ = static_cast(c); + if (!colinfo_[col].special_.empty()) { + colinfo_[col].special_ += c; + colinfo_[col].lines_ = std::count( + colinfo_[col].special_.begin(), + colinfo_[col].special_.end(), '|'); + LYXERR(Debug::MATHED) + << "special column separator: `" + << to_utf8(colinfo_[col].special_) + << '\'' << endl; + } ++col; colinfo_[col].lines_ = 0; + colinfo_[col].special_.clear(); } else { lyxerr << "unknown column separator: '" << c << "'" << endl; } @@ -215,7 +273,8 @@ InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const { col_type col = 0; for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) - if (*it == 'c' || *it == 'l' || *it == 'r') + if (*it == 'c' || *it == 'l' || *it == 'r'|| + *it == 'p' || *it == 'm' || *it == 'b') ++col; // let's have at least one column, even if we did not recognize its // alignment @@ -228,6 +287,12 @@ InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const void InsetMathGrid::halign(char h, col_type col) { colinfo_[col].align_ = h; + if (!colinfo_[col].special_.empty()) { + char_type & c = colinfo_[col].special_[colinfo_[col].special_.size() - 1]; + if (c == 'l' || c == 'c' || c == 'r') + c = h; + } + // FIXME: Change alignment of p, m and b columns, too } @@ -241,10 +306,15 @@ docstring InsetMathGrid::halign() const { docstring res; for (col_type col = 0; col < ncols(); ++col) { - res += docstring(colinfo_[col].lines_, '|'); - res += colinfo_[col].align_; + if (colinfo_[col].special_.empty()) { + res += docstring(colinfo_[col].lines_, '|'); + res += colinfo_[col].align_; + } else + res += colinfo_[col].special_; } - return res + docstring(colinfo_[ncols()].lines_, '|'); + if (colinfo_[ncols()].special_.empty()) + return res + docstring(colinfo_[ncols()].lines_, '|'); + return res + colinfo_[ncols()].special_; } @@ -1147,14 +1217,34 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) swapCol(cur.col()); cur.pos() = 0; // trick, see above } - else if (s == "add-vline-left") + else if (s == "add-vline-left") { colinfo_[cur.col()].lines_++; - else if (s == "add-vline-right") + if (!colinfo_[cur.col()].special_.empty()) + colinfo_[cur.col()].special_ += '|'; + } + else if (s == "add-vline-right") { colinfo_[cur.col()+1].lines_++; - else if (s == "delete-vline-left") + if (!colinfo_[cur.col()+1].special_.empty()) + colinfo_[cur.col()+1].special_.insert(0, 1, '|'); + } + else if (s == "delete-vline-left") { colinfo_[cur.col()].lines_--; - else if (s == "delete-vline-right") + docstring & special = colinfo_[cur.col()].special_; + if (!special.empty()) { + docstring::size_type i = special.rfind('|'); + BOOST_ASSERT(i != docstring::npos); + special.erase(i, 1); + } + } + else if (s == "delete-vline-right") { colinfo_[cur.col()+1].lines_--; + docstring & special = colinfo_[cur.col()+1].special_; + if (!special.empty()) { + docstring::size_type i = special.find('|'); + BOOST_ASSERT(i != docstring::npos); + special.erase(i, 1); + } + } else { cur.undispatched(); break; diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index 3faa33f4ea..6d80ad6a4e 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -83,6 +83,11 @@ public: unsigned int lines_; /// additional amount to be skipped when drawing int skip_; + /// Special alignment. + /// This does also contain align_ and lines_ if it is nonempty. + /// It needs to be in sync with align_ and lines_ because some + /// code only uses align_ and lines_. + docstring special_; }; public: