]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/formula.C
fix typo that put too many include paths for most people
[lyx.git] / src / mathed / formula.C
index 121bef4c55cb09c843d8799cdaff851aa9c87504..a58b4911dc221abd1c6213b01b2234922703de2c 100644 (file)
@@ -34,7 +34,7 @@
 #include "support/LOstream.h"
 #include "support/LAssert.h"
 #include "support/lyxlib.h"
-#include "support/syscall.h"
+#include "support/systemcall.h"
 #include "support/lstrings.h"
 #include "support/filetools.h" // LibFileSearch
 #include "LyXView.h"
@@ -43,6 +43,7 @@
 #include "math_hullinset.h"
 #include "math_support.h"
 #include "math_mathmlstream.h"
+#include "textpainter.h"
 
 using std::ostream;
 using std::ifstream;
@@ -60,7 +61,8 @@ namespace {
                string outfile = lyx::tempName(string(), "mathextern");
                string full =  "echo '" + data + "' | (" + cmd + ") > " + outfile;
                lyxerr << "calling: " << full << "\n";
-               Systemcalls dummy(Systemcalls::Wait, full);
+               Systemcall dummy;
+               dummy.startscript(Systemcall::Wait, full);
                string out = GetFileContents(outfile);
                lyx::unlink(outfile);
                lyxerr << "result: '" << out << "'\n";
@@ -90,7 +92,7 @@ namespace {
                                        "eval(`latex/latex/*`)):\n";
 
                // remove spurious \\noalign{\\medskip} in matrix output
-               header += 
+               header +=
                        "`latex/latex/matrix`:= "
                                "subs(`\\\\\\\\\\\\noalign{\\\\medskip}` = `\\\\\\\\`,"
                                        "eval(`latex/latex/matrix`)):\n";
@@ -109,7 +111,7 @@ namespace {
                        //
                        // ... > echo "1A;" | mint -i 1 -S -s -q
                        // on line     1: 1A;
-                       //                 ^ syntax error - 
+                       //                 ^ syntax error -
                        //                   Probably missing an operator such as * p
                        //
                        lyxerr << "checking expr: '" << expr << "'\n";
@@ -141,8 +143,8 @@ namespace {
                mathed_parse_cell(res, out);
                return res;
        }
-               
-       
+
+
        MathArray pipeThroughOctave(string const &, MathArray const & ar)
        {
                ostringstream os;
@@ -153,13 +155,13 @@ namespace {
 
                for (int i = 0; i < 100; ++i) { // at most 100 attempts
                        //
-                       // try to fix missing '*' the hard way 
+                       // try to fix missing '*' the hard way
                        // parse error:
                        // >>> ([[1 2 3 ];[2 3 1 ];[3 1 2 ]])([[1 2 3 ];[2 3 1 ];[3 1 2 ]])
                        //                                   ^
                        //
                        lyxerr << "checking expr: '" << expr << "'\n";
-                       out = captureOutput("octave -q 2>&1", expr);
+                       out = captureOutput("octave -q 2>&1", expr);
                        lyxerr << "checking out: '" << out << "'\n";
 
                        // leave loop if expression syntax is probably ok
@@ -232,7 +234,7 @@ namespace {
                        lyxerr << "converter to '" << lang << "' not found\n";
                        return MathArray();
                }
-               
+
                // run external sript
                string out = captureOutput(file, data);
                MathArray res;
@@ -253,7 +255,7 @@ InsetFormula::InsetFormula(MathInsetTypes t)
 {}
 
 
-InsetFormula::InsetFormula(string const & s) 
+InsetFormula::InsetFormula(string const & s)
 {
        if (s.size()) {
                bool res = mathed_parse_normal(par_, s);
@@ -276,16 +278,17 @@ Inset * InsetFormula::clone(Buffer const &, bool) const
 }
 
 
-void InsetFormula::write(Buffer const * buf, ostream & os) const
+void InsetFormula::write(Buffer const *, ostream & os) const
 {
        os << "Formula ";
-       latex(buf, os, false, false);
+       WriteStream wi(os, false, false);
+       par_->write(wi);
 }
 
 
-int InsetFormula::latex(Buffer const *, ostream & os, bool fragil, bool) const
+int InsetFormula::latex(Buffer const *, ostream & os, bool fragile, bool) const
 {
-       WriteStream wi(os, fragil);
+       WriteStream wi(os, fragile, true);
        par_->write(wi);
        return wi.line();
 }
@@ -293,9 +296,20 @@ int InsetFormula::latex(Buffer const *, ostream & os, bool fragil, bool) const
 
 int InsetFormula::ascii(Buffer const *, ostream & os, int) const
 {
+#if 1
+       TextMetricsInfo mi;
+       par()->metricsT(mi);
+       TextPainter tpain(par()->width(), par()->height());
+       par()->drawT(tpain, 0, par()->ascent());
+       tpain.show(os);
+       // reset metrics cache to "real" values
+       metrics();
+       return tpain.textheight();
+#else
        WriteStream wi(os, false);
        par_->write(wi);
        return wi.line();
+#endif
 }
 
 
@@ -334,14 +348,13 @@ void InsetFormula::read(Buffer const *, LyXLex & lex)
 void InsetFormula::draw(BufferView * bv, LyXFont const & font,
                        int y, float & xx, bool) const
 {
-       int x = int(xx);
-
-       Painter & pain = bv->painter();
-
        metrics(bv, font);
+
+       int x = int(xx);
        int w = par_->width();
        int h = par_->height();
        int a = par_->ascent();
+       Painter & pain = bv->painter();
 
        if (lcolor.getX11Name(LColor::mathbg)!=lcolor.getX11Name(LColor::background))
                pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
@@ -376,7 +389,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
 
        switch (action) {
 
-               case LFUN_BREAKLINE: 
+               case LFUN_BREAKLINE:
                        bv->lockedInsetStoreUndo(Undo::INSERT);
                        mathcursor->breakLine();
                        mathcursor->normalize();
@@ -484,11 +497,11 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        updateLocal(bv, true);
                        break;
                }
-               
+
                case LFUN_PASTESELECTION:
                {
                        string const clip = bv->getClipboard();
-               if (!clip.empty())
+               if (!clip.empty())
                                mathed_parse_normal(par_, clip);
                        break;
                }
@@ -511,14 +524,14 @@ void InsetFormula::handleExtern(const string & arg)
 {
        // where are we?
        if (!mathcursor)
-               return; 
+               return;
 
        string lang;
        string extra;
        istringstream iss(arg.c_str());
        iss >> lang >> extra;
        if (extra.empty())
-               extra = "noextra";      
+               extra = "noextra";
 
        bool selected = mathcursor->selection();
 
@@ -576,9 +589,9 @@ void InsetFormula::validate(LaTeXFeatures & features) const
 
 bool InsetFormula::insetAllowed(Inset::Code code) const
 {
-       return 
+       return
                (code == Inset::LABEL_CODE && display())
-               || code == Inset::ERT_CODE; 
+               || code == Inset::ERT_CODE;
 }