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 = trim(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 = trim(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 cerr << "t: " << t << " flags: " << flags << "\n";
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, bool is_long_tabular,
776 string posopts = p.getOpt();
777 if (!posopts.empty()) {
778 // FIXME: Convert this to ERT
780 cerr << "horizontal longtable";
782 cerr << "vertical tabular";
783 cerr << " positioning '" << posopts << "' ignored\n";
786 vector<ColInfo> colinfo;
788 // handle column formatting
789 handle_colalign(p, colinfo, ColInfo());
790 fix_colalign(colinfo);
792 // first scan of cells
793 // use table mode to keep it minimal-invasive
794 // not exactly what's TeX doing...
795 vector<string> lines;
797 RowPosition rowpos = ROW_START;
798 parse_table(p, ss, is_long_tabular, rowpos, FLAG_END);
799 split(ss.str(), lines, LINE);
801 vector< vector<CellInfo> > cellinfo(lines.size());
802 vector<RowInfo> rowinfo(lines.size());
805 //cerr << "// split into rows\n";
806 for (size_t row = 0; row < rowinfo.size(); ++row) {
809 cellinfo[row].resize(colinfo.size());
812 vector<string> dummy;
813 //cerr << "\n########### LINE: " << lines[row] << "########\n";
814 split(lines[row], dummy, HLINE);
816 // handle horizontal line fragments
817 // we do only expect this for a last line without '\\'
818 if (dummy.size() != 3) {
819 if ((dummy.size() != 1 && dummy.size() != 2) ||
820 row != rowinfo.size() - 1)
821 cerr << "unexpected dummy size: " << dummy.size()
822 << " content: " << lines[row] << "\n";
825 lines[row] = dummy[1];
827 //cerr << "line: " << row << " above 0: " << dummy[0] << "\n";
828 //cerr << "line: " << row << " below 2: " << dummy[2] << "\n";
829 //cerr << "line: " << row << " cells 1: " << dummy[1] << "\n";
831 for (int i = 0; i <= 2; i += 2) {
832 //cerr << " reading from line string '" << dummy[i] << "'\n";
835 Token t = p1.get_token();
836 //cerr << "read token: " << t << "\n";
837 if (t.cs() == "hline") {
839 if (rowinfo[row].topline) {
840 if (row > 0) // extra bottomline above
841 handle_hline_below(rowinfo[row - 1], cellinfo[row - 1]);
843 cerr << "dropping extra hline\n";
844 //cerr << "below row: " << row-1 << endl;
846 handle_hline_above(rowinfo[row], cellinfo[row]);
847 //cerr << "above row: " << row << endl;
850 //cerr << "below row: " << row << endl;
851 handle_hline_below(rowinfo[row], cellinfo[row]);
853 } else if (t.cs() == "cline") {
854 string arg = p1.verbatim_item();
855 //cerr << "read cline arg: '" << arg << "'\n";
859 size_t from = convert<unsigned int>(t[0]);
861 cerr << "Could not parse "
862 "cline start column."
865 // 1 based index -> 0 based
867 if (from >= colinfo.size()) {
868 cerr << "cline starts at non "
870 << (from + 1) << endl;
871 from = colinfo.size() - 1;
873 size_t to = convert<unsigned int>(t[1]);
875 cerr << "Could not parse "
879 // 1 based index -> 0 based
881 if (to >= colinfo.size()) {
882 cerr << "cline ends at non "
885 to = colinfo.size() - 1;
887 for (size_t col = from; col <= to; ++col) {
888 //cerr << "row: " << row << " col: " << col << " i: " << i << endl;
890 rowinfo[row].topline = true;
891 cellinfo[row][col].topline = true;
893 rowinfo[row].bottomline = true;
894 cellinfo[row][col].bottomline = true;
897 } else if (t.cs() == "endhead") {
899 rowinfo[row].type = LT_HEAD;
900 for (int r = row - 1; r >= 0; --r) {
901 if (rowinfo[r].type != LT_NORMAL)
903 rowinfo[r].type = LT_HEAD;
905 } else if (t.cs() == "endfirsthead") {
907 rowinfo[row].type = LT_FIRSTHEAD;
908 for (int r = row - 1; r >= 0; --r) {
909 if (rowinfo[r].type != LT_NORMAL)
911 rowinfo[r].type = LT_FIRSTHEAD;
913 } else if (t.cs() == "endfoot") {
915 rowinfo[row].type = LT_FOOT;
916 for (int r = row - 1; r >= 0; --r) {
917 if (rowinfo[r].type != LT_NORMAL)
919 rowinfo[r].type = LT_FOOT;
921 } else if (t.cs() == "endlastfoot") {
923 rowinfo[row].type = LT_LASTFOOT;
924 for (int r = row - 1; r >= 0; --r) {
925 if (rowinfo[r].type != LT_NORMAL)
927 rowinfo[r].type = LT_LASTFOOT;
929 } else if (t.cs() == "newpage") {
932 rowinfo[row - 1].newpage = true;
934 // This does not work in LaTeX
940 rowinfo[row].newpage = true;
942 cerr << "unexpected line token: " << t << endl;
948 vector<string> cells;
949 split(lines[row], cells, TAB);
950 for (size_t col = 0, cell = 0; cell < cells.size();
952 //cerr << "cell content: '" << cells[cell] << "'\n";
953 if (col >= colinfo.size()) {
954 // This does not work in LaTeX
955 cerr << "Ignoring extra cell '"
956 << cells[cell] << "'." << endl;
959 Parser p(cells[cell]);
961 //cells[cell] << "'\n";
962 if (p.next_token().cs() == "multicolumn") {
965 size_t const ncells =
966 convert<unsigned int>(p.verbatim_item());
968 // special cell properties alignment
970 handle_colalign(p, t, ColInfo());
971 ColInfo & ci = t.front();
973 // The logic of LyX for multicolumn vertical
974 // lines is too complicated to reproduce it
975 // here (see LyXTabular::TeXCellPreamble()).
976 // Therefore we simply put everything in the
980 cellinfo[row][col].multi = CELL_BEGIN_OF_MULTICOLUMN;
981 cellinfo[row][col].align = ci.align;
982 cellinfo[row][col].special = ci.special;
983 cellinfo[row][col].leftlines = ci.leftlines;
984 cellinfo[row][col].rightlines = ci.rightlines;
986 parse_text_in_inset(p, os, FLAG_ITEM, false, context);
987 if (!cellinfo[row][col].content.empty()) {
988 // This may or may not work in LaTeX,
989 // but it does not work in LyX.
990 // FIXME: Handle it correctly!
991 cerr << "Moving cell content '"
993 << "' into a multicolumn cell. "
994 "This will probably not work."
997 cellinfo[row][col].content += os.str();
999 // add dummy cells for multicol
1000 for (size_t i = 0; i < ncells - 1 && col < colinfo.size(); ++i) {
1002 cellinfo[row][col].multi = CELL_PART_OF_MULTICOLUMN;
1003 cellinfo[row][col].align = 'c';
1006 } else if (col == 0 && is_long_tabular &&
1007 p.next_token().cs() == "caption") {
1008 // longtable caption support in LyX is a hack:
1009 // Captions require a row of their own with
1010 // the caption flag set to true, having only
1011 // one multicolumn cell. The contents of that
1012 // cell must contain exactly one caption inset
1013 // and nothing else.
1014 rowinfo[row].caption = true;
1015 for (size_t c = 1; c < cells.size(); ++c) {
1016 if (!cells[c].empty()) {
1017 cerr << "Moving cell content '"
1019 << "' into the caption cell. "
1020 "This will probably not work."
1022 cells[0] += cells[c];
1026 cellinfo[row][col].align = colinfo[col].align;
1027 cellinfo[row][col].multi = CELL_BEGIN_OF_MULTICOLUMN;
1029 parse_text_in_inset(p, os, FLAG_CELL, false, context);
1030 cellinfo[row][col].content += os.str();
1031 // add dummy multicolumn cells
1032 for (size_t c = 1; c < colinfo.size(); ++c)
1033 cellinfo[row][c].multi = CELL_PART_OF_MULTICOLUMN;
1036 cellinfo[row][col].leftlines = colinfo[col].leftlines;
1037 cellinfo[row][col].rightlines = colinfo[col].rightlines;
1038 cellinfo[row][col].align = colinfo[col].align;
1040 parse_text_in_inset(p, os, FLAG_CELL, false, context);
1041 cellinfo[row][col].content += os.str();
1045 //cerr << "// handle almost empty last row what we have\n";
1046 // handle almost empty last row
1047 if (row && lines[row].empty() && row + 1 == rowinfo.size()) {
1048 //cerr << "remove empty last line\n";
1049 if (rowinfo[row].topline)
1050 rowinfo[row - 1].bottomline = true;
1051 for (size_t col = 0; col < colinfo.size(); ++col)
1052 if (cellinfo[row][col].topline)
1053 cellinfo[row - 1][col].bottomline = true;
1058 // Now we have the table structure and content in rowinfo, colinfo
1060 // Unfortunately LyX has some limitations that we need to work around.
1062 // Convert cells with special content to multicolumn cells
1063 // (LyX ignores the special field for non-multicolumn cells).
1064 for (size_t row = 0; row < rowinfo.size(); ++row) {
1065 for (size_t col = 0; col < cellinfo[row].size(); ++col) {
1066 if (cellinfo[row][col].multi == CELL_NORMAL &&
1067 !cellinfo[row][col].special.empty())
1068 cellinfo[row][col].multi = CELL_BEGIN_OF_MULTICOLUMN;
1072 // Distribute lines from rows/columns to cells
1073 // The code was stolen from convert_tablines() in lyx2lyx/lyx_1_6.py.
1074 // Each standard cell inherits the settings of the corresponding
1075 // rowinfo/colinfo. This works because all cells with individual
1076 // settings were converted to multicolumn cells above.
1077 // Each multicolumn cell inherits the settings of the rowinfo/colinfo
1078 // corresponding to the first column of the multicolumn cell (default
1079 // of the multicol package). This works because the special field
1080 // overrides the line fields.
1081 for (size_t row = 0; row < rowinfo.size(); ++row) {
1082 for (size_t col = 0; col < cellinfo[row].size(); ++col) {
1083 if (cellinfo[row][col].multi == CELL_NORMAL) {
1084 cellinfo[row][col].topline = rowinfo[row].topline;
1085 cellinfo[row][col].bottomline = rowinfo[row].bottomline;
1086 cellinfo[row][col].leftlines = colinfo[col].leftlines;
1087 cellinfo[row][col].rightlines = colinfo[col].rightlines;
1088 } else if (cellinfo[row][col].multi == CELL_BEGIN_OF_MULTICOLUMN) {
1090 while (s < cellinfo[row].size() &&
1091 cellinfo[row][s].multi == CELL_PART_OF_MULTICOLUMN)
1093 if (s < cellinfo[row].size() &&
1094 cellinfo[row][s].multi != CELL_BEGIN_OF_MULTICOLUMN)
1095 cellinfo[row][col].rightlines = colinfo[col].rightlines;
1096 if (col > 0 && cellinfo[row][col-1].multi == CELL_NORMAL)
1097 cellinfo[row][col].leftlines = colinfo[col].leftlines;
1102 //cerr << "// output what we have\n";
1103 // output what we have
1104 os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
1105 << "\" columns=\"" << colinfo.size() << "\">\n";
1107 << write_attribute("rotate", false)
1108 << write_attribute("islongtable", is_long_tabular)
1111 //cerr << "// after header\n";
1112 for (size_t col = 0; col < colinfo.size(); ++col) {
1113 os << "<column alignment=\""
1114 << verbose_align(colinfo[col].align) << "\""
1116 << verbose_valign(colinfo[col].valign) << "\""
1117 << write_attribute("width", translate_len(colinfo[col].width))
1118 << write_attribute("special", colinfo[col].special)
1121 //cerr << "// after cols\n";
1123 for (size_t row = 0; row < rowinfo.size(); ++row) {
1125 << write_attribute("endhead",
1126 rowinfo[row].type == LT_HEAD)
1127 << write_attribute("endfirsthead",
1128 rowinfo[row].type == LT_FIRSTHEAD)
1129 << write_attribute("endfoot",
1130 rowinfo[row].type == LT_FOOT)
1131 << write_attribute("endlastfoot",
1132 rowinfo[row].type == LT_LASTFOOT)
1133 << write_attribute("newpage", rowinfo[row].newpage)
1134 << write_attribute("caption", rowinfo[row].caption)
1136 for (size_t col = 0; col < colinfo.size(); ++col) {
1137 CellInfo const & cell = cellinfo[row][col];
1139 if (cell.multi != CELL_NORMAL)
1140 os << " multicolumn=\"" << cell.multi << "\"";
1141 os << " alignment=\"" << verbose_align(cell.align)
1143 << " valignment=\"" << verbose_valign(cell.valign)
1145 << write_attribute("topline", cell.topline)
1146 << write_attribute("bottomline", cell.bottomline)
1147 << write_attribute("leftline", cell.leftlines > 0)
1148 << write_attribute("rightline", cell.rightlines > 0)
1149 << write_attribute("rotate", cell.rotate);
1150 //cerr << "\nrow: " << row << " col: " << col;
1152 // cerr << " topline=\"true\"";
1153 //if (cell.bottomline)
1154 // cerr << " bottomline=\"true\"";
1155 os << " usebox=\"none\""
1156 << write_attribute("width", translate_len(cell.width));
1157 if (cell.multi != CELL_NORMAL)
1158 os << write_attribute("special", cell.special);
1160 << "\n\\begin_inset Text\n"
1162 << "\n\\end_inset\n"
1168 os << "</lyxtabular>\n";