}
+//////////////////////////////////////////////////////////////
+
+
+MathGridInset::CellInfo::CellInfo()
+ : dummy_(false)
+{}
+
+
+
+
+//////////////////////////////////////////////////////////////
+
+
+MathGridInset::RowInfo::RowInfo()
+ : lines_(0), skip_(0)
+{}
+
+
+
int MathGridInset::RowInfo::skipPixels() const
{
return crskip_.inBP();
+//////////////////////////////////////////////////////////////
+
+
+MathGridInset::ColInfo::ColInfo()
+ : align_('c'), leftline_(false), rightline_(false), lines_(0)
+{}
+
+
//////////////////////////////////////////////////////////////
MathGridInset::MathGridInset(char v, string const & h)
- : MathNestInset(1), rowinfo_(1), colinfo_(1), cellinfo_(1)
+ : MathNestInset(guessColumns(h)),
+ rowinfo_(2),
+ colinfo_(guessColumns(h) + 1),
+ cellinfo_(1 * guessColumns(h))
{
setDefaults();
valign(v);
MathGridInset::MathGridInset()
- : MathNestInset(1), rowinfo_(1), colinfo_(1), cellinfo_(1), v_align_('c')
+ : MathNestInset(1),
+ rowinfo_(1 + 1),
+ colinfo_(1 + 1),
+ cellinfo_(1),
+ v_align_('c')
{
setDefaults();
}
MathGridInset::MathGridInset(col_type m, row_type n)
: MathNestInset(m * n),
- rowinfo_(n), colinfo_(m), cellinfo_(m * n), v_align_('c')
+ rowinfo_(n + 1),
+ colinfo_(m + 1),
+ cellinfo_(m * n),
+ v_align_('c')
{
setDefaults();
}
MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
: MathNestInset(m * n),
- rowinfo_(n), colinfo_(m), cellinfo_(m * n), v_align_(v)
+ rowinfo_(n + 1),
+ colinfo_(m + 1),
+ cellinfo_(m * n),
+ v_align_(v)
{
setDefaults();
valign(v);
//if (nrows() <= 0)
// lyxerr << "positive number of rows expected\n";
for (col_type col = 0; col < ncols(); ++col) {
- colinfo_[col].align = defaultColAlign(col);
- colinfo_[col].skip_ = defaultColSpace(col);
+ colinfo_[col].align_ = defaultColAlign(col);
+ colinfo_[col].skip_ = defaultColSpace(col);
}
}
{
col_type col = 0;
for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
- if (col == ncols())
- addCol(ncols() - 1);
- char const c = *it;
- lyxerr << "handle column separator: '" << c << "'\n";
+ if (col >= ncols())
+ break;
+ char c = *it;
if (c == '|') {
colinfo_[col].lines_++;
} else if (c == 'c' || c == 'l' || c == 'r') {
- colinfo_[col].align = c;
+ colinfo_[col].align_ = c;
++col;
colinfo_[col].lines_ = 0;
} else {
}
}
+/*
col_type n = hh.size();
- if (n >= ncols())
- n = ncols() - 1;
+ if (n > ncols())
+ n = ncols();
for (col_type col = 0; col < n; ++col)
- colinfo_[col].align = hh[col];
+ colinfo_[col].align_ = hh[col];
+*/
}
+MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
+{
+ col_type col = 0;
+ for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
+ if (*it == 'c' || *it == 'l' || *it == 'r')
+ ++col;
+ // let's have at least one column, even if we did not recognize its
+ // alignment
+ if (col == 0)
+ col = 1;
+ return col;
+}
+
void MathGridInset::halign(char h, col_type col)
{
- colinfo_[col].align = h;
+ colinfo_[col].align_ = h;
}
char MathGridInset::halign(col_type col) const
{
- return colinfo_[col].align;
+ return colinfo_[col].align_;
}
string res;
for (col_type col = 0; col < ncols(); ++col) {
res += string(colinfo_[col].lines_, '|');
- res += colinfo_[col].align;
+ res += colinfo_[col].align_;
}
- return res;
+ return res + string(colinfo_[ncols()].lines_, '|');
}
MathGridInset::col_type MathGridInset::ncols() const
{
- return colinfo_.size();
+ return colinfo_.size() - 1;
}
MathGridInset::row_type MathGridInset::nrows() const
{
- return rowinfo_.size();
+ return rowinfo_.size() - 1;
}
rowinfo_[row].descent_ = desc;
}
rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
+ rowinfo_[nrows()].ascent_ = 0;
+ rowinfo_[nrows()].descent_ = 0;
// compute vertical offsets
rowinfo_[0].offset_ = 0;
- for (row_type row = 1; row < nrows(); ++row) {
+ for (row_type row = 1; row <= nrows(); ++row) {
rowinfo_[row].offset_ =
rowinfo_[row - 1].offset_ +
rowinfo_[row - 1].descent_ +
default:
h = rowinfo_[nrows() - 1].offset_ / 2;
}
- for (row_type row = 0; row < nrows(); ++row)
+ for (row_type row = 0; row <= nrows(); ++row)
rowinfo_[row].offset_ -= h;
wid = max(wid, cell(index(row, col)).width());
colinfo_[col].width_ = wid;
}
+ colinfo_[ncols()].width_ = 0;
// compute horizontal offsets
colinfo_[0].offset_ = border();
- for (col_type col = 1; col < ncols(); ++col) {
+ for (col_type col = 1; col <= ncols(); ++col) {
colinfo_[col].offset_ =
colinfo_[col - 1].offset_ +
colinfo_[col - 1].width_ +
}
- dim_.w = colinfo_[ncols() - 1].offset_
+ dim_.w = colinfo_[ncols() - 1].offset_
+ colinfo_[ncols() - 1].width_
- //+ vlinesep() * colinfo_[ncols()].lines_
+ + vlinesep() * colinfo_[ncols()].lines_
+ border();
- dim_.a = - rowinfo_[0].offset_
+ dim_.a = - rowinfo_[0].offset_
+ rowinfo_[0].ascent_
- + hlinesep() * rowinfo_[0].lines_
+ + hlinesep() * rowinfo_[0].lines_
+ border();
dim_.d = rowinfo_[nrows() - 1].offset_
+ rowinfo_[nrows() - 1].descent_
- //+ hlinesep() * rowinfo_[nrows()].lines_
+ + hlinesep() * rowinfo_[nrows()].lines_
+ border();
for (idx_type idx = 0; idx < nargs(); ++idx)
cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
- for (row_type row = 0; row < nrows(); ++row)
+ for (row_type row = 0; row <= nrows(); ++row)
for (int i = 0; i < rowinfo_[row].lines_; ++i) {
int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
- i * hlinesep() - hlinesep()/2 - rowsep()/2;
pi.pain.line(x + 1, yy, x + width() - 1, yy);
}
- for (col_type col = 0; col < ncols(); ++col)
+ for (col_type col = 0; col <= ncols(); ++col)
for (int i = 0; i < colinfo_[col].lines_; ++i) {
int xx = x + colinfo_[col].offset_
- i * vlinesep() - vlinesep()/2 - colsep()/2;
rowinfo_[row].descent_ = desc;
}
//rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
+ rowinfo_[nrows()].ascent_ = 0;
+ rowinfo_[nrows()].descent_ = 0;
// compute vertical offsets
rowinfo_[0].offset_ = 0;
- for (row_type row = 1; row < nrows(); ++row) {
+ for (row_type row = 1; row <= nrows(); ++row) {
rowinfo_[row].offset_ =
rowinfo_[row - 1].offset_ +
rowinfo_[row - 1].descent_ +
default:
h = rowinfo_[nrows() - 1].offset_ / 2;
}
- for (row_type row = 0; row < nrows(); ++row)
+ for (row_type row = 0; row <= nrows(); ++row)
rowinfo_[row].offset_ -= h;
wid = max(wid, cell(index(row, col)).width());
colinfo_[col].width_ = wid;
}
+ colinfo_[ncols()].width_ = 0;
// compute horizontal offsets
colinfo_[0].offset_ = border();
- for (col_type col = 1; col < ncols(); ++col) {
+ for (col_type col = 1; col <= ncols(); ++col) {
colinfo_[col].offset_ =
colinfo_[col - 1].offset_ +
colinfo_[col - 1].width_ +
swap(cellinfo_, new_cellinfo);
ColInfo inf;
- inf.skip_ = defaultColSpace(newcol);
- inf.align = defaultColAlign(newcol);
+ inf.skip_ = defaultColSpace(newcol);
+ inf.align_ = defaultColAlign(newcol);
colinfo_.insert(colinfo_.begin() + newcol, inf);
}
{
col_type c = col(idx);
int x = colinfo_[c].offset_;
- char align = colinfo_[c].align;
+ char align = colinfo_[c].align_;
if (align == 'r' || align == 'R')
x += colinfo_[c].width_ - cell(idx).width();
if (align == 'c' || align == 'C')
if (!emptyline && row + 1 < nrows())
os << "\n";
}
- //string const s = verboseHLine(rowinfo_[nrows()].lines_);
- //if (!s.empty() && s != " ") {
- // if (os.fragile())
- // os << "\\protect";
- // os << "\\\\" << s;
- //}
+ string const s = verboseHLine(rowinfo_[nrows()].lines_);
+ if (!s.empty() && s != " ") {
+ if (os.fragile())
+ os << "\\protect";
+ os << "\\\\" << s;
+ }
}
#include "math_nestinset.h"
#include "vspace.h"
#include "LString.h"
-#include "math_gridinfo.h"
/** Gridded math inset base class.
public:
/// additional per-cell information
- struct CellInfo : public ::CellInfo {
- /// fixed glue
+ struct CellInfo {
+ ///
+ CellInfo();
+ /// a dummy cell before a multicolumn cell
+ int dummy_;
+ /// special multi colums alignment
+ string align_;
+ /// these should be a per-cell property, but ok to have it here
+ /// for single-column grids like paragraphs
mutable int glue_;
///
mutable pos_type begin_;
};
/// additional per-row information
- struct RowInfo : public ::RowInfo {
+ struct RowInfo {
///
- RowInfo()
- : lines_(0), skip_(0)
- {}
-
+ RowInfo();
///
int skipPixels() const;
- /// how many hlines above this row?
- int lines_;
- /// parameter to the line break
- LyXLength crskip_;
- /// extra distance between lines on screen
- int skip_;
-
/// cached descent
mutable int descent_;
/// cached ascent
mutable int ascent_;
/// cached offset
mutable int offset_;
+ /// how many hlines above this row?
+ int lines_;
+ /// parameter to the line break
+ LyXLength crskip_;
+ /// extra distance between lines
+ int skip_;
};
// additional per-row information
- struct ColInfo : public ::ColInfo {
+ struct ColInfo {
///
- ColInfo()
- : lines_(0), skip_(0)
- {}
-
+ ColInfo();
+ /// currently possible: 'l', 'c', 'r'
+ char align_;
/// cache for drawing
- int lines_;
- /// additional amount to be skipped on screen
- int skip_;
-
+ int h_offset;
/// cached width
mutable int width_;
/// cached offset
mutable int offset_;
+ /// do we need a line to the left?
+ bool leftline_;
+ /// do we need a line to the right?
+ bool rightline_;
+ /// how many lines to the left of this column?
+ int lines_;
+ /// additional amount to be skipped when drawing
+ int skip_;
};
public:
virtual string eolString(row_type row, bool fragile = false) const;
/// returns proper 'end of column' code for LaTeX
virtual string eocString(col_type col, col_type lastcol) const;
+ /// extract number of columns from alignment string
+ col_type guessColumns(string const & halign) const;
/// splits cells and shifts right part to the next cell
void splitCell(idx_type &, pos_type & pos);
{
if (s == "none") return 0;
if (s == "simple") return 1;
- if (s == "chemistry") return 2;
- if (s == "equation") return 3;
- if (s == "eqnarray") return 4;
- if (s == "align") return 5;
- if (s == "alignat") return 6;
- if (s == "xalignat") return 7;
- if (s == "xxalignat") return 8;
- if (s == "multline") return 9;
- if (s == "gather") return 10;
- if (s == "flalign") return 11;
+ if (s == "equation") return 2;
+ if (s == "eqnarray") return 3;
+ if (s == "align") return 4;
+ if (s == "alignat") return 5;
+ if (s == "xalignat") return 6;
+ if (s == "xxalignat") return 7;
+ if (s == "multline") return 8;
+ if (s == "gather") return 9;
+ if (s == "flalign") return 10;
lyxerr << "unknown hull type '" << s << "'\n";
return 0;
}
{
if (type_ == "none")
return "lyxnochange";
- if (type_ == "chemistry")
- return "mathrm";
return "mathnormal";
}
bool MathHullInset::display() const
{
- return type_ != "simple" && type_ != "none" && type_ != "chemistry";
+ return type_ != "simple" && type_ != "none";
}
{
if (type_ == "none")
return false;
- if (type_ == "chemistry")
- return false;
if (type_ == "simple")
return false;
if (type_ == "xxalignat")
os << ' ';
}
- else if (type_ == "chemistry")
- os << "$\\mathrm{";
-
else if (type_ == "equation") {
if (n)
os << "\\begin{equation" << star(n) << "}\n";
else if (type_ == "simple")
os << '$';
- else if (type_ == "chemistry")
- os << "}$";
-
else if (type_ == "equation")
if (n)
os << "\\end{equation" << star(n) << "}\n";
// done
}
- else if (newtype == "none" || newtype == "chemistry") {
- mutate("simple");
+ else if (type_ == "none") {
+ setType("simple");
numbered(0, false);
+ mutate(newtype);
}
- else if (newtype == "simple") {
- if (type_ != "none" && type_ != "chemistry") {
- mutate("equation");
+ else if (type_ == "simple") {
+ if (newtype == "none") {
+ setType("none");
+ } else {
+ setType("equation");
numbered(0, false);
+ mutate(newtype);
}
}
- else if (newtype == "equation" && smaller(type_, newtype)) {
- numbered(0, false);
- }
-
else if (type_ == "equation") {
if (smaller(newtype, type_)) {
setType("simple");
lyxerr << "mutation from '" << type_
<< "' to '" << newtype << "' not implemented" << endl;
}
-
- setType(newtype);
}
string MathHullInset::fileInsetLabel() const
{
- if (type_ == "chemistry")
- return "Chemistry";
return "Formula";
}