From a996b1bd2ba6fb8b3870aad05decde3cce1a6df6 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Sun, 11 Feb 2001 09:58:20 +0000 Subject: [PATCH] - Add support for the align environment from amsmath - RTL fixes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1479 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ui/default.ui | 8 +++++--- src/ChangeLog | 9 +++++++++ src/buffer.C | 2 +- src/insets/ChangeLog | 5 +++++ src/insets/insettext.C | 9 +++++++++ src/lyxparagraph.h | 2 ++ src/mathed/ChangeLog | 4 ++++ src/mathed/math_cursor.C | 11 +++++++++- src/mathed/math_defs.h | 10 ++++++++-- src/mathed/math_inset.C | 22 ++++++++++++++------ src/mathed/math_parser.C | 13 +++++++++++- src/mathed/math_write.C | 6 +++++- src/paragraph.C | 43 +++++++++++++++++++++++++++++++++++++++- src/text.C | 13 +++++------- 14 files changed, 133 insertions(+), 24 deletions(-) diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 588929d489..def3d0ed7d 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -146,9 +146,11 @@ Menuset Menu "edit_math" Item "Make eqnarray|e" "break-line e" Item "Make multline|m" "break-line m" - Item "Make alignat 1 column|1" "break-line 1" - Item "Make alignat 2 columns|2" "break-line 2" - Item "Make alignat 3 columns|3" "break-line 3" + Item "Make align 1 column|1" "break-line 1" + Item "Make align 2 columns|2" "break-line 2" + Item "Make align 3 columns|3" "break-line 3" + Item "Make alignat 2 columns|2" "break-line B" + Item "Make alignat 3 columns|3" "break-line C" Separator Item "Toggle numbering|n" "math-number" Item "Toggle numbering of line|u" "math-nonumber" diff --git a/src/ChangeLog b/src/ChangeLog index ea479d722b..f910fa6b61 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2001-02-10 Dekel Tsur + + * text.C (PrepareToPrint): RTL Fix. + + * paragraph.C (GetUChar): New method. + (String): Use GetUChar. + + * buffer.C (asciiParagraph): Use GetUChar. + 2001-02-09 Dekel Tsur * text.C (GetVisibleRow): Fix selection drawing for RTL text in tables. diff --git a/src/buffer.C b/src/buffer.C index f4c92268c5..c548ce5396 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1528,7 +1528,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par, } else { islatex = 0; } - c = par->GetChar(i); + c = par->GetUChar(params, i); if (islatex) continue; switch (c) { diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 5388b4e6ab..2ae1eb1185 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2001-02-10 Dekel Tsur + + * insettext.C (LocalDispatch): Restore the language if the inset + becomes empty. + 2001-02-09 Dekel Tsur * insettext.C (moveRightIntern): Update the selection cursor. diff --git a/src/insets/insettext.C b/src/insets/insettext.C index ee26c8f475..1b16607f03 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1101,6 +1101,15 @@ InsetText::LocalDispatch(BufferView * bv, result = UNDISPATCHED; break; } + + /// If the action has deleted all text in the inset, we need to change the + // language to the language to the surronding text. + if (par->Last() == 0 && !par->next) { + LyXFont font(LyXFont::ALL_IGNORE); + font.setLanguage(bv->getParentLanguage(this)); + SetFont(bv, font, false); + } + if (result != FINISHED) { ShowInsetCursor(bv); } else diff --git a/src/lyxparagraph.h b/src/lyxparagraph.h index 98e73a11ec..69e956f2f0 100644 --- a/src/lyxparagraph.h +++ b/src/lyxparagraph.h @@ -441,6 +441,8 @@ public: LyXFont const getFont(BufferParams const &, size_type pos) const; /// value_type GetChar(size_type pos) const; + /// + value_type GetUChar(BufferParams const &, size_type pos) const; /// The position must already exist. void SetChar(size_type pos, value_type c) { #ifndef HAVE_ROPE diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index da0505e9c4..f71d92ee99 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,7 @@ +2001-02-10 Dekel Tsur + + * Many files: add support for the align environment from amsmath. + 2001-02-09 André Pönitz * array.h: replace array buffer 'byte bf[]' by 'std::vector bf' diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index f525f2a964..5d68953385 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -337,6 +337,12 @@ MathMatrixInset * create_multiline(short int type, int cols) cols = 1; switch (type) { + case LM_OT_ALIGN: + case LM_OT_ALIGNN: + columns = 2*cols; + for (int i = 0; i < cols; ++i) + align += "Rl"; + break; case LM_OT_ALIGNAT: case LM_OT_ALIGNATN: columns = 2*cols; @@ -377,8 +383,11 @@ void MathedCursor::Insert(byte c, MathedTextCodes t) short int type = LM_OT_MPAR; int cols = 1; if (c >= '1' && c <= '9') { + type = LM_OT_ALIGN; + cols = c - '1' + 1; + } else if (c >= 'A' && c <= 'I') { type = LM_OT_ALIGNAT; - cols = c - '0'; + cols = c - 'A' + 1; } else if (c == 'm') type = LM_OT_MULTLINE; else if (c == 'e') diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index 10e49d0e53..0d1901d5d6 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -145,6 +145,10 @@ enum MathedInsetTypes { /// A multiline numbered paragraph LM_OT_MPARN, /// + LM_OT_ALIGN, + /// + LM_OT_ALIGNN, + /// LM_OT_ALIGNAT, /// LM_OT_ALIGNATN, @@ -683,7 +687,8 @@ bool is_singlely_numbered(short int type) inline bool is_multi_numbered(short int type) { - return type == LM_OT_MPARN || type == LM_OT_ALIGNATN; + return type == LM_OT_MPARN || type == LM_OT_ALIGNN + || type == LM_OT_ALIGNATN; } inline @@ -695,7 +700,8 @@ bool is_numbered(short int type) inline bool is_multicolumn(short int type) { - return type == LM_OT_ALIGNAT || type == LM_OT_ALIGNATN; + return type == LM_OT_ALIGN || type == LM_OT_ALIGNN + || type == LM_OT_ALIGNAT || type == LM_OT_ALIGNATN; } #endif diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 3ab75b3f98..491a9d0d39 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -464,7 +464,11 @@ void MathMatrixInset::Metrics() } descent = h - ascent + 2; - + // Increase ws[i] for 'R' columns (except the first one) + for (i = 1; i < nc; ++i) + if (h_align[i] == 'R') + ws[i] += 10*df_width; + // Adjust local tabs cxrow = row; width = MATH_COLSEP; @@ -477,12 +481,18 @@ void MathMatrixInset::Metrics() isvoid = true; } switch (h_align[i]) { - case 'l': lf = 0; break; - case 'c': lf = (ws[i] - cxrow->getTab(i))/2; - break; - case 'r': lf = ws[i] - cxrow->getTab(i); break; + case 'l': + lf = 0; + break; + case 'c': + lf = (ws[i] - cxrow->getTab(i))/2; + break; + case 'r': + case 'R': + lf = ws[i] - cxrow->getTab(i); + break; } - ww = (isvoid) ? lf: lf + cxrow->getTab(i); + ww = (isvoid) ? lf : lf + cxrow->getTab(i); cxrow->setTab(i, lf + rg); rg = ws[i] - ww + MATH_COLSEP; if (cxrow == row) width += ws[i] + MATH_COLSEP; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 288496ffad..45a0d5db12 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -65,13 +65,15 @@ MathedInsetTypes mathed_env = LM_OT_MIN; string mathed_label; -int const latex_mathenv_num = 10; +int const latex_mathenv_num = 12; char const * latex_mathenv[latex_mathenv_num] = { "math", "displaymath", "equation", "eqnarray*", "eqnarray", + "align*", + "align", "alignat*", "alignat", "multline*", @@ -809,6 +811,15 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array, if (is_multiline(mathed_env)) { int cols = 1; if (is_multicolumn(mathed_env)) { + if (mathed_env != LM_OT_ALIGNAT && + mathed_env != LM_OT_ALIGNATN && + yyis->good()) { + char c; + yyis->get(c); + if (c != '%') + lyxerr << "Math parse error: unexpected '" + << c << "'" << endl; + } LexGetArg('{'); cols = strToInt(string(yytext)); } diff --git a/src/mathed/math_write.C b/src/mathed/math_write.C index 114584a231..2336354026 100644 --- a/src/mathed/math_write.C +++ b/src/mathed/math_write.C @@ -336,8 +336,12 @@ void mathed_write(MathParInset * p, ostream & os, int * newlines, os << "\\begin{" << latex_mathenv[mathed_env] << "}"; - if (mathed_env == LM_OT_ALIGNAT || mathed_env == LM_OT_ALIGNATN) + if (is_multicolumn(mathed_env)) { + if (mathed_env != LM_OT_ALIGNAT + && mathed_env != LM_OT_ALIGNATN) + os << "%"; os << "{" << p->GetColumns()/2 << "}"; + } os << "\n"; } ++number_of_newlines; diff --git a/src/paragraph.C b/src/paragraph.C index 510b784b21..363038a231 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1018,6 +1018,47 @@ LyXParagraph::GetChar(LyXParagraph::size_type pos) const } +LyXParagraph::value_type +LyXParagraph::GetUChar(BufferParams const & bparams, + LyXParagraph::size_type pos) const +{ + value_type c = GetChar(pos); + if (!lyxrc.rtl_support) + return c; + + value_type uc = c; + switch (c) { + case '(': + uc = ')'; + break; + case ')': + uc = '('; + break; + case '[': + uc = ']'; + break; + case ']': + uc = '['; + break; + case '{': + uc = '}'; + break; + case '}': + uc = '{'; + break; + case '<': + uc = '>'; + break; + case '>': + uc = '<'; + break; + } + if (uc != c && GetFontSettings(bparams, pos).isRightToLeft()) + return uc; + else + return c; +} + // return an string of the current word, and the end of the word in lastpos. string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const { @@ -3995,7 +4036,7 @@ string const LyXParagraph::String(Buffer const * buffer, s += labelstring + ' '; for (LyXParagraph::size_type i = beg; i < end; ++i) { - value_type c = GetChar(i); + value_type c = GetUChar(buffer->params, i); if (IsPrintable(c)) s += c; else if (c == META_INSET) { diff --git a/src/text.C b/src/text.C index b493a5498a..64fa5b2615 100644 --- a/src/text.C +++ b/src/text.C @@ -2196,21 +2196,18 @@ void LyXText::PrepareToPrint(BufferView * bview, bool const is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params); -#ifndef NEW_INSETS - if (is_rtl) { - x = RightMargin(bview->buffer(), row); + x = (workWidth(bview) > 0) + ? RightMargin(bview->buffer(), row) : 0; +#ifndef NEW_INSETS if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { LyXFont font(LyXFont::ALL_SANE); font.setSize(LyXFont::SIZE_SMALL); x += lyxfont::width("Mwide-figM", font); } - } else #endif - if (workWidth(bview) > 0) - x = LeftMargin(bview, row); - else - x = 0; + } else + x = (workWidth(bview) > 0) ? LeftMargin(bview, row) : 0; // is there a manual margin with a manual label if (textclasslist.Style(bview->buffer()->params.textclass, -- 2.39.2