+
2003-04-14 Angus Leeming <leeming@lyx.org>
* math_fboxinset.C:
#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 {
-InsetFormula::InsetFormula()
+InsetFormula::InsetFormula(bool chemistry)
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
-{}
+{
+ if (chemistry)
+ mutate("chemistry");
+}
InsetFormula::InsetFormula(InsetFormula const & other)
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();
}
}
-/*
void InsetFormula::mutate(string const & type)
{
par_.nucleus()->mutate(type);
}
-*/
//
class InsetFormula : public InsetFormulaBase {
public:
///
- InsetFormula();
+ InsetFormula(bool chemistry = false);
///
explicit InsetFormula(BufferView *);
///
///
void addPreview(grfx::PreviewLoader &) const;
///
- //void mutate(string const & type);
+ void mutate(string const & type);
private:
/// available in AMS only?
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();
}
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;
// 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;
// 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_ +
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;
+ //}
}
{
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;
}
{
if (type_ == "none")
return "lyxnochange";
+ if (type_ == "chemistry")
+ return "mathrm";
return "mathnormal";
}
bool MathHullInset::display() const
{
- return type_ != "simple" && type_ != "none";
+ return type_ != "simple" && type_ != "none" && type_ != "chemistry";
}
{
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 (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");
lyxerr << "mutation from '" << type_
<< "' to '" << newtype << "' not implemented" << endl;
}
+
+ setType(newtype);
}
}
return UNDISPATCHED;
}
+
+
+string MathHullInset::fileInsetLabel() const
+{
+ if (type_ == "chemistry")
+ return "Chemistry";
+ return "Formula";
+}
///
bool idxLast(idx_type &, pos_type &) const;
+ ///
+ string fileInsetLabel() const;
///
void write(WriteStream & os) const;
///
string const & MathInset::getType() const
{
- static string t("none");
+ static string const t("none");
return t;
}
return os;
}
+
+string MathInset::fileInsetLabel() const
+{
+ return "Formula";
+}
/// 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;
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;