]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathFrac.cpp
add busy.gif to resources (in line with cmake)
[lyx.git] / src / mathed / InsetMathFrac.cpp
index 3fbd56d8fdfc1bf552538258d4a4455d2a4af2be..752dd54bea51d3583dce802437256697012bec37 100644 (file)
@@ -17,7 +17,6 @@
 #include "Cursor.h"
 #include "LaTeXFeatures.h"
 #include "MathData.h"
-#include "MathExtern.h"
 #include "MathStream.h"
 #include "MathSupport.h"
 #include "MetricsInfo.h"
@@ -168,7 +167,7 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
                        dim.des = dim1.height() - 5;
                } else {
                        if (kind_ == CFRAC || kind_ == CFRACLEFT
-                       || kind_ == CFRACRIGHT || kind_ == DFRAC) {
+                                 || kind_ == CFRACRIGHT || kind_ == DFRAC) {
                                // \cfrac and \dfrac are always in display size
                                StyleChanger dummy2(mi.base, LM_ST_DISPLAY);
                                cell(0).metrics(mi, dim0);
@@ -255,13 +254,13 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
                pi.pain.line(xx + dim0.wid,
                                y + dim.des - 2,
                                xx + dim0.wid + 5,
-                               y - dim.asc + 2, Color_math);
+                               y - dim.asc + 2, pi.base.font.color());
        }
        if (kind_ == FRAC || kind_ == CFRAC || kind_ == CFRACLEFT
                || kind_ == CFRACRIGHT || kind_ == DFRAC
                || kind_ == TFRAC || kind_ == OVER)
                pi.pain.line(x + 1, y - 5,
-                               x + dim.wid - 2, y - 5, Color_math);
+                               x + dim.wid - 2, y - 5, pi.base.font.color());
        drawMarkers(pi, x, y);
 }
 
@@ -385,14 +384,21 @@ void InsetMathFrac::octave(OctaveStream & os) const
 }
 
 
-docstring InsetMathFrac::mathmlize(MathStream & os) const
+void InsetMathFrac::mathmlize(MathStream & os) const
 {
-       os << MTag("mfrac") << MTag("mrow");
-       docstring rv = lyx::mathmlize(cell(0), os);
-       os << ETag("mrow") << MTag("mrow");
-       rv += lyx::mathmlize(cell(1), os);
-       os << ETag("mrow") << ETag("mfrac");
-       return rv;
+       os << MTag("mfrac")
+          << MTag("mrow") << cell(0) << ETag("mrow")
+                << MTag("mrow") << cell(1) << ETag("mrow")
+                << ETag("mfrac");
+}
+
+
+void InsetMathFrac::htmlize(HtmlStream & os) const
+{
+       os << MTag("span", "class='frac'")
+                << MTag("span", "class='numer'") << cell(0) << ETag("span")
+                << MTag("span", "class='denom'") << cell(1) << ETag("span")
+                << ETag("span");
 }
 
 
@@ -401,8 +407,15 @@ void InsetMathFrac::validate(LaTeXFeatures & features) const
        if (kind_ == NICEFRAC || kind_ == UNITFRAC || kind_ == UNIT)
                features.require("units");
        if (kind_ == CFRAC || kind_ == CFRACLEFT || kind_ == CFRACRIGHT
-               || kind_ == DFRAC || kind_ == TFRAC)
+                 || kind_ == DFRAC || kind_ == TFRAC)
                features.require("amsmath");
+       if (features.runparams().math_flavor == OutputParams::MathAsHTML)
+               // CSS adapted from eLyXer
+               features.addPreambleSnippet("<style type=\"text/css\">\n"
+                       "span.frac{display: inline-block; vertical-align: middle; text-align:center;}\n"
+                       "span.numer{display: block;}\n"
+                       "span.denom{display: block; border-top: thin solid #000040;}\n"
+                       "</style>");
        InsetMathNest::validate(features);
 }
 
@@ -536,31 +549,78 @@ void InsetMathBinom::normalize(NormalStream & os) const
 }
 
 
-docstring InsetMathBinom::mathmlize(MathStream & os) const
+void InsetMathBinom::mathmlize(MathStream & os) const
 {
-       // FIXME This all needs fixing
+       char ldelim = ' ';
+       char rdelim = ' ';
        switch (kind_) {
        case BINOM:
-               os << MTag("mbinom") << cell(0) << cell(1) << ETag("mbinom");
-               break;
        case TBINOM:
-               os << MTag("mtbinom") << cell(0) << cell(1) << ETag("mtbinom");
+       case DBINOM:
+       case CHOOSE:
+               ldelim = '(';
+               rdelim = ')';
                break;
+       case BRACE:
+               ldelim = '{';
+               rdelim = '}';
+               break;
+       case BRACK:
+               ldelim = '[';
+               rdelim = ']';
+               break;
+       }
+       os << "<mo fence='true' stretchy='true' form='prefix'>" << ldelim << "</mo>"
+          << "<mfrac linethickness='0'>"
+          << cell(0) << cell(1)
+          << "</mfrac>"
+          << "<mo fence='true' stretchy='true' form='postfix'>" << rdelim << "</mo>";
+}
+
+
+void InsetMathBinom::htmlize(HtmlStream & os) const
+{
+       char ldelim = ' ';
+       char rdelim = ' ';
+       switch (kind_) {
+       case BINOM:
+       case TBINOM:
        case DBINOM:
-       default:
-               os << MTag("mdbinom") << cell(0) << cell(1) << ETag("mdbinom");
+       case CHOOSE:
+               ldelim = '(';
+               rdelim = ')';
+               break;
+       case BRACE:
+               ldelim = '{';
+               rdelim = '}';
+               break;
+       case BRACK:
+               ldelim = '[';
+               rdelim = ']';
                break;
        }
-       return docstring();
+       os << MTag("span", "class='binomdelim'") << ldelim << ETag("span") << '\n'
+          << MTag("span", "class='binom'") << '\n'
+          << MTag("span") << cell(0) << ETag("span") << '\n'
+          << MTag("span") << cell(1) << ETag("span") << '\n'
+          << ETag("span") << '\n'
+                << MTag("span", "class='binomdelim'") << rdelim << ETag("span") << '\n';
 }
 
 
 void InsetMathBinom::validate(LaTeXFeatures & features) const
 {
-       if (kind_ == BINOM)
-               features.require("binom");
-       if (kind_ == DBINOM || kind_ == TBINOM)
-               features.require("amsmath");
+       if (features.runparams().isLaTeX()) {
+               if (kind_ == BINOM)
+                       features.require("binom");
+               if (kind_ == DBINOM || kind_ == TBINOM)
+                       features.require("amsmath");
+       } else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
+               features.addPreambleSnippet("<style type=\"text/css\">\n"
+                       "span.binom{display: inline-block; vertical-align: bottom; text-align:center;}\n"
+                       "span.binom span{display: block;}\n"
+                       "span.binomdelim{font-size: 2em;}\n"
+                       "</style>");
        InsetMathNest::validate(features);
 }