3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
19 #include "support/lassert.h"
20 #include "support/convert.h"
21 #include "support/lstrings.h"
32 // filled in preamble.cpp
33 map<char, int> special_columns;
40 ColInfo() : align('n'), valign('n'), rightlines(0), leftlines(0) {}
43 /// vertical alignment
47 /// special column alignment
49 /// number of lines on the right
51 /// number of lines on the left
56 /// row type for longtables
63 /// part of head on first page
67 /// part of foot on last page
74 RowInfo() : topline(false), bottomline(false), type(LT_NORMAL),
75 caption(false), newpage(false) {}
76 /// horizontal line above
78 /// horizontal line below
80 /// These are for longtabulars only
81 /// row type (head, foot, firsthead etc.)
90 /// the numeric values are part of the file format!
94 /// A multicolumn cell. The number of columns is <tt>1 + number
95 /// of CELL_PART_OF_MULTICOLUMN cells</tt> that follow directly
96 CELL_BEGIN_OF_MULTICOLUMN = 1,
97 /// This is a dummy cell (part of a multicolumn cell)
98 CELL_PART_OF_MULTICOLUMN = 2
104 CellInfo() : multi(CELL_NORMAL), align('n'), valign('n'),
105 leftlines(0), rightlines(0), topline(false),
106 bottomline(false), rotate(false) {}
113 /// vertical cell alignment
115 /// number of lines on the left
117 /// number of lines on the right
119 /// do we have a line above?
121 /// do we have a line below?
123 /// is the cell rotated?
125 /// width for multicolumn cells
127 /// special formatting for multicolumn cells
132 /// translate a horizontal alignment (as stored in ColInfo and CellInfo) to LyX
133 inline char const * verbose_align(char c)
148 /// translate a vertical alignment (as stored in ColInfo and CellInfo) to LyX
149 inline char const * verbose_valign(char c)
151 // The default value for no special alignment is "top".
164 // stripped down from tabluar.C. We use it currently only for bools and
166 string const write_attribute(string const & name, bool const & b)
168 // we write only true attribute values so we remove a bit of the
169 // file format bloat for tabulars.
170 return b ? ' ' + name + "=\"true\"" : string();
174 string const write_attribute(string const & name, string const & s)
176 return s.empty() ? string() : ' ' + name + "=\"" + s + '"';
180 /*! rather brutish way to code table structure in a string:
185 \multicolumn{2}{c}{4} & 5 //
191 gets "translated" to:
194 HLINE 1 TAB 2 TAB 3 HLINE HLINE LINE
195 \hline HLINE \multicolumn{2}{c}{4} TAB 5 HLINE HLINE LINE
196 HLINE 6 TAB 7 HLINE HLINE LINE
197 HLINE 8 HLINE \endhead HLINE LINE
201 char const TAB = '\001';
202 char const LINE = '\002';
203 char const HLINE = '\004';
207 * Move the information in leftlines, rightlines, align and valign to the
208 * special field. This is necessary if the special field is not empty,
209 * because LyX ignores leftlines > 1, rightlines > 1, align and valign in
212 void ci2special(ColInfo & ci)
214 if (ci.width.empty() && ci.align == 'n')
215 // The alignment setting is already in special, since
216 // handle_colalign() never stores ci with these settings
217 // and ensures that leftlines == 0 and rightlines == 0 in
221 if (!ci.width.empty()) {
224 ci.special += ">{\\raggedright}";
227 ci.special += ">{\\raggedleft}";
230 ci.special += ">{\\centering}";
233 if (ci.valign == 'n')
236 ci.special += ci.valign;
237 ci.special += '{' + ci.width + '}';
240 ci.special += ci.align;
242 // LyX can only have one left and one right line.
243 for (int i = 1; i < ci.leftlines; ++i)
244 ci.special.insert(0, "|");
245 for (int i = 1; i < ci.rightlines; ++i)
247 ci.leftlines = min(ci.leftlines, 1);
248 ci.rightlines = min(ci.rightlines, 1);
255 * Handle column specifications for tabulars and multicolumns.
256 * The next token of the parser \p p must be an opening brace, and we read
257 * everything until the matching closing brace.
258 * The resulting column specifications are filled into \p colinfo. This is
259 * in an intermediate form. fix_colalign() makes it suitable for LyX output.
261 void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
262 ColInfo const & start)
264 if (p.get_token().cat() != catBegin)
265 cerr << "Wrong syntax for table column alignment.\n"
266 "Expected '{', got '" << p.curr_token().asInput()
269 ColInfo next = start;
270 for (Token t = p.get_token(); p.good() && t.cat() != catEnd;
273 cerr << "t: " << t << " c: '" << t.character() << "'\n";
276 // We cannot handle comments here
277 if (t.cat() == catComment) {
278 if (t.cs().empty()) {
282 cerr << "Ignoring comment: " << t.asInput();
286 switch (t.character()) {
290 // new column, horizontal aligned
291 next.align = t.character();
292 if (!next.special.empty())
294 colinfo.push_back(next);
300 // new column, vertical aligned box
301 next.valign = t.character();
302 next.width = p.verbatim_item();
303 if (!next.special.empty())
305 colinfo.push_back(next);
310 if (colinfo.empty()) {
311 if (next.special.empty())
315 } else if (colinfo.back().special.empty())
316 ++colinfo.back().rightlines;
317 else if (next.special.empty())
320 colinfo.back().special += '|';
323 // text before the next column
324 string const s = trimSpaceAndEol(p.verbatim_item());
325 if (next.special.empty() &&
327 // Maybe this can be converted to a
328 // horizontal alignment setting for
329 // fixed width columns
330 if (s == "\\raggedleft")
332 else if (s == "\\raggedright")
334 else if (s == "\\centering")
337 next.special = ">{" + s + '}';
339 next.special += ">{" + s + '}';
343 // text after the last column
344 string const s = trimSpaceAndEol(p.verbatim_item());
346 // This is not possible in LaTeX.
347 cerr << "Ignoring separator '<{"
348 << s << "}'." << endl;
350 ColInfo & ci = colinfo.back();
352 ci.special += "<{" + s + '}';
357 // *{n}{arg} means 'n' columns of type 'arg'
358 string const num = p.verbatim_item();
359 string const arg = p.verbatim_item();
360 size_t const n = convert<unsigned int>(num);
361 if (!arg.empty() && n > 0) {
363 for (size_t i = 0; i < n; ++i)
367 handle_colalign(p2, colinfo, next);
370 cerr << "Ignoring column specification"
371 " '*{" << num << "}{"
372 << arg << "}'." << endl;
377 // text instead of the column spacing
379 // text in addition to the column spacing
380 next.special += t.character();
381 next.special += '{' + p.verbatim_item() + '}';
384 // try user defined column types
385 if (special_columns.find(t.character()) !=
386 special_columns.end()) {
388 next.special += t.character();
390 special_columns[t.character()];
391 for (int i = 0; i < nargs; ++i)
392 next.special += '{' +
395 colinfo.push_back(next);
398 cerr << "Ignoring column specification"
399 " '" << t << "'." << endl;
404 // Maybe we have some column separators that need to be added to the
407 if (!next.special.empty()) {
408 ColInfo & ci = colinfo.back();
410 ci.special += next.special;
411 next.special.erase();
417 * Move the left and right lines and alignment settings of the column \p ci
418 * to the special field if necessary.
420 void fix_colalign(ColInfo & ci)
422 if (ci.leftlines > 1 || ci.rightlines > 1)
428 * LyX can't handle more than one vertical line at the left or right side
430 * This function moves the left and right lines and alignment settings of all
431 * columns in \p colinfo to the special field if necessary.
433 void fix_colalign(vector<ColInfo> & colinfo)
435 // Try to move extra leftlines to the previous column.
436 // We do this only if both special fields are empty, otherwise we
437 // can't tell wether the result will be the same.
438 for (size_t col = 0; col < colinfo.size(); ++col) {
439 if (colinfo[col].leftlines > 1 &&
440 colinfo[col].special.empty() && col > 0 &&
441 colinfo[col - 1].rightlines == 0 &&
442 colinfo[col - 1].special.empty()) {
443 ++colinfo[col - 1].rightlines;
444 --colinfo[col].leftlines;
447 // Try to move extra rightlines to the next column
448 for (size_t col = 0; col < colinfo.size(); ++col) {
449 if (colinfo[col].rightlines > 1 &&
450 colinfo[col].special.empty() &&
451 col < colinfo.size() - 1 &&
452 colinfo[col + 1].leftlines == 0 &&
453 colinfo[col + 1].special.empty()) {
454 ++colinfo[col + 1].leftlines;
455 --colinfo[col].rightlines;
458 // Move the lines and alignment settings to the special field if
460 for (size_t col = 0; col < colinfo.size(); ++col)
461 fix_colalign(colinfo[col]);
466 * Parse hlines and similar stuff.
467 * \returns wether the token \p t was parsed
469 bool parse_hlines(Parser & p, Token const & t, string & hlines,
470 bool is_long_tabular)
472 LASSERT(t.cat() == catEscape, return false);
474 if (t.cs() == "hline")
477 else if (t.cs() == "cline")
478 hlines += "\\cline{" + p.verbatim_item() + '}';
480 else if (is_long_tabular && t.cs() == "newpage")
481 hlines += "\\newpage";
490 /// Position in a row
492 /// At the very beginning, before the first token
494 /// After the first token and before any column token
496 /// After the first column token. Comments and whitespace are only
497 /// treated as tokens in this position
499 /// After the first non-column token at the end
505 * Parse table structure.
506 * We parse tables in a two-pass process: This function extracts the table
507 * structure (rows, columns, hlines etc.), but does not change the cell
508 * content. The cell content is parsed in a second step in handle_tabular().
510 void parse_table(Parser & p, ostream & os, bool is_long_tabular,
511 RowPosition & pos, unsigned flags)
513 // table structure commands such as \hline
516 // comments that occur at places where we can't handle them
520 Token const & t = p.get_token();
523 debugToken(cerr, t, flags);
526 // comments and whitespace in hlines
529 case IN_HLINES_START:
531 if (t.cat() == catComment) {
536 // We can't handle comments here,
537 // store them for later use
538 comments += t.asInput();
540 } else if (t.cat() == catSpace ||
541 t.cat() == catNewline) {
542 // whitespace is irrelevant here, we
543 // need to recognize hline stuff
552 // We need to handle structure stuff first in order to
553 // determine wether we need to output a HLINE separator
554 // before the row or not.
555 if (t.cat() == catEscape) {
556 if (parse_hlines(p, t, hlines, is_long_tabular)) {
559 pos = IN_HLINES_START;
564 case IN_HLINES_START:
571 else if (t.cs() == "tabularnewline" ||
575 cerr << "Warning: Converting TeX "
576 "'\\cr' to LaTeX '\\\\'."
578 // stuff before the line break
579 os << comments << HLINE << hlines << HLINE
581 //cerr << "hlines: " << hlines << endl;
588 else if (is_long_tabular &&
589 (t.cs() == "endhead" ||
590 t.cs() == "endfirsthead" ||
591 t.cs() == "endfoot" ||
592 t.cs() == "endlastfoot")) {
593 hlines += t.asInput();
597 // these commands are implicit line
599 os << comments << HLINE << hlines
606 pos = IN_HLINES_START;
608 case IN_HLINES_START:
616 // We need a HLINE separator if we either have no hline
617 // stuff at all and are just starting a row or if we just
618 // got the first non-hline token.
621 // no hline tokens exist, first token at row start
622 case IN_HLINES_START:
623 // hline tokens exist, first non-hline token at row
625 os << hlines << HLINE << comments;
631 // Oops, there is still cell content after hline
632 // stuff. This does not work in LaTeX, so we ignore
634 cerr << "Ignoring '" << hlines << "' in a cell"
645 // If we come here we have normal cell content
649 if (t.cat() == catMath) {
650 // we are inside some text mode thingy, so opening new math is allowed
651 Token const & n = p.get_token();
652 if (n.cat() == catMath) {
653 // TeX's $$...$$ syntax for displayed math
655 // This does only work because parse_math outputs TeX
656 parse_math(p, os, FLAG_SIMPLE, MATH_MODE);
658 p.get_token(); // skip the second '$' token
660 // simple $...$ stuff
663 // This does only work because parse_math outputs TeX
664 parse_math(p, os, FLAG_SIMPLE, MATH_MODE);
669 else if (t.cat() == catSpace
670 || t.cat() == catNewline
671 || t.cat() == catLetter
672 || t.cat() == catSuper
674 || t.cat() == catOther
675 || t.cat() == catActive
676 || t.cat() == catParameter)
679 else if (t.cat() == catBegin) {
681 parse_table(p, os, is_long_tabular, pos,
686 else if (t.cat() == catEnd) {
687 if (flags & FLAG_BRACE_LAST)
689 cerr << "unexpected '}'\n";
692 else if (t.cat() == catAlign) {
697 else if (t.cat() == catComment)
700 else if (t.cs() == "(") {
702 // This does only work because parse_math outputs TeX
703 parse_math(p, os, FLAG_SIMPLE2, MATH_MODE);
707 else if (t.cs() == "[") {
709 // This does only work because parse_math outputs TeX
710 parse_math(p, os, FLAG_EQUATION, MATH_MODE);
714 else if (t.cs() == "begin") {
715 string const name = p.getArg('{', '}');
716 active_environments.push_back(name);
717 os << "\\begin{" << name << '}';
718 // treat the nested environment as a block, don't
719 // parse &, \\ etc, because they don't belong to our
720 // table if they appear.
721 os << p.verbatimEnvironment(name);
722 os << "\\end{" << name << '}';
723 active_environments.pop_back();
726 else if (t.cs() == "end") {
727 if (flags & FLAG_END) {
728 // eat environment name
729 string const name = p.getArg('{', '}');
730 if (name != active_environment())
731 p.error("\\end{" + name + "} does not match \\begin{"
732 + active_environment() + "}");
735 p.error("found 'end' unexpectedly");
742 // We can have comments if the last line is incomplete
745 // We can have hline stuff if the last line is incomplete
746 if (!hlines.empty()) {
747 // this does not work in LaTeX, so we ignore it
748 cerr << "Ignoring '" << hlines << "' at end of tabular"
754 void handle_hline_above(RowInfo & ri, vector<CellInfo> & ci)
757 for (size_t col = 0; col < ci.size(); ++col)
758 ci[col].topline = true;
762 void handle_hline_below(RowInfo & ri, vector<CellInfo> & ci)
764 ri.bottomline = true;
765 for (size_t col = 0; col < ci.size(); ++col)
766 ci[col].bottomline = true;
770 } // anonymous namespace
773 void handle_tabular(Parser & p, ostream & os, string const & name,
774 string const & tabularwidth, Context & context)
776 bool const is_long_tabular(name == "longtable");
777 string tabularvalignment("middle");
778 string posopts = p.getOpt();
779 if (!posopts.empty()) {
780 // FIXME: Convert this to ERT
782 cerr << "horizontal longtable positioning '"
783 << posopts << "' ignored\n";
784 else if (posopts == "[t]")
785 tabularvalignment = "top";
786 else if (posopts == "[b]")
787 tabularvalignment = "bottom";
789 cerr << "vertical tabular positioning '"
790 << posopts << "' ignored\n";
793 vector<ColInfo> colinfo;
795 // handle column formatting
796 handle_colalign(p, colinfo, ColInfo());
797 fix_colalign(colinfo);
799 // first scan of cells
800 // use table mode to keep it minimal-invasive
801 // not exactly what's TeX doing...
802 vector<string> lines;
804 RowPosition rowpos = ROW_START;
805 parse_table(p, ss, is_long_tabular, rowpos, FLAG_END);
806 split(ss.str(), lines, LINE);
808 vector< vector<CellInfo> > cellinfo(lines.size());
809 vector<RowInfo> rowinfo(lines.size());
812 //cerr << "// split into rows\n";
813 for (size_t row = 0; row < rowinfo.size(); ++row) {
816 cellinfo[row].resize(colinfo.size());
819 vector<string> dummy;
820 //cerr << "\n########### LINE: " << lines[row] << "########\n";
821 split(lines[row], dummy, HLINE);
823 // handle horizontal line fragments
824 // we do only expect this for a last line without '\\'
825 if (dummy.size() != 3) {
826 if ((dummy.size() != 1 && dummy.size() != 2) ||
827 row != rowinfo.size() - 1)
828 cerr << "unexpected dummy size: " << dummy.size()
829 << " content: " << lines[row] << "\n";
832 lines[row] = dummy[1];
834 //cerr << "line: " << row << " above 0: " << dummy[0] << "\n";
835 //cerr << "line: " << row << " below 2: " << dummy[2] << "\n";
836 //cerr << "line: " << row << " cells 1: " << dummy[1] << "\n";
838 for (int i = 0; i <= 2; i += 2) {
839 //cerr << " reading from line string '" << dummy[i] << "'\n";
842 Token t = p1.get_token();
843 //cerr << "read token: " << t << "\n";
844 if (t.cs() == "hline") {
846 if (rowinfo[row].topline) {
847 if (row > 0) // extra bottomline above
848 handle_hline_below(rowinfo[row - 1], cellinfo[row - 1]);
850 cerr << "dropping extra hline\n";
851 //cerr << "below row: " << row-1 << endl;
853 handle_hline_above(rowinfo[row], cellinfo[row]);
854 //cerr << "above row: " << row << endl;
857 //cerr << "below row: " << row << endl;
858 handle_hline_below(rowinfo[row], cellinfo[row]);
860 } else if (t.cs() == "cline") {
861 string arg = p1.verbatim_item();
862 //cerr << "read cline arg: '" << arg << "'\n";
866 size_t from = convert<unsigned int>(t[0]);
868 cerr << "Could not parse "
869 "cline start column."
872 // 1 based index -> 0 based
874 if (from >= colinfo.size()) {
875 cerr << "cline starts at non "
877 << (from + 1) << endl;
878 from = colinfo.size() - 1;
880 size_t to = convert<unsigned int>(t[1]);
882 cerr << "Could not parse "
886 // 1 based index -> 0 based
888 if (to >= colinfo.size()) {
889 cerr << "cline ends at non "
892 to = colinfo.size() - 1;
894 for (size_t col = from; col <= to; ++col) {
895 //cerr << "row: " << row << " col: " << col << " i: " << i << endl;
897 rowinfo[row].topline = true;
898 cellinfo[row][col].topline = true;
900 rowinfo[row].bottomline = true;
901 cellinfo[row][col].bottomline = true;
904 } else if (t.cs() == "endhead") {
906 rowinfo[row].type = LT_HEAD;
907 for (int r = row - 1; r >= 0; --r) {
908 if (rowinfo[r].type != LT_NORMAL)
910 rowinfo[r].type = LT_HEAD;
912 } else if (t.cs() == "endfirsthead") {
914 rowinfo[row].type = LT_FIRSTHEAD;
915 for (int r = row - 1; r >= 0; --r) {
916 if (rowinfo[r].type != LT_NORMAL)
918 rowinfo[r].type = LT_FIRSTHEAD;
920 } else if (t.cs() == "endfoot") {
922 rowinfo[row].type = LT_FOOT;
923 for (int r = row - 1; r >= 0; --r) {
924 if (rowinfo[r].type != LT_NORMAL)
926 rowinfo[r].type = LT_FOOT;
928 } else if (t.cs() == "endlastfoot") {
930 rowinfo[row].type = LT_LASTFOOT;
931 for (int r = row - 1; r >= 0; --r) {
932 if (rowinfo[r].type != LT_NORMAL)
934 rowinfo[r].type = LT_LASTFOOT;
936 } else if (t.cs() == "newpage") {
939 rowinfo[row - 1].newpage = true;
941 // This does not work in LaTeX
947 rowinfo[row].newpage = true;
949 cerr << "unexpected line token: " << t << endl;
955 vector<string> cells;
956 split(lines[row], cells, TAB);
957 for (size_t col = 0, cell = 0; cell < cells.size();
959 //cerr << "cell content: '" << cells[cell] << "'\n";
960 if (col >= colinfo.size()) {
961 // This does not work in LaTeX
962 cerr << "Ignoring extra cell '"
963 << cells[cell] << "'." << endl;
966 Parser p(cells[cell]);
968 //cells[cell] << "'\n";
969 if (p.next_token().cs() == "multicolumn") {
972 size_t const ncells =
973 convert<unsigned int>(p.verbatim_item());
975 // special cell properties alignment
977 handle_colalign(p, t, ColInfo());
979 ColInfo & ci = t.front();
981 // The logic of LyX for multicolumn vertical
982 // lines is too complicated to reproduce it
983 // here (see LyXTabular::TeXCellPreamble()).
984 // Therefore we simply put everything in the
988 cellinfo[row][col].multi = CELL_BEGIN_OF_MULTICOLUMN;
989 cellinfo[row][col].align = ci.align;
990 cellinfo[row][col].special = ci.special;
991 cellinfo[row][col].leftlines = ci.leftlines;
992 cellinfo[row][col].rightlines = ci.rightlines;
994 parse_text_in_inset(p, os, FLAG_ITEM, false, context);
995 if (!cellinfo[row][col].content.empty()) {
996 // This may or may not work in LaTeX,
997 // but it does not work in LyX.
998 // FIXME: Handle it correctly!
999 cerr << "Moving cell content '"
1001 << "' into a multicolumn cell. "
1002 "This will probably not work."
1005 cellinfo[row][col].content += os.str();
1007 // add dummy cells for multicol
1008 for (size_t i = 0; i < ncells - 1 && col < colinfo.size(); ++i) {
1010 cellinfo[row][col].multi = CELL_PART_OF_MULTICOLUMN;
1011 cellinfo[row][col].align = 'c';
1014 } else if (col == 0 && is_long_tabular &&
1015 p.next_token().cs() == "caption") {
1016 // longtable caption support in LyX is a hack:
1017 // Captions require a row of their own with
1018 // the caption flag set to true, having only
1019 // one multicolumn cell. The contents of that
1020 // cell must contain exactly one caption inset
1021 // and nothing else.
1022 rowinfo[row].caption = true;
1023 for (size_t c = 1; c < cells.size(); ++c) {
1024 if (!cells[c].empty()) {
1025 cerr << "Moving cell content '"
1027 << "' into the caption cell. "
1028 "This will probably not work."
1030 cells[0] += cells[c];
1034 cellinfo[row][col].align = colinfo[col].align;
1035 cellinfo[row][col].multi = CELL_BEGIN_OF_MULTICOLUMN;
1037 parse_text_in_inset(p, os, FLAG_CELL, false, context);
1038 cellinfo[row][col].content += os.str();
1039 // add dummy multicolumn cells
1040 for (size_t c = 1; c < colinfo.size(); ++c)
1041 cellinfo[row][c].multi = CELL_PART_OF_MULTICOLUMN;
1044 cellinfo[row][col].leftlines = colinfo[col].leftlines;
1045 cellinfo[row][col].rightlines = colinfo[col].rightlines;
1046 cellinfo[row][col].align = colinfo[col].align;
1048 parse_text_in_inset(p, os, FLAG_CELL, false, context);
1049 cellinfo[row][col].content += os.str();
1053 //cerr << "// handle almost empty last row what we have\n";
1054 // handle almost empty last row
1055 if (row && lines[row].empty() && row + 1 == rowinfo.size()) {
1056 //cerr << "remove empty last line\n";
1057 if (rowinfo[row].topline)
1058 rowinfo[row - 1].bottomline = true;
1059 for (size_t col = 0; col < colinfo.size(); ++col)
1060 if (cellinfo[row][col].topline)
1061 cellinfo[row - 1][col].bottomline = true;
1066 // Now we have the table structure and content in rowinfo, colinfo
1068 // Unfortunately LyX has some limitations that we need to work around.
1070 // Convert cells with special content to multicolumn cells
1071 // (LyX ignores the special field for non-multicolumn cells).
1072 for (size_t row = 0; row < rowinfo.size(); ++row) {
1073 for (size_t col = 0; col < cellinfo[row].size(); ++col) {
1074 if (cellinfo[row][col].multi == CELL_NORMAL &&
1075 !cellinfo[row][col].special.empty())
1076 cellinfo[row][col].multi = CELL_BEGIN_OF_MULTICOLUMN;
1080 // Distribute lines from rows/columns to cells
1081 // The code was stolen from convert_tablines() in lyx2lyx/lyx_1_6.py.
1082 // Each standard cell inherits the settings of the corresponding
1083 // rowinfo/colinfo. This works because all cells with individual
1084 // settings were converted to multicolumn cells above.
1085 // Each multicolumn cell inherits the settings of the rowinfo/colinfo
1086 // corresponding to the first column of the multicolumn cell (default
1087 // of the multicol package). This works because the special field
1088 // overrides the line fields.
1089 for (size_t row = 0; row < rowinfo.size(); ++row) {
1090 for (size_t col = 0; col < cellinfo[row].size(); ++col) {
1091 if (cellinfo[row][col].multi == CELL_NORMAL) {
1092 cellinfo[row][col].topline = rowinfo[row].topline;
1093 cellinfo[row][col].bottomline = rowinfo[row].bottomline;
1094 cellinfo[row][col].leftlines = colinfo[col].leftlines;
1095 cellinfo[row][col].rightlines = colinfo[col].rightlines;
1096 } else if (cellinfo[row][col].multi == CELL_BEGIN_OF_MULTICOLUMN) {
1098 while (s < cellinfo[row].size() &&
1099 cellinfo[row][s].multi == CELL_PART_OF_MULTICOLUMN)
1101 if (s < cellinfo[row].size() &&
1102 cellinfo[row][s].multi != CELL_BEGIN_OF_MULTICOLUMN)
1103 cellinfo[row][col].rightlines = colinfo[col].rightlines;
1104 if (col > 0 && cellinfo[row][col-1].multi == CELL_NORMAL)
1105 cellinfo[row][col].leftlines = colinfo[col].leftlines;
1110 //cerr << "// output what we have\n";
1111 // output what we have
1112 os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
1113 << "\" columns=\"" << colinfo.size() << "\">\n";
1115 << write_attribute("rotate", false)
1116 << write_attribute("islongtable", is_long_tabular);
1117 if (!is_long_tabular)
1118 os << write_attribute("tabularvalignment", tabularvalignment)
1119 << write_attribute("tabularwidth", tabularwidth);
1122 //cerr << "// after header\n";
1123 for (size_t col = 0; col < colinfo.size(); ++col) {
1124 os << "<column alignment=\""
1125 << verbose_align(colinfo[col].align) << "\""
1127 << verbose_valign(colinfo[col].valign) << "\""
1128 << write_attribute("width", translate_len(colinfo[col].width))
1129 << write_attribute("special", colinfo[col].special)
1132 //cerr << "// after cols\n";
1134 for (size_t row = 0; row < rowinfo.size(); ++row) {
1136 << write_attribute("endhead",
1137 rowinfo[row].type == LT_HEAD)
1138 << write_attribute("endfirsthead",
1139 rowinfo[row].type == LT_FIRSTHEAD)
1140 << write_attribute("endfoot",
1141 rowinfo[row].type == LT_FOOT)
1142 << write_attribute("endlastfoot",
1143 rowinfo[row].type == LT_LASTFOOT)
1144 << write_attribute("newpage", rowinfo[row].newpage)
1145 << write_attribute("caption", rowinfo[row].caption)
1147 for (size_t col = 0; col < colinfo.size(); ++col) {
1148 CellInfo const & cell = cellinfo[row][col];
1150 if (cell.multi != CELL_NORMAL)
1151 os << " multicolumn=\"" << cell.multi << "\"";
1152 os << " alignment=\"" << verbose_align(cell.align)
1154 << " valignment=\"" << verbose_valign(cell.valign)
1156 << write_attribute("topline", cell.topline)
1157 << write_attribute("bottomline", cell.bottomline)
1158 << write_attribute("leftline", cell.leftlines > 0)
1159 << write_attribute("rightline", cell.rightlines > 0)
1160 << write_attribute("rotate", cell.rotate);
1161 //cerr << "\nrow: " << row << " col: " << col;
1163 // cerr << " topline=\"true\"";
1164 //if (cell.bottomline)
1165 // cerr << " bottomline=\"true\"";
1166 os << " usebox=\"none\""
1167 << write_attribute("width", translate_len(cell.width));
1168 if (cell.multi != CELL_NORMAL)
1169 os << write_attribute("special", cell.special);
1171 << "\n\\begin_inset Text\n"
1173 << "\n\\end_inset\n"
1179 os << "</lyxtabular>\n";