clean up horizontal tabular line latex-output

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26395 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2008-09-14 12:31:58 +00:00
parent a2c42bc702
commit 3573d29271

View File

@ -1802,35 +1802,33 @@ bool Tabular::isPartOfMultiColumn(row_type row, col_type column) const
int Tabular::TeXTopHLine(odocstream & os, row_type row) const int Tabular::TeXTopHLine(odocstream & os, row_type row) const
{ {
// FIXME: assert or return 0 as in TeXBottomHLine()? col_type const ncols = column_info.size();
LASSERT(row != npos, /**/); vector<bool> topline;
LASSERT(row < row_info.size(), /**/); int nset = 0;
for (col_type c = 0; c < ncols; ++c) {
idx_type const fcell = getFirstCellInRow(row); topline.push_back(topLine(cellIndex(row, c)));
idx_type const n = numberOfCellsInRow(fcell) + fcell; if (topline[c])
idx_type tmp = 0; ++nset;
for (idx_type i = fcell; i < n; ++i) {
if (topLine(i))
++tmp;
} }
if (use_booktabs && row == 0) {
if (topLine(fcell)) if ((row == 0 && nset == 0) || (row > 0 && nset != ncols))
os << "\\toprule "; return 0;
} else if (tmp == n - fcell) {
os << (use_booktabs ? "\\midrule " : "\\hline "); if (nset == ncols) {
} else if (tmp) { if (use_booktabs) {
for (idx_type i = fcell; i < n; ++i) { os << (row == 0 ? "\\toprule " : "\\midrule ");
if (topLine(i)) { } else {
os << (use_booktabs ? "\\cmidrule{" : "\\cline{") os << "\\hline ";
<< cellColumn(i) + 1 }
<< '-' } else if (row == 0) {
<< cellRightColumn(i) + 1 for (col_type c = 0; c < ncols; ++c) {
<< "} "; if (topline[c]) {
os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 << '-';
while (c < ncols && topline[c])
++c;
os << c << "} ";
} }
} }
} else {
return 0;
} }
os << "\n"; os << "\n";
return 1; return 1;
@ -1839,35 +1837,41 @@ int Tabular::TeXTopHLine(odocstream & os, row_type row) const
int Tabular::TeXBottomHLine(odocstream & os, row_type row) const int Tabular::TeXBottomHLine(odocstream & os, row_type row) const
{ {
// FIXME: return 0 or assert as in TeXTopHLine()? bool lastrow = row == row_info.size() - 1;
if (row == npos || row >= row_info.size()) col_type const ncols = column_info.size();
vector<bool> bottomline, topline;
bool nextrowset = true;
for (col_type c = 0; c < ncols; ++c) {
bottomline.push_back(bottomLine(cellIndex(row, c)));
topline.push_back(!lastrow && topLine(cellIndex(row + 1, c)));
nextrowset &= topline[c];
}
int nset = 0;
for (col_type c = 0; c < ncols; ++c) {
if (!nextrowset)
bottomline[c] = bottomline[c] || topline[c];
if (bottomline[c])
++nset;
}
if (nset == 0 || (nextrowset && nset != ncols))
return 0; return 0;
idx_type const fcell = getFirstCellInRow(row); if (nset == ncols) {
idx_type const n = numberOfCellsInRow(fcell) + fcell; if (use_booktabs)
idx_type tmp = 0; os << (lastrow ? "\\bottomrule" : "\\midrule");
else
for (idx_type i = fcell; i < n; ++i) { os << "\\hline";
if (bottomLine(i)) } else {
++tmp; for (col_type c = 0; c < ncols; ++c) {
} if (bottomline[c]) {
if (use_booktabs && row == row_info.size() - 1) { os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 << '-';
if (bottomLine(fcell)) while (c < ncols && bottomline[c])
os << "\\bottomrule"; ++c;
} else if (tmp == n - fcell) { os << c << "} ";
os << (use_booktabs ? "\\midrule" : "\\hline");
} else if (tmp) {
for (idx_type i = fcell; i < n; ++i) {
if (bottomLine(i)) {
os << (use_booktabs ? "\\cmidrule{" : "\\cline{")
<< cellColumn(i) + 1
<< '-'
<< cellRightColumn(i) + 1
<< "} ";
} }
} }
} else {
return 0;
} }
os << "\n"; os << "\n";
return 1; return 1;