math_fracinset.h \
math_fracbase.C \
math_fracbase.h \
+ math_gridinfo.h \
math_gridinset.C \
math_gridinset.h \
math_hullinset.C \
{
FontSetChanger dummy(mi.base, "lyxert");
MathTextInset::metrics(mi);
- cache_.colinfo_[0].align_ = 'l';
+ cache_.colinfo_[0].align = 'l';
metricsMarkers2();
}
--- /dev/null
+#ifndef MATH_GRIDINFO_H
+#define MATH_GRIDINFO_H
+
+struct ColInfo
+{
+ ColInfo() : rightline(0), leftline(false) {}
+ char align; // column alignment
+ string width; // column width
+ int rightline; // a line on the right?
+ bool leftline;
+};
+
+
+struct RowInfo
+{
+ RowInfo() : topline(false), bottomline(false) {}
+ bool topline; // horizontal line above
+ int bottomline; // horizontal line below
+};
+
+
+struct CellInfo
+{
+ CellInfo()
+ : multi(0), leftline(false), rightline(false),
+ topline(false), bottomline(false)
+ {}
+
+ string content; // cell content
+ int multi; // multicolumn flag
+ char align; // cell alignment
+ bool leftline; // do we have a line on the left?
+ bool rightline; // do we have a line on the right?
+ bool topline; // do we have a line above?
+ bool bottomline; // do we have a line below?
+};
+
+
+inline char const * verbose_align(char c)
+{
+ return c == 'c' ? "center" : c == 'r' ? "right" : c == 'l' ? "left" : "none";
+}
+
+
+#endif
}
-//////////////////////////////////////////////////////////////
-
-
-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(guessColumns(h)),
- rowinfo_(2),
- colinfo_(guessColumns(h) + 1),
- cellinfo_(1 * guessColumns(h))
+ : MathNestInset(1), rowinfo_(1), colinfo_(1), cellinfo_(1)
{
setDefaults();
valign(v);
MathGridInset::MathGridInset()
- : MathNestInset(1),
- rowinfo_(1 + 1),
- colinfo_(1 + 1),
- cellinfo_(1),
- v_align_('c')
+ : MathNestInset(1), rowinfo_(1), colinfo_(1), cellinfo_(1), v_align_('c')
{
setDefaults();
}
MathGridInset::MathGridInset(col_type m, row_type n)
: MathNestInset(m * n),
- rowinfo_(n + 1),
- colinfo_(m + 1),
- cellinfo_(m * n),
- v_align_('c')
+ rowinfo_(n), colinfo_(m), 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 + 1),
- colinfo_(m + 1),
- cellinfo_(m * n),
- v_align_(v)
+ rowinfo_(n), colinfo_(m), 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())
- break;
+ if (col == ncols())
+ addCol(ncols() - 1);
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 {
}
-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 + string(colinfo_[ncols()].lines_, '|');
}
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')
#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 {
- ///
- 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
+ struct CellInfo : public ::CellInfo {
+ /// fixed glue
mutable int glue_;
///
mutable pos_type begin_;
};
/// additional per-row information
- struct RowInfo {
+ struct RowInfo : public ::RowInfo {
///
- RowInfo();
+ RowInfo()
+ : lines_(0), skip_(0)
+ {}
+
///
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 {
+ struct ColInfo : public ::ColInfo {
///
- ColInfo();
- /// currently possible: 'l', 'c', 'r'
- char align_;
+ ColInfo()
+ : lines_(0), skip_(0)
+ {}
+
/// cache for drawing
- int h_offset;
+ int lines_;
+ /// additional amount to be skipped on screen
+ int skip_;
+
/// 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);
}
else if (t.cs() == "[") {
+ // special handling of a few common SW user quirks
+ p.skip_spaces();
+ //if (p.next_token().cs() ==
os << "\\[";
parse_math(p, os, FLAG_EQUATION, MATH_MODE);
os << "\\]";
using std::string;
using std::vector;
+#include "mathed/math_gridinfo.h"
namespace {
-struct ColInfo
-{
- ColInfo() : rightline(0), leftline(false) {}
- string align; // column alignment
- string width; // column width
- int rightline; // a line on the right?
- bool leftline;
-};
-
-
-struct RowInfo
-{
- RowInfo() : topline(false), bottomline(false) {}
- bool topline; // horizontal line above
- int bottomline; // horizontal line below
-};
-
-
-struct CellInfo
-{
- CellInfo()
- : multi(0), leftline(false), rightline(false),
- topline(false), bottomline(false)
- {}
-
- string content; // cell content
- int multi; // multicolumn flag
- string align; // cell alignment
- bool leftline; // do we have a line on the left?
- bool rightline; // do we have a line on the right?
- bool topline; // do we have a line above?
- bool bottomline; // do we have a line below?
-};
-
-
int string2int(string const & s, int deflt = 0)
{
istringstream is(s);
string read_hlines(Parser & p)
{
ostringstream os;
- p.skipSpaces();
+ p.skip_spaces();
while (p.good()) {
if (p.next_token().cs() == "hline") {
p.get_token();
os << "\\cline{" << p.verbatim_item() << "}";
} else
break;
- p.skipSpaces();
+ p.skip_spaces();
};
//cerr << "read_hlines(), read: '" << os.str() << "'\n";
//cerr << "read_hlines(), next token: " << p.next_token() << "\n";
char const LINE = '\002';
char const HLINE = '\004';
-string get_align(char c)
-{
- switch (c) {
- case 'c': return "center";
- case 'l': return "left";
- case 'r': return "right";
- case 'b': return "block";
- }
- return "center";
-}
-
void handle_colalign(Parser & p, vector<ColInfo> & colinfo)
{
if (p.get_token().cat() != catBegin)
cerr << "wrong syntax for table column alignment. '{' expected\n";
- string nextalign = "block";
+ char nextalign = 'b';
bool leftline = false;
for (Token t=p.get_token(); p.good() && t.cat() != catEnd; t = p.get_token()){
#ifdef FILEDEBUG
case 'l':
case 'r': {
ColInfo ci;
- ci.align = get_align(t.character());
+ ci.align = t.character();
if (colinfo.size() && colinfo.back().rightline > 1) {
ci.leftline = true;
--colinfo.back().rightline;
colinfo.push_back(ColInfo());
colinfo.back().align = nextalign;
colinfo.back().width = p.verbatim_item();
- nextalign = "block";
+ nextalign = 'b';
break;
case '|':
if (colinfo.empty())
case '>': {
string s = p.verbatim_item();
if (s == "\\raggedleft ")
- nextalign = "left";
+ nextalign = 'l';
else if (s == "\\raggedright ")
- nextalign = "right";
+ nextalign = 'r';
else
cerr << "unknown '>' column '" << s << "'\n";
break;
}
else if (t.cs() == "tabularnewline" || t.cs() == "\\") {
- //else if (t.cs() == "tabularnewline") {
// stuff before the line break
// and look ahead for stuff after the line break
os << HLINE << hlines << HLINE << LINE << read_hlines(p) << HLINE;
cell < cells.size() && col < colinfo.size(); ++col, ++cell) {
//cerr << "cell content: '" << cells[cell] << "'\n";
Parser p(cells[cell]);
- p.skipSpaces();
+ p.skip_spaces();
//cells[cell] << "'\n";
if (p.next_token().cs() == "multicolumn") {
// how many cells?
for (size_t i = 0; i < ncells - 1 && col < colinfo.size(); ++i) {
++col;
cellinfo[row][col].multi = 2;
- cellinfo[row][col].align = "center";
+ cellinfo[row][col].align = 'c';
}
// more than one line on the right?
// cerr << " topline=\"true\"";
//if (cell.bottomline)
// cerr << " bottomline=\"true\"";
- os << " alignment=\"" << cell.align << "\""
+ os << " alignment=\"" << verbose_align(cell.align) << "\""
<< " valignment=\"top\""
<< " usebox=\"none\""
<< ">"
s += t.asString();
}
//cerr << "comment: " << s << "\n";
- p.skipSpaces();
+ p.skip_spaces();
}
}
-void Parser::skipSpaces()
+void Parser::skip_spaces()
{
while (1) {
if (next_token().cat() == catSpace || next_token().cat() == catNewline)
string Parser::getArg(char left, char right)
{
- skipSpaces();
+ skip_spaces();
string result;
char c = getChar();
{
if (!good())
error("stream bad");
- skipSpaces();
+ skip_spaces();
if (next_token().cat() == catBegin) {
Token t = get_token(); // skip brace
string res;
///
Token const & get_token();
/// skips spaces if any
- void skipSpaces();
+ void skip_spaces();
///
void lex(string const & s);
///
}
else if (t.cs() == "item") {
- p.skipSpaces();
+ p.skip_spaces();
string s;
if (p.next_token().character() == '[') {
p.get_token(); // eat '['
}
else if (t.cs() == "par") {
- p.skipSpaces();
+ p.skip_spaces();
if (p.next_token().cs() != "\\begin")
handle_par(os);
//cerr << "next token: '" << p.next_token().cs() << "'\n";