}
-void Tabular::TeXTopHLine(otexstream & os, row_type row, list<col_type> columns) const
+void Tabular::TeXTopHLine(otexstream & os, row_type row, list<col_type> columns,
+ list<col_type> logical_columns) const
{
// we only output complete row lines and the 1st row here, the rest
// is done in Tabular::TeXBottomHLine(...)
} else if (realfirstrow || have_trims) {
string const cline = use_booktabs ? "\\cmidrule" : "\\cline";
col_type c = 0;
- for (auto & cl : columns) {
+ std::list<col_type>::const_iterator it1 = logical_columns.begin();
+ std::list<col_type>::const_iterator it2 = columns.begin();
+ // We need to iterate over the logical columns here, but take care for
+ // bidi swapping
+ for (; it1 != logical_columns.end() && it2 != columns.end(); ++it1, ++it2) {
+ col_type cl = *it1;
if (cl < c)
continue;
c = cl;
for (col_type j = 0 ; j < c; ++j)
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
++offset;
- string const firstcol = convert<string>(c + 1 + offset);
+ // If the two iterators differ, we are in bidi with swapped columns
+ col_type firstcol = (*it1 == *it2) ? c + 1 + offset : columns.size() - c + offset;
while (isPartOfMultiColumn(row, c))
++c;
string trim;
for (col_type j = cstart ; j < c ; ++j)
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
++offset;
- col_type const lastcol = c + 1 + offset;
+ col_type lastcol =(*it1 == *it2) ? c + 1 + offset : columns.size() - c + offset;
if (toprtrims.find(c) != toprtrims.end()
&& toprtrims.find(c)->second)
trim += "r";
os << cline;
if (!trim.empty())
os << "(" << trim << ")";
- os << "{" << firstcol << '-' << lastcol << "}";
+ if (firstcol > lastcol)
+ // This can happen with bidi (swapped columns)
+ os << "{" << lastcol << '-' << firstcol << "}";
+ else
+ os << "{" << firstcol << '-' << lastcol << "}";
if (c == columns.size() - 1)
break;
++c;
}
-void Tabular::TeXBottomHLine(otexstream & os, row_type row, list<col_type> columns) const
+void Tabular::TeXBottomHLine(otexstream & os, row_type row, list<col_type> columns,
+ list<col_type> logical_columns) const
{
// we output bottomlines of row r and the toplines of row r+1
// if the latter do not span the whole tabular
} else {
string const cline = use_booktabs ? "\\cmidrule" : "\\cline";
col_type c = 0;
- for (auto & cl : columns) {
+ std::list<col_type>::const_iterator it1 = logical_columns.begin();
+ std::list<col_type>::const_iterator it2 = columns.begin();
+ // We need to iterate over the logical columns here, but take care for
+ // bidi swapping
+ for (; it1 != logical_columns.end() && it2 != columns.end(); ++it1, ++it2) {
+ col_type cl = *it1;
if (cl < c)
continue;
c = cl;
for (col_type j = 0 ; j < c; ++j)
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
++offset;
- string const firstcol = convert<string>(c + 1 + offset);
+ // If the two iterators differ, we are in bidi with swapped columns
+ col_type firstcol = (*it1 == *it2) ? c + 1 + offset : columns.size() - c + offset;
while (isPartOfMultiColumn(row, c))
++c;
string trim;
for (col_type j = cstart ; j < c ; ++j)
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
++offset;
- col_type const lastcol = c + 1 + offset;
+ col_type lastcol =(*it1 == *it2) ? c + 1 + offset : columns.size() - c + offset;
if (bottomrtrims.find(c) != bottomrtrims.end()
&& bottomrtrims.find(c)->second)
trim += "r";
os << cline;
if (!trim.empty())
os << "(" << trim << ")";
- os << "{" << firstcol << '-' << lastcol << "}";
+ if (firstcol > lastcol)
+ // This can happen with bidi (swapped columns)
+ os << "{" << lastcol << '-' << firstcol << "}";
+ else
+ os << "{" << firstcol << '-' << lastcol << "}";
if (c == columns.size() - 1)
break;
++c;
void Tabular::TeXLongtableHeaderFooter(otexstream & os,
OutputParams const & runparams,
- list<col_type> columns) const
+ list<col_type> columns,
+ list<col_type> logical_columns) const
{
if (!is_long_tabular)
return;
if (row_info[r].caption &&
!row_info[r].endfirsthead && !row_info[r].endhead &&
!row_info[r].endfoot && !row_info[r].endlastfoot)
- TeXRow(os, r, runparams, columns);
+ TeXRow(os, r, runparams, columns, logical_columns);
}
}
// output first header info
os << "\\hline\n";
for (row_type r = 0; r < nrows(); ++r) {
if (row_info[r].endfirsthead)
- TeXRow(os, r, runparams, columns);
+ TeXRow(os, r, runparams, columns, logical_columns);
}
if (endfirsthead.bottomDL)
os << "\\hline\n";
os << "\\hline\n";
for (row_type r = 0; r < nrows(); ++r) {
if (row_info[r].endhead)
- TeXRow(os, r, runparams, columns);
+ TeXRow(os, r, runparams, columns, logical_columns);
}
if (endhead.bottomDL)
os << "\\hline\n";
os << "\\hline\n";
for (row_type r = 0; r < nrows(); ++r) {
if (row_info[r].endfoot)
- TeXRow(os, r, runparams, columns);
+ TeXRow(os, r, runparams, columns, logical_columns);
}
if (endfoot.bottomDL)
os << "\\hline\n";
os << "\\hline\n";
for (row_type r = 0; r < nrows(); ++r) {
if (row_info[r].endlastfoot)
- TeXRow(os, r, runparams, columns);
+ TeXRow(os, r, runparams, columns, logical_columns);
}
if (endlastfoot.bottomDL)
os << "\\hline\n";
void Tabular::TeXRow(otexstream & os, row_type row,
OutputParams const & runparams,
- list<col_type> columns) const
+ list<col_type> columns, list<col_type> logical_columns) const
{
idx_type cell = cellIndex(row, 0);
//output the top line
- TeXTopHLine(os, row, columns);
+ TeXTopHLine(os, row, columns, logical_columns);
if (row_info[row].top_space_default) {
if (use_booktabs)
os << '\n';
//output the bottom line
- TeXBottomHLine(os, row, columns);
+ TeXBottomHLine(os, row, columns, logical_columns);
if (row_info[row].interline_space_default) {
if (use_booktabs)
runparams.local_font->isRightToLeft()
&& runparams.useBidiPackage();
list<col_type> columns;
+ list<col_type> logical_columns;
for (col_type cl = 0; cl < ncols(); ++cl) {
if (!buffer().params().output_changes && column_info[cl].change.deleted())
continue;
columns.push_front(cl);
else
columns.push_back(cl);
+ // for some calculations, we need the logical (non-swapped)
+ // columns also in bidi.
+ logical_columns.push_back(cl);
}
// If we use \cline or \cmidrule, we need to locally de-activate
}
os << "}\n";
- TeXLongtableHeaderFooter(os, runparams, columns);
+ TeXLongtableHeaderFooter(os, runparams, columns, logical_columns);
//+---------------------------------------------------------------------
//+ the single row and columns (cells) +
if (!buffer().params().output_changes && row_info[r].change.deleted())
continue;
if (isValidRow(r)) {
- TeXRow(os, r, runparams, columns);
+ TeXRow(os, r, runparams, columns, logical_columns);
if (is_long_tabular && row_info[r].newpage)
os << "\\newpage\n";
}