- string s;
- s = fl;
- if (s.length() > 8)
- version = atoi(s.c_str() + 8);
- else
- version = 1;
- if (version < 5) {
- lyxerr << "Tabular format < 5 is not supported anymore\n"
- "Get an older version of LyX (< 1.1.x) for conversion!"
- << endl;
- WriteAlert(_("Warning:"),
- _("Tabular format < 5 is not supported anymore\n"),
- _("Get an older version of LyX (< 1.1.x) for conversion!"));
- if (version > 2) {
- is >> rows_arg >> columns_arg >> is_long_tabular_arg
- >> rotate_arg >> a >> b >> c >> d;
- } else
- is >> rows_arg >> columns_arg;
- Init(buffer, rows_arg, columns_arg);
- SetLongTabular(is_long_tabular_arg);
- SetRotateTabular(rotate_arg);
- string tmp;
- for (i = 0; i < rows_; ++i) {
- getline(is, tmp);
- }
- for (i = 0; i < columns_; ++i) {
- getline(is, tmp);
- }
- for (i = 0; i < rows_; ++i) {
- for (j = 0; j < columns_; ++j) {
- getline(is, tmp);
- }
- }
- set_row_column_number_info();
- return;
- }
- is >> rows_arg >> columns_arg >> is_long_tabular_arg
- >> rotate_arg >> a >> b >> c >> d;
- Init(buffer, rows_arg, columns_arg);
- SetLongTabular(is_long_tabular_arg);
- SetRotateTabular(rotate_arg);
- endhead = a;
- endfirsthead = b;
- endfoot = c;
- endlastfoot = d;
- for (i = 0; i < rows_; ++i) {
- a = b = c = d = e = f = g = h = 0;
- is >> a >> b >> c >> d;
- row_info[i].top_line = a;
- row_info[i].bottom_line = b;
-// row_info[i].is_cont_row = c;
- row_info[i].newpage = d;
- }
- for (i = 0; i < columns_; ++i) {
- string s1;
- string s2;
- is >> a >> b >> c;
- char ch; // skip '"'
- is >> ch;
- getline(is, s1, '"');
- is >> ch; // skip '"'
- getline(is, s2, '"');
- column_info[i].alignment = static_cast<char>(a);
- column_info[i].left_line = b;
- column_info[i].right_line = c;
- column_info[i].p_width = s1;
- column_info[i].align_special = s2;
- }
- for (i = 0; i < rows_; ++i) {
- for (j = 0; j < columns_; ++j) {
- string s1;
- string s2;
- is >> a >> b >> c >> d >> e >> f >> g;
- char ch;
- is >> ch; // skip '"'
- getline(is, s1, '"');
- is >> ch; // skip '"'
- getline(is, s2, '"');
- cell_info[i][j].multicolumn = static_cast<char>(a);
- cell_info[i][j].alignment = static_cast<char>(b);
- cell_info[i][j].top_line = static_cast<char>(c);
- cell_info[i][j].bottom_line = static_cast<char>(d);
-// cell_info[i][j].has_cont_row = static_cast<bool>(e);
- cell_info[i][j].rotate = static_cast<bool>(f);
- cell_info[i][j].linebreaks = static_cast<bool>(g);
- cell_info[i][j].align_special = s1;
- cell_info[i][j].p_width = s2;
- }
- }
- set_row_column_number_info();
-}
-
-
-// cell < 0 will tex the preamble
-// returns the number of printed newlines
-int LyXTabular::TexEndOfCell(ostream & os, int cell) const
-{
- int i;
- int ret = 0;
- int tmp; // tmp2;
- int fcell, nvcell;
- if (IsLastCell(cell)) {
- // the very end at the very beginning
- if (GetLinebreaks(cell))
- os << "\\smallskip{}}";
- if (IsMultiColumn(cell))
- os << '}';
- if (GetRotateCell(cell)) {
- os << "\n\\end{sideways}";
- ++ret;
- }
- os << "\\\\\n";
- ++ret;
-
- tmp = 0;
- fcell = cell;
- while (!IsFirstCellInRow(fcell)) --fcell;
- for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
- if (BottomLine(fcell + i))
- ++tmp;
- }
- if (tmp == NumberOfCellsInRow(fcell)) {
- os << "\\hline ";
- } else {
- tmp = 0;
- for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
- if (BottomLine(fcell + i)) {
- os << "\\cline{"
- << column_of_cell(fcell + i) + 1
- << '-'
- << right_column_of_cell(fcell + i) + 1
- << "} ";
- tmp = 1;
- }
- }
- }
- if (tmp){
- os << '\n';
- ++ret;
- }
- if (is_long_tabular)
- os << "\\end{longtable}";
- else
- os << "\\end{tabular}";
- if (rotate) {
- os << "\n\\end{sideways}";
- ++ret;
- }
- } else {
- nvcell = cell + 1;
- if (cell < 0){
- // preamble
- if (rotate) {
- os << "\\begin{sideways}\n";
- ++ret;
- }
- if (is_long_tabular)
- os << "\\begin{longtable}{";
- else
- os << "\\begin{tabular}{";
- for (i = 0; i < columns_; ++i) {
- if (column_info[i].left_line)
- os << '|';
- if (!column_info[i].align_special.empty()) {
- os << column_info[i].align_special;
- } else if (!column_info[i].p_width.empty()) {
- os << "p{"
- << column_info[i].p_width
- << '}';
- } else {
- switch (column_info[i].alignment) {
- case LYX_ALIGN_LEFT:
- os << 'l';
- break;
- case LYX_ALIGN_RIGHT:
- os << 'r';
- break;
- default:
- os << 'c';
- break;
- }
- }
- if (column_info[i].right_line)
- os << '|';
- }
- os << "}\n";
- ++ret;
- tmp = 0;
- if (GetNumberOfCells()) {
- fcell = 0;
- for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
- if (TopLine(fcell + i))
- ++tmp;
- }
- if (tmp == NumberOfCellsInRow(fcell)){
- os << "\\hline ";
- } else {
- tmp = 0;
- for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
- if (TopLine(fcell + i)) {
- os << "\\cline{"
- << column_of_cell(fcell + i) + 1
- << '-'
- << right_column_of_cell(fcell + i) + 1
- << "} ";
- tmp = 1;
- }
- }
- }
- if (tmp){
- os << '\n';
- ++ret;
- }
- }
- if (GetRotateCell(0)) {
- os << "\\begin{sideways}\n";
- ++ret;
- }
- } else {
- // usual cells
- if (GetLinebreaks(cell))
- os << "\\smallskip{}}";
- if (IsMultiColumn(cell)){
- os << '}';
- }
- if (GetRotateCell(cell)) {
- os << "\n\\end{sideways}";
- ++ret;
- }
- if (IsLastCellInRow(cell)) {
- int row = row_of_cell(cell);
- string hline1, hline2;
- bool print_hline = true;
- bool flag1 = IsLongTabular() &&
- ((row == endhead) || (row == endfirsthead) ||
- (row == endfoot) || (row == endlastfoot));
- ++row;
- bool flag2 = IsLongTabular() &&
- ((row <= endhead) || (row <= endfirsthead) ||
- (row <= endfoot) || (row <= endlastfoot));
- --row;
- // print the bottom hline only if (otherwise it is doubled):
- // - is no LongTabular
- // - there IS a first-header
- // - the next row is no special header/footer
- // & this row is no special header/footer
- // - the next row is a special header/footer
- // & this row is a special header/footer
- bool pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
- (endfirsthead == endhead);
- os << "\\\\\n";
- ++ret;
- tmp = 0;
- fcell = cell;
- while (!IsFirstCellInRow(fcell))
- --fcell;
- for (i = 0; i < NumberOfCellsInRow(cell); ++i) {
- if (BottomLine(fcell + i))
- ++tmp;
- }
- if (tmp == NumberOfCellsInRow(cell)){
- os << "\\hline ";
- hline1 = "\\hline ";
- } else {
- tmp = 0;
- for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
- if (BottomLine(fcell + i)){
- os << "\\cline{"
- << column_of_cell(fcell + i) + 1
- << '-'
- << right_column_of_cell(fcell + i) + 1
- << "} ";
- hline1 += "\\cline{";
- hline1 += tostr(column_of_cell(fcell + i) + 1);
- hline1 += '-';
- hline1 += tostr(right_column_of_cell(fcell + i) + 1);
- hline1 += "} ";
- tmp = 1;
- }
- }
- }
- if (tmp){
- os << '\n';
- ++ret;
- }
- if (IsLongTabular() && (row == endfoot)) {
- os << "\\endfoot\n";
- ++ret;
- print_hline = false; // no double line below footer
- }
- if (IsLongTabular() && (row == endlastfoot)) {
- os << "\\endlastfoot\n";
- ++ret;
- print_hline = false; // no double line below footer
- }
- if (IsLongTabular() && row_info[row].newpage) {
- os << "\\newpage\n";
- ++ret;
- print_hline = false; // no line below a \\newpage-command
- }
- tmp = 0;
- if ((nvcell < numberofcells) &&
- (cell < GetNumberOfCells() - 1) && !IsLastCell(cell)) {
- fcell = nvcell;
- for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
- if (TopLine(fcell + i))
- ++tmp;
- }
- if (tmp == NumberOfCellsInRow(fcell)) {
- if (print_hline)
- os << "\\hline ";
- hline2 = "\\hline ";
- } else {
- tmp = 0;
- for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
- if (TopLine(fcell + i)) {
- if (print_hline) {
- os << "\\cline{"
- << column_of_cell(fcell + i) + 1
- << '-'
- << right_column_of_cell(fcell + i) + 1
- << "} ";
- }
- hline2 += "\\cline{";
- hline2 += tostr(column_of_cell(fcell+i)+1);
- hline2 += '-';
- hline2 += tostr(right_column_of_cell(fcell+i)+1);
- hline2 += "} ";
- tmp = 1;
- }
- }
- }
- if (tmp && print_hline){
- os << '\n';
- ++ret;
- }
- }
- // the order here is important as if one defines two
- // or more things in one line only the first entry is
- // displayed the other are set to an empty-row. This
- // is important if I have a footer and want that the
- // lastfooter is NOT displayed!!!
- bool sflag2 = (row == endhead) || (row == endfirsthead) ||
- (row == endfoot) || (row == endlastfoot);
- --row;
- row += 2;
- bool sflag1 = IsLongTabular() && (row != endhead) &&
- (row != endfirsthead) &&
- ((row == endfoot) || (row == endlastfoot));
- --row;
- if (IsLongTabular() && (row == endhead)) {
- os << "\\endhead\n";
- ++ret;
- }
- if (IsLongTabular() && (row == endfirsthead)) {
- os << "\\endfirsthead\n";
- ++ret;
- }
- if (sflag1) { // add the \hline for next foot row
- if (!hline1.empty()) {
- os << hline1 + '\n';
- ++ret;
- }
- }
- // add the \hline for the first row
- if (pr_top_hline && sflag2) {
- if (!hline2.empty()) {
- os << hline2 + '\n';
- ++ret;
- }
- }
- if (nvcell < numberofcells && GetRotateCell(nvcell)) {
- os << "\\begin{sideways}\n";
- ++ret;
- }
- } else {
- os << "&\n";
- ++ret;
- if (nvcell < numberofcells && GetRotateCell(nvcell)) {
- os << "\\begin{sideways}\n";
- ++ret;
- }
- }
- }
- if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
- os << "\\multicolumn{"
- << cells_in_multicolumn(nvcell)
- << "}{";
- if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
- os << cellinfo_of_cell(cell+1)->align_special
- << "}{";
- } else {
- if (LeftLine(nvcell))
- os << '|';
- if (!GetPWidth(nvcell).empty()) {
- os << "p{"
- << GetPWidth(nvcell)
- << '}';
- } else {
- switch (GetAlignment(nvcell)) {
- case LYX_ALIGN_LEFT: os << 'l'; break;
- case LYX_ALIGN_RIGHT: os << 'r'; break;
- default: os << 'c'; break;
- }
- }
- if (RightLine(nvcell))
- os << '|';
- //if (column_of_cell(cell+2)!= 0 && LeftLine(cell+2))
- if (((nvcell + 1) < numberofcells) &&
- ((nvcell+1) < numberofcells) &&
- (column_of_cell(nvcell+1)!= 0) &&
- LeftLine(nvcell+1))
- os << '|';
-
- os << "}{";
- }
- }
- if (nvcell < numberofcells && GetLinebreaks(nvcell)) {
- os << "\\parbox[t]{"
- << GetPWidth(nvcell)
- << "}{\\smallskip{}";
- }
- }
- return ret;