]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/table.cpp
use enchant exception message accessor
[lyx.git] / src / tex2lyx / table.cpp
index 06ad747dd0e9493c95843d65f819fd13bb59aa00..eed7bb91c81ad92db450fa87f925cd14c46344f5 100644 (file)
@@ -118,7 +118,7 @@ class CellInfo {
 public:
        CellInfo() : multi(CELL_NORMAL), align('n'), valign('n'),
                     leftlines(0), rightlines(0), topline(false),
-                    bottomline(false), rotate(false) {}
+                    bottomline(false), rotate(0) {}
        /// cell content
        string content;
        /// multicolumn flag
@@ -135,8 +135,8 @@ public:
        bool topline;
        /// do we have a line below?
        bool bottomline;
-       /// is the cell rotated?
-       bool rotate;
+       /// how is the cell rotated?
+       int rotate;
        /// width for multicolumn cells
        string width;
        /// special formatting for multicolumn cells
@@ -209,6 +209,14 @@ string const write_attribute(string const & name, string const & s)
 }
 
 
+string const write_attribute(string const & name, int const & i)
+{
+       // we write only true attribute values so we remove a bit of the
+       // file format bloat for tabulars.
+       return i ? write_attribute(name, convert<string>(i)) : string();
+}
+
+
 /*! rather brutish way to code table structure in a string:
 
 \verbatim
@@ -726,13 +734,13 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
                        }
                }
 
-               else if (t.cat() == catSpace 
+               else if (t.cat() == catSpace
                         || t.cat() == catNewline
-                        || t.cat() == catLetter 
-                        || t.cat() == catSuper 
-                        || t.cat() == catSub 
-                        || t.cat() == catOther 
-                        || t.cat() == catActive 
+                        || t.cat() == catLetter
+                        || t.cat() == catSuper
+                        || t.cat() == catSub
+                        || t.cat() == catOther
+                        || t.cat() == catActive
                         || t.cat() == catParameter)
                        os << t.cs();
 
@@ -778,7 +786,7 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
                        // treat the nested environment as a block, don't
                        // parse &, \\ etc, because they don't belong to our
                        // table if they appear.
-                       os << p.verbatimEnvironment(name);
+                       os << p.ertEnvironment(name);
                        os << "\\end{" << name << '}';
                        active_environments.pop_back();
                }
@@ -1156,8 +1164,20 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
                                cellinfo[row][col].content += os.str();
 
                                // add dummy cells for multicol
-                               for (size_t i = 0; i < ncells - 1 && col < colinfo.size(); ++i) {
+                               for (size_t i = 0; i < ncells - 1; ++i) {
                                        ++col;
+                                       if (col >= colinfo.size()) {
+                                               cerr << "The cell '"
+                                                       << cells[cell]
+                                                       << "' specifies "
+                                                       << convert<string>(ncells)
+                                                       << " columns while the table has only "
+                                                       << convert<string>(colinfo.size())
+                                                       << " columns!"
+                                                       << " Therefore the surplus columns will be ignored."
+                                                       << endl;
+                                               break;
+                                       }
                                        cellinfo[row][col].multi = CELL_PART_OF_MULTICOLUMN;
                                        cellinfo[row][col].align = 'c';
                                }
@@ -1171,51 +1191,66 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
                                // one multicolumn cell. The contents of that
                                // cell must contain exactly one caption inset
                                // and nothing else.
-                               // LyX outputs all caption rows as first head,
-                               // so we must not set the caption flag for
-                               // captions not in the first head.
                                // Fortunately, the caption flag is only needed
                                // for tables with more than one column.
-                               bool usecaption = (rowinfo[row].type == LT_NORMAL ||
-                                                  rowinfo[row].type == LT_FIRSTHEAD);
-                               for (size_t r = 0; r < row && usecaption; ++r)
-                                       if (rowinfo[row].type != LT_NORMAL &&
-                                           rowinfo[row].type != LT_FIRSTHEAD)
-                                               usecaption = false;
-                               if (usecaption) {
-                                       rowinfo[row].caption = true;
-                                       for (size_t c = 1; c < cells.size(); ++c) {
-                                               if (!cells[c].empty()) {
-                                                       cerr << "Moving cell content '"
-                                                            << cells[c]
-                                                            << "' into the caption cell. "
-                                                               "This will probably not work."
-                                                            << endl;
-                                                       cells[0] += cells[c];
-                                               }
+                               rowinfo[row].caption = true;
+                               for (size_t c = 1; c < cells.size(); ++c) {
+                                       if (!cells[c].empty()) {
+                                               cerr << "Moving cell content '"
+                                                    << cells[c]
+                                                    << "' into the caption cell. "
+                                                       "This will probably not work."
+                                                    << endl;
+                                               cells[0] += cells[c];
                                        }
-                                       cells.resize(1);
-                                       cellinfo[row][col].align      = colinfo[col].align;
-                                       cellinfo[row][col].multi      = CELL_BEGIN_OF_MULTICOLUMN;
-                               } else {
-                                       cellinfo[row][col].leftlines  = colinfo[col].leftlines;
-                                       cellinfo[row][col].rightlines = colinfo[col].rightlines;
-                                       cellinfo[row][col].align      = colinfo[col].align;
                                }
+                               cells.resize(1);
+                               cellinfo[row][col].align      = colinfo[col].align;
+                               cellinfo[row][col].multi      = CELL_BEGIN_OF_MULTICOLUMN;
                                ostringstream os;
                                parse_text_in_inset(p, os, FLAG_CELL, false, context);
                                cellinfo[row][col].content += os.str();
-                               if (usecaption) {
-                                       // add dummy multicolumn cells
-                                       for (size_t c = 1; c < colinfo.size(); ++c)
-                                               cellinfo[row][c].multi = CELL_PART_OF_MULTICOLUMN;
-                               }
+                               // add dummy multicolumn cells
+                               for (size_t c = 1; c < colinfo.size(); ++c)
+                                       cellinfo[row][c].multi = CELL_PART_OF_MULTICOLUMN;
                        } else {
+                               bool turn = false;
+                               int rotate = 0;
+                               if (p.next_token().cs() == "begin") {
+                                       p.pushPosition();
+                                       p.get_token();
+                                       string const env = p.getArg('{', '}');
+                                       if (env == "sideways" || env == "turn") {
+                                               string angle = "90";
+                                               if (env == "turn") {
+                                                       turn = true;
+                                                       angle = p.getArg('{', '}');
+                                               }
+                                               active_environments.push_back(env);
+                                               p.ertEnvironment(env);
+                                               active_environments.pop_back();
+                                               p.skip_spaces();
+                                               if (!p.good() && support::isStrInt(angle))
+                                                       rotate = convert<int>(angle);
+                                       }
+                                       p.popPosition();
+                               }
                                cellinfo[row][col].leftlines  = colinfo[col].leftlines;
                                cellinfo[row][col].rightlines = colinfo[col].rightlines;
                                cellinfo[row][col].align      = colinfo[col].align;
                                ostringstream os;
-                               parse_text_in_inset(p, os, FLAG_CELL, false, context);
+                               if (rotate != 0) {
+                                       cellinfo[row][col].rotate = rotate;
+                                       p.get_token();
+                                       active_environments.push_back(p.getArg('{', '}'));
+                                       if (turn)
+                                               p.getArg('{', '}');
+                                       parse_text_in_inset(p, os, FLAG_END, false, context);
+                                       active_environments.pop_back();
+                                       preamble.registerAutomaticallyLoadedPackage("rotating");
+                               } else {
+                                       parse_text_in_inset(p, os, FLAG_CELL, false, context);
+                               }
                                cellinfo[row][col].content += os.str();
                        }
                }
@@ -1286,10 +1321,11 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
 
        //cerr << "// output what we have\n";
        // output what we have
+       string const rotate = "0";
        os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
           << "\" columns=\"" << colinfo.size() << "\">\n";
        os << "<features"
-          << write_attribute("rotate", false)
+          << write_attribute("rotate", rotate)
           << write_attribute("booktabs", booktabs)
           << write_attribute("islongtable", is_long_tabular);
        if (is_long_tabular) {