From 82b70e9c64910942ab86459602a9f00f0cfcb905 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Thu, 26 Apr 2007 21:40:51 +0000 Subject: [PATCH] File format change: Fix bug 1746 partly git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18052 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 10 +++++- lib/lyx2lyx/LyX.py | 2 +- lib/lyx2lyx/lyx_1_5.py | 35 ++++++++++++++++++--- src/Buffer.cpp | 2 +- src/insets/InsetTabular.cpp | 62 ++++++++++++++----------------------- 5 files changed, 66 insertions(+), 45 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index fbba433b8d..7dca45b607 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,5 +1,13 @@ LyX file-format changes ----------------------- + +2007-04-26 Uwe Stöhr + + * format incremented to 265: fix LyX's table border line handling + With the fix (see bug 1746) LyX now takes care if the user has entered + a "|" character in the argument field of tables. Therefore the "|" + character has to be removed when also a table border is set. + 2007-04-24 José Matos * format incremented to 264: @@ -45,7 +53,7 @@ LyX file-format changes 'xx \textbf{yy} zz'. New: Spaces are always output with the font set by the user. -2007-01-31 Uwe Stöhr +2007-01-31 Uwe Stöhr * format incremented to 258: new \lyxline definition Old: diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 51f261fdc5..c975aa3724 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -74,7 +74,7 @@ format_relation = [("0_06", [200], generate_minor_versions("0.6" , 4)), ("1_2", [220], generate_minor_versions("1.2" , 4)), ("1_3", [221], generate_minor_versions("1.3" , 7)), ("1_4", range(222,246), generate_minor_versions("1.4" , 4)), - ("1_5", range(246,265), generate_minor_versions("1.5" , 0))] + ("1_5", range(246,266), generate_minor_versions("1.5" , 0))] def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_5.py b/lib/lyx2lyx/lyx_1_5.py index 3b1bc7afc3..9f1b1ff980 100644 --- a/lib/lyx2lyx/lyx_1_5.py +++ b/lib/lyx2lyx/lyx_1_5.py @@ -732,7 +732,7 @@ def convert_lyxline(document): k = 0 while i < len(document.body): i = find_token(document.body, "\\size " + fontsizes[n], i) - k = find_token(document.body, "\\lyxline",i) + k = find_token(document.body, "\\lyxline", i) # the corresponding fontsize command is always 2 lines before the \lyxline if (i != -1 and k == i+2): document.body[i:i+1] = [] @@ -1257,6 +1257,32 @@ def revert_cv_textclass(document): document.textclass = "cv" +def convert_tableborder(document): + # The problematic is: LyX double the table cell border as it ignores the "|" character in + # the cell arguments. A fix takes care of this and therefore the "|" has to be removed + i = 0 + while i < len(document.body): + h = document.body[i].find("leftline=\"true\"", 0, len(document.body[i])) + k = document.body[i].find("|>{", 0, len(document.body[i])) + # the two tokens have to be in one line + if (h != -1 and k != -1): + # delete the "|" + document.body[i] = document.body[i][:k] + document.body[i][k+1:len(document.body[i])-1] + i = i + 1 + + +def revert_tableborder(document): + i = 0 + while i < len(document.body): + h = document.body[i].find("leftline=\"true\"", 0, len(document.body[i])) + k = document.body[i].find(">{", 0, len(document.body[i])) + # the two tokens have to be in one line + if (h != -1 and k != -1): + # add the "|" + document.body[i] = document.body[i][:k] + '|' + document.body[i][k:] + i = i + 1 + + ## # Conversion hub # @@ -1280,9 +1306,11 @@ convert = [[246, []], [261, [convert_changes]], [262, []], [263, [normalize_language_name]], - [264, [convert_cv_textclass]]] + [264, [convert_cv_textclass]], + [265, [convert_tableborder]]] -revert = [[263, [revert_cv_textclass]], +revert = [[264, [revert_tableborder]], + [263, [revert_cv_textclass]], [262, [revert_language_name]], [261, [revert_ascii]], [260, []], @@ -1306,4 +1334,3 @@ revert = [[263, [revert_cv_textclass]], if __name__ == "__main__": pass - diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 728d288ce9..2216084ed1 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -141,7 +141,7 @@ using std::string; namespace { -int const LYX_FORMAT = 264; +int const LYX_FORMAT = 265; } // namespace anon diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 6596396c35..85900d7e08 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -835,14 +835,8 @@ bool Tabular::leftLine(idx_type cell, bool wholecolumn) const return false; if (!wholecolumn && isMultiColumn(cell) && (isFirstCellInRow(cell) || isMultiColumn(cell-1))) - { - if (cellinfo_of_cell(cell).align_special.empty()) - return cellinfo_of_cell(cell).left_line; - return prefixIs(ltrim(cellinfo_of_cell(cell).align_special), '|'); - } - if (column_info[column_of_cell(cell)].align_special.empty()) - return column_info[column_of_cell(cell)].left_line; - return prefixIs(ltrim(column_info[column_of_cell(cell)].align_special), '|'); + return cellinfo_of_cell(cell).left_line; + return column_info[column_of_cell(cell)].left_line; } @@ -852,14 +846,8 @@ bool Tabular::rightLine(idx_type cell, bool wholecolumn) const return false; if (!wholecolumn && isMultiColumn(cell) && (isLastCellInRow(cell) || isMultiColumn(cell + 1))) - { - if (cellinfo_of_cell(cell).align_special.empty()) - return cellinfo_of_cell(cell).right_line; - return suffixIs(rtrim(cellinfo_of_cell(cell).align_special), '|'); - } - if (column_info[column_of_cell(cell)].align_special.empty()) - return column_info[right_column_of_cell(cell)].right_line; - return suffixIs(rtrim(column_info[column_of_cell(cell)].align_special), '|'); + return cellinfo_of_cell(cell).right_line; + return column_info[right_column_of_cell(cell)].right_line; } @@ -2055,16 +2043,14 @@ int Tabular::TeXCellPreamble(odocstream & os, idx_type cell) const } if (isMultiColumn(cell)) { os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{"; + if (leftLine(cell) && + (isFirstCellInRow(cell) || + (!isMultiColumn(cell - 1) && !leftLine(cell, true) && + !rightLine(cell - 1, true)))) + os << '|'; if (!cellinfo_of_cell(cell).align_special.empty()) { - os << cellinfo_of_cell(cell).align_special << "}{"; + os << cellinfo_of_cell(cell).align_special; } else { - if (leftLine(cell) && - (isFirstCellInRow(cell) || - (!isMultiColumn(cell - 1) && !leftLine(cell, true) && - !rightLine(cell - 1, true)))) - { - os << '|'; - } if (!getPWidth(cell).zero()) { switch (getVAlignment(cell)) { case LYX_VALIGN_TOP: @@ -2092,15 +2078,15 @@ int Tabular::TeXCellPreamble(odocstream & os, idx_type cell) const os << 'c'; break; } - } - if (rightLine(cell)) - os << '|'; - if (((cell + 1) < numberofcells) && !isFirstCellInRow(cell+1) && - leftLine(cell+1)) - os << '|'; - os << "}{"; + } // end if else !getPWidth + } // end if else !cellinfo_of_cell + if (rightLine(cell)) + os << '|'; + if (((cell + 1) < numberofcells) && !isFirstCellInRow(cell+1) && + leftLine(cell+1)) + os << '|'; + os << "}{"; } - } if (getUsebox(cell) == BOX_PARBOX) { os << "\\parbox["; switch (getVAlignment(cell)) { @@ -2361,11 +2347,11 @@ int Tabular::latex(Buffer const & buf, odocstream & os, else os << "\\begin{tabular}{"; for (col_type i = 0; i < columns_; ++i) { + if (!use_booktabs && column_info[i].left_line) + os << '|'; if (!column_info[i].align_special.empty()) { os << column_info[i].align_special; } else { - if (!use_booktabs && column_info[i].left_line) - os << '|'; if (!column_info[i].p_width.zero()) { switch (column_info[i].alignment) { case LYX_ALIGN_LEFT: @@ -2410,10 +2396,10 @@ int Tabular::latex(Buffer const & buf, odocstream & os, os << 'c'; break; } - } - if (!use_booktabs && column_info[i].right_line) - os << '|'; - } + } // end if else !column_info[i].p_width + } // end if else !column_info[i].align_special + if (!use_booktabs && column_info[i].right_line) + os << '|'; } os << "}\n"; ++ret; -- 2.39.2