]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/formula.C
oh well
[lyx.git] / src / mathed / formula.C
index fc759f77446e45bf82129a0703c30767ed2d166a..c145aa8fb5db8f6d0f259c1bb3c2af9707b4245c 100644 (file)
@@ -33,9 +33,7 @@
 #include "frontends/Alert.h"
 #include "support/LOstream.h"
 #include "support/LAssert.h"
-#include "support/lyxlib.h"
 #include "support/systemcall.h"
-#include "support/lstrings.h"
 #include "support/filetools.h" // LibFileSearch
 #include "LyXView.h"
 #include "Painter.h"
@@ -43,6 +41,7 @@
 #include "math_hullinset.h"
 #include "math_support.h"
 #include "math_mathmlstream.h"
+#include "textpainter.h"
 
 using std::ostream;
 using std::ifstream;
@@ -91,7 +90,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";
@@ -110,7 +109,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";
@@ -142,8 +141,8 @@ namespace {
                mathed_parse_cell(res, out);
                return res;
        }
-               
-       
+
+
        MathArray pipeThroughOctave(string const &, MathArray const & ar)
        {
                ostringstream os;
@@ -154,13 +153,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
@@ -233,7 +232,7 @@ namespace {
                        lyxerr << "converter to '" << lang << "' not found\n";
                        return MathArray();
                }
-               
+
                // run external sript
                string out = captureOutput(file, data);
                MathArray res;
@@ -254,7 +253,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);
@@ -277,16 +276,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();
 }
@@ -294,9 +294,20 @@ int InsetFormula::latex(Buffer const *, ostream & os, bool fragil, bool) const
 
 int InsetFormula::ascii(Buffer const *, ostream & os, int) const
 {
-       WriteStream wi(os, false);
+#if 0
+       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, true);
        par_->write(wi);
        return wi.line();
+#endif
 }
 
 
@@ -376,7 +387,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 +495,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 +522,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 +587,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;
 }