]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathBig.cpp
Remove hardcoded values
[lyx.git] / src / mathed / InsetMathBig.cpp
index 128cade0d6258939a9111d3802233712ffe42a67..eeaf96514bd97fdd32d6c9d79585f9fc4e294785 100644 (file)
@@ -12,6 +12,9 @@
 
 #include "InsetMathBig.h"
 
+#include "Dimension.h"
+#include "LaTeXFeatures.h"
+
 #include "MathSupport.h"
 #include "MathStream.h"
 #include "MetricsInfo.h"
@@ -46,9 +49,11 @@ InsetMathBig::size_type InsetMathBig::size() const
 {
        // order: big Big bigg Bigg biggg Biggg
        //        0   1   2    3    4     5
+       char_type const c = name_[name_.size() - 1];
+       int const base_size = (c == 'l' || c == 'm' || c == 'r') ? 4 : 3;
        return name_[0] == 'B' ?
-               2 * (name_.size() - 4) + 1:
-               2 * (name_.size() - 4);
+               2 * (name_.size() - base_size) + 1:
+               2 * (name_.size() - base_size);
 }
 
 
@@ -64,6 +69,7 @@ double InsetMathBig::increase() const
 
 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       Changer dummy = mi.base.changeEnsureMath();
        double const h = theFontMetrics(mi.base.font).ascent('I');
        double const f = increase();
        dim.wid = 6;
@@ -72,18 +78,26 @@ void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
-void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
+docstring InsetMathBig::word() const
 {
-       Dimension const dim = dimension(*pi.base.bv);
        // mathed_draw_deco does not use the leading backslash, so remove it
        // (but don't use ltrim if this is the backslash delimiter).
        // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
        // would treat it as |.
-       docstring const delim = (delim_ == "\\|") ?  from_ascii("Vert") :
-               (delim_ == "\\\\") ? from_ascii("\\") : support::ltrim(delim_, "\\");
+       if (delim_ == "\\|")
+               return from_ascii("Vert");
+       if (delim_ == "\\\\")
+               return from_ascii("\\");
+       return support::ltrim(delim_, "\\");
+}
+
+
+void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
+{
+       Changer dummy = pi.base.changeEnsureMath();
+       Dimension const dim = dimension(*pi.base.bv);
        mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(),
-                        delim);
-       setPosCache(pi, x, y);
+                        word());
 }
 
 
@@ -102,51 +116,26 @@ void InsetMathBig::normalize(NormalStream & os) const
 }
 
 
-docstring InsetMathBig::mathmlize(MathStream & os) const
+void InsetMathBig::mathmlize(MathStream & os) const
 {
-       os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>";
-       if (delim_ == "(" || delim_ == ")"
-                       || delim_ == "[" || delim_ == "]"
-                       || delim_ == "|" || delim_ == "/")
-               os << delim_;
-       else if (delim_ == "\\{" || delim_ == "\\lbrace")
-               os << "{";
-       else if (delim_ == "\\}" || delim_ == "\\rbrace")
-               os << "}";
-       else if (delim_ == "\\slash")
-               os << "/";
-       else if (delim_ == "\\|" || delim_ == "\\vert")
-               os << "|";
-       else if (delim_ == "\\Vert")
-               os << "&par;";
-       else if (delim_ == "\\\\" || delim_ == "\\backslash")
-               os <<" \\";
-       else if (delim_ == "\\langle")
-               os << "&lt;";
-       else if (delim_ == "\\rangle")
-               os << "&gt;";
-       else if (delim_ == "\\lceil")
-               os << "&lceil;";
-       else if (delim_ == "\\rceil")
-               os << "&rceil;";
-       else if (delim_ == "\\lfloor")
-               os << "&lfloor;";
-       else if (delim_ == "\\rfloor")
-               os << "&rfloor;";
-       else if (delim_ == "\\downarrow")
-               os << "&darr;";
-       else if (delim_ == "\\uparrow")
-               os << "&uarr;";
-       else if (delim_ == "\\Downarrow")
-               os << "&dArr;";
-       else if (delim_ == "\\Uparrow")
-               os << "&uArr;";
-       else if (delim_ == "\\updownarrow")
-               os << "&varr;";
-       else if (delim_ == "\\Updownarrow")
-               os << "&vArr;";
-       os << "</mo>";
-       return docstring();;
+       os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
+          << convertDelimToXMLEscape(delim_)
+          << "</mo>";
+}
+
+
+void InsetMathBig::htmlize(HtmlStream & os) const
+{
+       std::string name;
+       switch (size()) {
+       case 0: case 1: name = "big"; break;
+       case 2: case 3: name = "bigg"; break;
+       case 4: case 5: name = "biggg"; break;
+       default: name  = "big"; break;
+       }
+       os << MTag("span", "class='" + name + "symbol'")
+          << convertDelimToXMLEscape(delim_)
+          << ETag("span");
 }
 
 
@@ -162,9 +151,10 @@ bool InsetMathBig::isBigInsetDelim(docstring const & delim)
        static char const * const delimiters[] = {
                "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
                "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
-               "\\\\", "\\backslash",
+               "<", ">", "\\\\", "\\backslash",
                "\\langle", "\\lceil", "\\lfloor",
                "\\rangle", "\\rceil", "\\rfloor",
+               "\\llbracket", "\\rrbracket",
                "\\downarrow", "\\Downarrow",
                "\\uparrow", "\\Uparrow",
                "\\updownarrow", "\\Updownarrow", ""
@@ -173,4 +163,15 @@ bool InsetMathBig::isBigInsetDelim(docstring const & delim)
 }
 
 
+void InsetMathBig::validate(LaTeXFeatures & features) const
+{
+       validate_math_word(features, word());
+       if (features.runparams().math_flavor == OutputParams::MathAsHTML)
+               features.addCSSSnippet(
+                       "span.bigsymbol{font-size: 150%;}\n"
+                       "span.biggsymbol{font-size: 200%;}\n"
+                       "span.bigggsymbol{font-size: 225%;}");
+}
+
+
 } // namespace lyx