add missing writeNormal() methods to some insets

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2935 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-10-24 16:10:38 +00:00
parent e3052dc18b
commit d1633491db
10 changed files with 110 additions and 86 deletions

View File

@ -201,10 +201,17 @@ void MathArray::write(MathWriteInfo & wi) const
void MathArray::writeNormal(ostream & os) const
{
os << "[par ";
for (const_iterator it = begin(); it != end(); ++it)
(*it)->writeNormal(os);
os << "]";
for (const_iterator it = begin(); it != end(); ++it) {
MathInset * p = it->nucleus();
if (!p)
continue;
if (MathScriptInset const * q = asScript(it)) {
q->writeNormal(p, os);
++it;
} else {
p->writeNormal(os);
}
}
}

View File

@ -18,7 +18,6 @@
#endif
#include <config.h>
#include <fstream>
#include "formula.h"
#include "commandtags.h"
@ -35,6 +34,7 @@
#include "support/lyxlib.h"
#include "support/syscall.h"
#include "support/lstrings.h"
#include "support/filetools.h" // LibFileSearch
#include "LyXView.h"
#include "Painter.h"
#include "lyxrc.h"
@ -63,6 +63,40 @@ namespace {
ar.erase(pos, ar.size());
}
MathArray pipeThroughExtern(string const & arg, MathArray const & ar)
{
string lang;
string extra;
istringstream iss(arg.c_str());
iss >> lang >> extra;
if (extra.empty())
extra = "noextra";
// create normalized expression
string outfile = lyx::tempName(string(), "mathextern");
ostringstream os;
os << "[" << extra << ' ';
ar.writeNormal(os);
os << "]";
string code = os.str().c_str();
// run external sript
string file = LibFileSearch(string(), "lyx2" + lang);
if (file.empty()) {
lyxerr << "converter to '" << lang << "' not found\n";
return MathArray();
}
string script = file + " '" + code + "' " + outfile;
lyxerr << "calling: " << script << endl;
Systemcalls cmd(Systemcalls::System, script, 0);
// append result
MathArray res;
mathed_parse_cell(res, GetFileContents(outfile));
return res;
}
}
@ -317,49 +351,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
return result;
}
#if 0
void InsetFormula::handleExtern(const string & arg)
{
// where are we?
if (!mathcursor)
return;
MathArray & ar = mathcursor->cursor().cell();
// parse args
string lang;
string extra;
istringstream iss(arg.c_str());
iss >> lang >> extra;
if (extra.empty())
extra = "noextra";
// strip last '=' and everything behind
stripFromLastEqualSign(ar);
// create normalized expression
//string outfile = lyx::tempName("maple.out");
string outfile = "/tmp/lyx2" + lang + ".out";
ostringstream os;
os << "[" << extra << ' ';
ar.writeNormal(os);
os << "]";
string code = os.str().c_str();
// run external sript
string script = "lyx2" + arg + " '" + code + "' " + outfile;
lyxerr << "calling: " << script << endl;
Systemcalls cmd(Systemcalls::System, script, 0);
// append a '='
ar.push_back(MathAtom(new MathCharInset('=')));
// append result
ifstream is(outfile.c_str());
mathed_parse_cell(ar, is);
mathcursor->end();
}
#endif
void InsetFormula::handleExtern(const string & arg)
{
@ -374,45 +365,17 @@ void InsetFormula::handleExtern(const string & arg)
mathcursor->selGet(ar);
lyxerr << "use selection: " << ar << "\n";
} else {
mathcursor->end();
ar = mathcursor->cursor().cell();
stripFromLastEqualSign(ar);
mathcursor->insert(MathAtom(new MathCharInset('=', LM_TC_VAR)));
lyxerr << "use whole cell: " << ar << "\n";
}
// parse args
string lang;
string extra;
istringstream iss(arg.c_str());
iss >> lang >> extra;
if (extra.empty())
extra = "noextra";
// strip last '=' and everything behind
stripFromLastEqualSign(ar);
// create normalized expression
//string outfile = lyx::tempName("maple.out");
string outfile = "/tmp/lyx2" + lang + ".out";
ostringstream os;
os << "[" << extra << ' ';
ar.writeNormal(os);
os << "]";
string code = os.str().c_str();
// run external sript
string script = "lyx2" + lang + " '" + code + "' " + outfile;
lyxerr << "calling: " << script << endl;
Systemcalls cmd(Systemcalls::System, script, 0);
// append result
MathArray br;
if (selected)
br.push_back(MathAtom(new MathCharInset('=', LM_TC_VAR)));
ifstream is(outfile.c_str());
mathed_parse_cell(br, is);
mathcursor->insert(br);
mathcursor->insert(pipeThroughExtern(arg, ar));
}
bool InsetFormula::display() const
{
return mat()->getType() != LM_OT_SIMPLE;

View File

@ -119,7 +119,7 @@ void MathCharInset::write(MathWriteInfo & os) const
void MathCharInset::writeNormal(std::ostream & os) const
{
os << char_;
os << "[char " << char_ << " " << "mathalpha" << "]";
}

View File

@ -702,7 +702,8 @@ void MathCursor::selDel()
seldump("selDel");
if (selection_) {
theSelection.erase(*this);
pos() = 0;
if (pos() > size())
pos() = size();
selClear();
}
}

View File

@ -49,6 +49,12 @@ void MathDelimInset::write(MathWriteInfo & os) const
}
void MathDelimInset::writeNormal(std::ostream & os) const
{
os << "[delim " << latexName(left_) << " " << latexName(right_) << "]";
}
int MathDelimInset::dw() const
{
int w = height() / 5;

View File

@ -23,6 +23,8 @@ public:
void draw(Painter &, int x, int y) const;
///
void write(MathWriteInfo & os) const;
/// write normalized content
void writeNormal(std::ostream &) const;
///
void metrics(MathMetricsInfo const & st) const;
private:

View File

@ -70,7 +70,7 @@ void MathRootInset::writeNormal(std::ostream & os) const
cell(1).writeNormal(os);
os << " ";
cell(0).writeNormal(os);
os << "] ";
os << "]";
}

View File

@ -1,4 +1,7 @@
#include <config.h>
#include <sstream>
#include "debug.h"
#include "support.h"
#include "support/LOstream.h"
@ -10,6 +13,8 @@
#include "math_scriptinset.h"
using std::ostringstream;
MathScriptInset::MathScriptInset()
: MathNestInset(2), limits_(0)
@ -27,7 +32,6 @@ MathScriptInset::MathScriptInset(bool up)
}
MathInset * MathScriptInset::clone() const
{
return new MathScriptInset(*this);
@ -251,6 +255,43 @@ void MathScriptInset::write(MathInset const * nuc, MathWriteInfo & os) const
}
void MathScriptInset::writeNormal(ostream & os) const
{
//lyxerr << "unexpected call to MathScriptInset::writeNormal()\n";
writeNormal(0, os);
}
void MathScriptInset::writeNormal(MathInset const * nuc, ostream & os) const
{
bool d = hasDown() && down().data_.size();
bool u = hasUp() && up().data_.size();
ostringstream osb;
if (nuc)
nuc->writeNormal(osb);
else
osb << "[par]";
string base = osb.str();
if (u && d) {
os << "[sup [sub " << osb.str() << " ";
down().data_.writeNormal(os);
os << "]";
up().data_.writeNormal(os);
os << ']';
} else if (u) {
os << "[sup " << osb.str() << " ";
up().data_.writeNormal(os);
os << ']';
} else if (d) {
os << "[sub " << osb.str() << " ";
down().data_.writeNormal(os);
os << ']';
}
}
bool MathScriptInset::hasLimits(MathInset const * nuc) const
{
return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());

View File

@ -23,6 +23,8 @@ public:
///
void write(MathWriteInfo & os) const;
///
void writeNormal(ostream & os) const;
///
void metrics(MathMetricsInfo const & st) const;
///
void draw(Painter &, int x, int y) const;
@ -30,6 +32,8 @@ public:
///
void write(MathInset const *, MathWriteInfo & os) const;
///
void writeNormal(MathInset const *, ostream & os) const;
///
void metrics(MathInset const * nucleus, MathMetricsInfo const & st) const;
///
void draw(MathInset const * nucleus, Painter &, int x, int y) const;

View File

@ -53,5 +53,5 @@ void MathSqrtInset::writeNormal(std::ostream & os) const
{
os << "[sqrt ";
cell(0).writeNormal(os);
os << "] ";
os << "]";
}