fix random crashes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6867 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-04-28 08:44:56 +00:00
parent a52a7b5895
commit defe8051ab
9 changed files with 93 additions and 60 deletions

View File

@ -1,3 +1,4 @@
2003-04-14 Angus Leeming <leeming@lyx.org>
* math_fboxinset.C:

View File

@ -47,16 +47,9 @@
#include "graphics/PreviewedInset.h"
#include "graphics/PreviewImage.h"
#include <fstream>
using std::ostream;
using std::ifstream;
using std::istream;
using std::pair;
using std::endl;
using std::vector;
using std::getline;
class InsetFormula::PreviewImpl : public grfx::PreviewedInset {
@ -78,10 +71,13 @@ private:
InsetFormula::InsetFormula()
InsetFormula::InsetFormula(bool chemistry)
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{}
{
if (chemistry)
mutate("chemistry");
}
InsetFormula::InsetFormula(InsetFormula const & other)
@ -182,6 +178,19 @@ int InsetFormula::docbook(Buffer const * buf, ostream & os, bool) const
void InsetFormula::read(Buffer const *, LyXLex & lex)
{
mathed_parse_normal(par_, lex);
// remove extra 'mathrm' for chemistry stuff.
// will be re-added on write
if (par_->asHullInset()->getType() =="chemistry") {
lyxerr << "this is chemistry\n";
if (par_->cell(0).size() == 1) {
lyxerr << "this is size 1\n";
if (par_->cell(0)[0]->asFontInset()) {
lyxerr << "this is a font inset \n";
lyxerr << "replacing " << par_.nucleus()->cell(0) <<
" with " << par_->cell(0)[0]->cell(0) << "\n";
}
}
}
metrics();
}
@ -293,12 +302,10 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
}
/*
void InsetFormula::mutate(string const & type)
{
par_.nucleus()->mutate(type);
}
*/
//

View File

@ -25,7 +25,7 @@
class InsetFormula : public InsetFormulaBase {
public:
///
InsetFormula();
InsetFormula(bool chemistry = false);
///
explicit InsetFormula(BufferView *);
///
@ -75,7 +75,7 @@ public:
///
void addPreview(grfx::PreviewLoader &) const;
///
//void mutate(string const & type);
void mutate(string const & type);
private:
/// available in AMS only?

View File

@ -211,13 +211,13 @@ char MathGridInset::valign() const
MathGridInset::col_type MathGridInset::ncols() const
{
return colinfo_.size() - 1;
return colinfo_.size();
}
MathGridInset::row_type MathGridInset::nrows() const
{
return rowinfo_.size() - 1;
return rowinfo_.size();
}
@ -263,12 +263,10 @@ void MathGridInset::metrics(MetricsInfo & mi) const
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_ +
@ -290,7 +288,7 @@ void MathGridInset::metrics(MetricsInfo & mi) const
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;
@ -301,11 +299,10 @@ void MathGridInset::metrics(MetricsInfo & mi) const
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_ +
@ -315,19 +312,19 @@ void MathGridInset::metrics(MetricsInfo & mi) const
}
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();
@ -389,14 +386,14 @@ void MathGridInset::draw(PainterInfo & pi, int x, int y) const
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;
@ -430,7 +427,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
// 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_ +
@ -452,7 +449,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
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;
@ -467,7 +464,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
// 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_ +
@ -908,12 +905,12 @@ void MathGridInset::write(WriteStream & os) const
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;
//}
}

View File

@ -69,15 +69,16 @@ namespace {
{
if (s == "none") return 0;
if (s == "simple") return 1;
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;
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;
lyxerr << "unknown hull type '" << s << "'\n";
return 0;
}
@ -162,6 +163,8 @@ char const * MathHullInset::standardFont() const
{
if (type_ == "none")
return "lyxnochange";
if (type_ == "chemistry")
return "mathrm";
return "mathnormal";
}
@ -290,7 +293,7 @@ bool MathHullInset::ams() const
bool MathHullInset::display() const
{
return type_ != "simple" && type_ != "none";
return type_ != "simple" && type_ != "none" && type_ != "chemistry";
}
@ -306,6 +309,8 @@ bool MathHullInset::numberedType() const
{
if (type_ == "none")
return false;
if (type_ == "chemistry")
return false;
if (type_ == "simple")
return false;
if (type_ == "xxalignat")
@ -348,6 +353,9 @@ void MathHullInset::header_write(WriteStream & os) const
os << ' ';
}
else if (type_ == "chemistry")
os << "$\\mathrm{";
else if (type_ == "equation") {
if (n)
os << "\\begin{equation" << star(n) << "}\n";
@ -382,6 +390,9 @@ void MathHullInset::footer_write(WriteStream & os) const
else if (type_ == "simple")
os << '$';
else if (type_ == "chemistry")
os << "}$";
else if (type_ == "equation")
if (n)
os << "\\end{equation" << star(n) << "}\n";
@ -495,22 +506,22 @@ void MathHullInset::mutate(string const & newtype)
// done
}
else if (type_ == "none") {
setType("simple");
else if (newtype == "none" || newtype == "chemistry") {
mutate("simple");
numbered(0, false);
mutate(newtype);
}
else if (type_ == "simple") {
if (newtype == "none") {
setType("none");
} else {
setType("equation");
else if (newtype == "simple") {
if (type_ != "none" && type_ != "chemistry") {
mutate("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");
@ -614,6 +625,8 @@ void MathHullInset::mutate(string const & newtype)
lyxerr << "mutation from '" << type_
<< "' to '" << newtype << "' not implemented" << endl;
}
setType(newtype);
}
@ -842,3 +855,11 @@ dispatch_result MathHullInset::dispatch
}
return UNDISPATCHED;
}
string MathHullInset::fileInsetLabel() const
{
if (type_ == "chemistry")
return "Chemistry";
return "Formula";
}

View File

@ -79,6 +79,8 @@ public:
///
bool idxLast(idx_type &, pos_type &) const;
///
string fileInsetLabel() const;
///
void write(WriteStream & os) const;
///

View File

@ -276,7 +276,7 @@ int MathInset::docbook(std::ostream &, bool) const
string const & MathInset::getType() const
{
static string t("none");
static string const t("none");
return t;
}
@ -311,3 +311,8 @@ ostream & operator<<(ostream & os, MathAtom const & at)
return os;
}
string MathInset::fileInsetLabel() const
{
return "Formula";
}

View File

@ -299,7 +299,7 @@ public:
/// change type
virtual void mutate(string const &) {}
/// how is the inset called in the .lyx file?
virtual string fileInsetLabel() const { return "Formula"; }
virtual string fileInsetLabel() const;
/// usually the latex name
virtual string name() const;

View File

@ -1213,10 +1213,10 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
MathAtom at = createMathInset(t.cs());
MathInset::mode_type m = mode;
//if (m == MathInset::UNDECIDED_MODE)
lyxerr << "default creation: m1: " << m << "\n";
//lyxerr << "default creation: m1: " << m << "\n";
if (at->currentMode() != MathInset::UNDECIDED_MODE)
m = at->currentMode();
lyxerr << "default creation: m2: " << m << "\n";
//lyxerr << "default creation: m2: " << m << "\n";
MathInset::idx_type start = 0;
// this fails on \bigg[...\bigg]
//MathArray opt;