mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 13:48:59 +00:00
some common structures in extra file
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6857 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
63febc852e
commit
00e9ff93fb
@ -75,6 +75,7 @@ libmathed_la_SOURCES = \
|
||||
math_fracinset.h \
|
||||
math_fracbase.C \
|
||||
math_fracbase.h \
|
||||
math_gridinfo.h \
|
||||
math_gridinset.C \
|
||||
math_gridinset.h \
|
||||
math_hullinset.C \
|
||||
|
@ -16,7 +16,7 @@ void MathErtInset::metrics(MetricsInfo & mi) const
|
||||
{
|
||||
FontSetChanger dummy(mi.base, "lyxert");
|
||||
MathTextInset::metrics(mi);
|
||||
cache_.colinfo_[0].align_ = 'l';
|
||||
cache_.colinfo_[0].align = 'l';
|
||||
metricsMarkers2();
|
||||
}
|
||||
|
||||
|
45
src/mathed/math_gridinfo.h
Normal file
45
src/mathed/math_gridinfo.h
Normal file
@ -0,0 +1,45 @@
|
||||
#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
|
@ -68,25 +68,6 @@ int extractInt(istream & is)
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
MathGridInset::CellInfo::CellInfo()
|
||||
: dummy_(false)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
MathGridInset::RowInfo::RowInfo()
|
||||
: lines_(0), skip_(0)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
int MathGridInset::RowInfo::skipPixels() const
|
||||
{
|
||||
return crskip_.inBP();
|
||||
@ -94,22 +75,11 @@ int MathGridInset::RowInfo::skipPixels() const
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
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);
|
||||
@ -119,11 +89,7 @@ MathGridInset::MathGridInset(char v, string const & h)
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
@ -131,10 +97,7 @@ MathGridInset::MathGridInset()
|
||||
|
||||
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();
|
||||
}
|
||||
@ -142,10 +105,7 @@ MathGridInset::MathGridInset(col_type m, row_type n)
|
||||
|
||||
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);
|
||||
@ -179,7 +139,7 @@ void MathGridInset::setDefaults()
|
||||
//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].align = defaultColAlign(col);
|
||||
colinfo_[col].skip_ = defaultColSpace(col);
|
||||
}
|
||||
}
|
||||
@ -189,13 +149,13 @@ void MathGridInset::halign(string const & hh)
|
||||
{
|
||||
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 {
|
||||
@ -213,29 +173,16 @@ void MathGridInset::halign(string const & hh)
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -244,7 +191,7 @@ string MathGridInset::halign() const
|
||||
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_, '|');
|
||||
}
|
||||
@ -660,7 +607,7 @@ void MathGridInset::addCol(col_type newcol)
|
||||
|
||||
ColInfo inf;
|
||||
inf.skip_ = defaultColSpace(newcol);
|
||||
inf.align_ = defaultColAlign(newcol);
|
||||
inf.align = defaultColAlign(newcol);
|
||||
colinfo_.insert(colinfo_.begin() + newcol, inf);
|
||||
}
|
||||
|
||||
@ -707,7 +654,7 @@ int MathGridInset::cellXOffset(idx_type idx) const
|
||||
{
|
||||
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')
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "math_nestinset.h"
|
||||
#include "vspace.h"
|
||||
#include "LString.h"
|
||||
#include "math_gridinfo.h"
|
||||
|
||||
|
||||
/** Gridded math inset base class.
|
||||
@ -20,15 +21,8 @@ class MathGridInset : public MathNestInset {
|
||||
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_;
|
||||
@ -37,45 +31,45 @@ public:
|
||||
};
|
||||
|
||||
/// 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:
|
||||
@ -220,8 +214,6 @@ protected:
|
||||
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);
|
||||
|
||||
|
@ -137,6 +137,9 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
|
||||
}
|
||||
|
||||
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 << "\\]";
|
||||
|
@ -23,44 +23,10 @@ using std::ostringstream;
|
||||
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);
|
||||
@ -73,7 +39,7 @@ int string2int(string const & s, int deflt = 0)
|
||||
string read_hlines(Parser & p)
|
||||
{
|
||||
ostringstream os;
|
||||
p.skipSpaces();
|
||||
p.skip_spaces();
|
||||
while (p.good()) {
|
||||
if (p.next_token().cs() == "hline") {
|
||||
p.get_token();
|
||||
@ -83,7 +49,7 @@ string read_hlines(Parser & p)
|
||||
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";
|
||||
@ -111,24 +77,13 @@ char const TAB = '\001';
|
||||
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
|
||||
@ -140,7 +95,7 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo)
|
||||
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;
|
||||
@ -152,7 +107,7 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo)
|
||||
colinfo.push_back(ColInfo());
|
||||
colinfo.back().align = nextalign;
|
||||
colinfo.back().width = p.verbatim_item();
|
||||
nextalign = "block";
|
||||
nextalign = 'b';
|
||||
break;
|
||||
case '|':
|
||||
if (colinfo.empty())
|
||||
@ -163,9 +118,9 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo)
|
||||
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;
|
||||
@ -242,7 +197,6 @@ void parse_table(Parser & p, ostream & os, unsigned flags)
|
||||
}
|
||||
|
||||
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;
|
||||
@ -414,7 +368,7 @@ void handle_tabular(Parser & p, ostream & os)
|
||||
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?
|
||||
@ -434,7 +388,7 @@ void handle_tabular(Parser & p, ostream & os)
|
||||
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?
|
||||
@ -505,7 +459,7 @@ void handle_tabular(Parser & p, ostream & os)
|
||||
// cerr << " topline=\"true\"";
|
||||
//if (cell.bottomline)
|
||||
// cerr << " bottomline=\"true\"";
|
||||
os << " alignment=\"" << cell.align << "\""
|
||||
os << " alignment=\"" << verbose_align(cell.align) << "\""
|
||||
<< " valignment=\"top\""
|
||||
<< " usebox=\"none\""
|
||||
<< ">"
|
||||
|
@ -40,7 +40,7 @@ void handle_comment(Parser & p)
|
||||
s += t.asString();
|
||||
}
|
||||
//cerr << "comment: " << s << "\n";
|
||||
p.skipSpaces();
|
||||
p.skip_spaces();
|
||||
}
|
||||
|
||||
|
||||
|
@ -166,7 +166,7 @@ Token const & Parser::get_token()
|
||||
}
|
||||
|
||||
|
||||
void Parser::skipSpaces()
|
||||
void Parser::skip_spaces()
|
||||
{
|
||||
while (1) {
|
||||
if (next_token().cat() == catSpace || next_token().cat() == catNewline)
|
||||
@ -202,7 +202,7 @@ char Parser::getChar()
|
||||
|
||||
string Parser::getArg(char left, char right)
|
||||
{
|
||||
skipSpaces();
|
||||
skip_spaces();
|
||||
|
||||
string result;
|
||||
char c = getChar();
|
||||
@ -341,7 +341,7 @@ string Parser::verbatim_item()
|
||||
{
|
||||
if (!good())
|
||||
error("stream bad");
|
||||
skipSpaces();
|
||||
skip_spaces();
|
||||
if (next_token().cat() == catBegin) {
|
||||
Token t = get_token(); // skip brace
|
||||
string res;
|
||||
|
@ -128,7 +128,7 @@ public:
|
||||
///
|
||||
Token const & get_token();
|
||||
/// skips spaces if any
|
||||
void skipSpaces();
|
||||
void skip_spaces();
|
||||
///
|
||||
void lex(string const & s);
|
||||
///
|
||||
|
@ -332,7 +332,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer)
|
||||
}
|
||||
|
||||
else if (t.cs() == "item") {
|
||||
p.skipSpaces();
|
||||
p.skip_spaces();
|
||||
string s;
|
||||
if (p.next_token().character() == '[') {
|
||||
p.get_token(); // eat '['
|
||||
@ -350,7 +350,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer)
|
||||
}
|
||||
|
||||
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";
|
||||
|
Loading…
Reference in New Issue
Block a user