- } else {
- is >> rows_arg >> columns_arg >> is_long_tabular_arg
- >> rotate_arg >> a >> b >> c >> d;
- Init(rows_arg, columns_arg);
- cont_row_info = vector<int>(rows_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;
- cont_row_info[i] = 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].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();
-
- LyXParagraph * par = new LyXParagraph;
- LyXParagraph * return_par = 0;
- LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
- LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
- string token, tmptok;
- int pos = 0;
- char depth = 0;
- LyXFont font(LyXFont::ALL_SANE);
-
- while (lex.IsOK()) {
- lex.nextToken();
- token = lex.GetString();
- if (token.empty())
- continue;
- if ((token == "\\layout") || (token == "\\end_float") ||
- (token == "\\end_deeper"))
- {
- lex.pushToken(token);
- break;
- }
- if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
- return_par,
- token, pos,
- depth, font,
- footnoteflag,
- footnotekind))
- {
- // the_end read
- lex.pushToken(token);
- break;
- }
- if (return_par) {
- lex.printError("New Paragraph allocated! This should not happen!");
- lex.pushToken(token);
- delete par;
- par = return_par;
- break;
- }
- }
- // now we have the par we should fill the insets with this!
- int cell = 0;
- InsetText * inset = GetCellInset(cell);
- int row;
-
- for(int i = 0; i < par->Last(); ++i) {
- if (par->IsNewline(i)) {
- ++cell;
- if (cell > GetNumberOfCells()) {
- lyxerr << "Some error in reading old table format occured!" <<
- endl << "Terminating when reading cell[" << cell << "]!" <<
- endl;
- return;
- }
- row = row_of_cell(cell);
- if (cont_row_info[row]) {
- DeleteRow(row);
- cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
- while(!IsFirstCellInRow(--cell));
- } else {
- inset = GetCellInset(cell);
- continue;
- }
- inset = GetCellInset(cell);
- row = row_of_cell(cell);
- if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].linebreaks)
- {
- // insert a space instead
- par->Erase(i);
- par->InsertChar(i, ' ');
- }
- }
- par->CopyIntoMinibuffer(current_view->buffer()->params, i);
- inset->par->InsertFromMinibuffer(inset->par->Last());
- }
- Reinit();
-}
-
-
-char const * LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
-{
- int i = isColumn ? cell : column_of_cell(cell);
-
- //if (isColumn)
- //i = cell;
- //else
- //i = column_of_cell(cell);
- if (!isColumn && IsMultiColumn(cell)) {
- if (!cellinfo_of_cell(cell)->align_special.empty()) {
- return cellinfo_of_cell(cell)->align_special.c_str();
- } else {
- switch (GetAlignment(cell)) {
- case LYX_ALIGN_LEFT:
- return "left";
- case LYX_ALIGN_RIGHT:
- return "right";
- default:
- return "center";
- }
- }
- } else {
- if (!column_info[i].align_special.empty()) {
- return column_info[i].align_special.c_str();
- }
-#ifdef IGNORE_THIS_FOR_NOW
- else if (!column_info[i].p_width.empty()) {
- file += "p{";
- file += column_info[i].p_width;
- file += '}';
- }
-#endif
- else {
- switch (column_info[i].alignment) {
- case LYX_ALIGN_LEFT:
- return "left";
- case LYX_ALIGN_RIGHT:
- return "right";
- default:
- return "center";
- }
- }
- }
-}
-
-
-// cell <0 will tex the preamble
-// returns the number of printed newlines
-int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
-{
- int i;
- int ret = 0;
- //int tmp; // tmp2; // unused
- int nvcell; // fcell; // unused
- if (IsLastCell(cell)) {
- os << newlineAndDepth(--depth)
- << "</ENTRY>"
- << newlineAndDepth(--depth)
- << "</ROW>"
- << newlineAndDepth(--depth)
- << "</TBODY>"
- << newlineAndDepth(--depth);
- if (is_long_tabular)
- os << "</TGROUP>";
- else
- os << "</TGROUP>"
- << newlineAndDepth(--depth);
- ret += 4;
- } else {
- nvcell = cell + 1;
- if (cell < 0) {
- // preamble
- if (is_long_tabular)
- os << "<TGROUP ";
- else
- os << "<TGROUP ";
- os << "COLS='"
- << columns_
- << "' COLSEP='1' ROWSEP='1'>"
- << newlineAndDepth(++depth);
- ++ret;
- for (i = 0; i < columns_; ++i) {
- os << "<COLSPEC ALIGN='"
- << GetDocBookAlign(i, true)
- << "' COLNAME='col"
- << i + 1
- << "' COLNUM='"
- << i + 1
- << "' COLSEP='";
- if (i == (columns_-1)) {
- os << '1';
- } else {
- if (column_info[i].right_line ||
- column_info[i+1].left_line)
- os << '1';
- else
- os << '0';
- }
- os << "'>"
- << newlineAndDepth(depth);
- ++ret;
-#ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
- if (column_info[i].left_line)
- os << '|';
-#endif
- }
- os << "<TBODY>"
- << newlineAndDepth(++depth)
- << "<ROW>"
- << newlineAndDepth(++depth)
- << "<ENTRY ALIGN='"
- << GetDocBookAlign(0)
- << "'";
- if (IsMultiColumn(0)) {
- os << " NAMEST='col1' NAMEEND='col"
- << cells_in_multicolumn(0)
- << "'";
- }
- os << ">"
- << newlineAndDepth(++depth);
- ret += 3;
- } else {
- if (IsLastCellInRow(cell)) {
- os << newlineAndDepth(--depth)
- << "</ENTRY>"
- << newlineAndDepth(--depth)
- << "</ROW>"
- << newlineAndDepth(depth)
- << "<ROW>"
- << newlineAndDepth(++depth)
- << "<ENTRY ALIGN='"
- << GetDocBookAlign(cell + 1)
- << "' VALIGN='middle'";
- if (IsMultiColumn(cell + 1)) {
- os << " NAMEST='col"
- << column_of_cell(cell+1) + 1
- << "' NAMEEND='col"
- << column_of_cell(cell + 1) +
- cells_in_multicolumn(cell + 1)
- << "'";
- }
- os << ">"
- << newlineAndDepth(++depth);
- ret += 4;
- } else {
- os << newlineAndDepth(--depth)
- << "</ENTRY>"
- << newlineAndDepth(depth)
- << "<ENTRY ALIGN='"
- << GetDocBookAlign(cell + 1)
- << "' VALIGN='middle'";
- if (IsMultiColumn(cell + 1)) {
- os << " NAMEST='col"
- << column_of_cell(cell+1) + 1
- << "' NAMEEND='col"
- << column_of_cell(cell+1) +
- cells_in_multicolumn(cell+1)
- << "'";
- }
- os << ">"
- << newlineAndDepth(++depth);
- ret += 3;
- }
- }
- }
- return ret;
-}
-
-
-bool LyXTabular::IsMultiColumn(int cell) const
-{
- return (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL);