]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathDots.cpp
g-brief loads babel internally. So don't load it ourselves.
[lyx.git] / src / mathed / InsetMathDots.cpp
index 147e7627e48e9fc7791bb9cf66ad8470ab93c69b..ed0db97de6acc24402a51e0edfe4a6604ca77e06 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "InsetMathDots.h"
 
+#include "Dimension.h"
 #include "LaTeXFeatures.h"
 #include "MathStream.h"
 #include "MathSupport.h"
@@ -25,7 +26,7 @@
 namespace lyx {
 
 InsetMathDots::InsetMathDots(latexkeys const * key)
-       : key_(key)
+       : dh_(0), key_(key)
 {}
 
 
@@ -37,38 +38,26 @@ Inset * InsetMathDots::clone() const
 
 void InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       dim = theFontMetrics(mi.base.font).dimension('M');
+       dim = theFontMetrics(mi.base.font).dimension('X');
        dh_ = 0;
        if (key_->name == "cdots" || key_->name == "dotsb"
                        || key_->name == "dotsm" || key_->name == "dotsi")
                dh_ = dim.asc / 2;
-       else if (key_->name == "dotsc")
-               dh_ = dim.asc / 4;
-       else if (key_->name == "vdots") {
-               dim.wid = (dim.wid / 2) + 1;
-               dh_ = dim.asc;
-       }
-       else if (key_->name == "ddots" || key_->name == "adots" || key_->name == "iddots")
+       else if (key_->name == "ddots" || key_->name == "adots"
+                       || key_->name == "iddots" || key_->name == "vdots")
                dh_ = dim.asc;
 }
 
 
-void InsetMathDots::draw(PainterInfo & pain, int x, int y) const
+void InsetMathDots::draw(PainterInfo & pi, int x, int y) const
 {
-       Dimension const dim = dimension(*pain.base.bv);
+       Dimension const dim = dimension(*pi.base.bv);
        if (key_->name == "adots" || key_->name == "iddots")
                --y;
-       mathed_draw_deco(pain, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
+       else if (key_->name == "vdots")
+               x += (dim.width() - 2) / 2;
+       mathed_draw_deco(pi, x + 1, y - dh_, dim.width() - 2, dim.ascent(),
                        key_->name);
-       if (key_->name == "vdots" || key_->name == "ddots" || key_->name == "adots" || key_->name == "iddots")
-               ++x;
-       if (key_->name == "adots" || key_->name == "iddots")
-               ++y;
-       else if (key_->name != "vdots")
-               --y;
-       mathed_draw_deco(pain, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
-               key_->name);
-       setPosCache(pain, x, y);
 }
 
 
@@ -80,52 +69,39 @@ docstring InsetMathDots::name() const
 
 void InsetMathDots::validate(LaTeXFeatures & features) const
 {
-       if (!key_->requires.empty())
-               features.require(to_utf8(key_->requires));
+       if (!key_->required.empty())
+               features.require(key_->required);
 }
 
 
-void InsetMathDots::mathmlize(MathStream & os) const
-{
+namespace {
+std::string symbolToXMLEntity(docstring const & n) {
        // which symbols we support is decided by what is listed in
        // lib/symbols as generating a dots inset
-       docstring const & n = key_->name;
-       std::string ent;
        if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
-               ent = "…";
+               return "…";
        else if (n == "adots" || n == "iddots")
-               ent = "⋰";
+               return "⋰";
        else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
-               ent = "⋯";
+               return "⋯";
        else if (n == "ddots")
-               ent = "⋱";
+               return "⋱";
        else if (n == "vdots")
-               ent = "⋮";
-       else
-               LASSERT(false, ent = "…");
-       os << MTag("mi") << from_ascii(ent) << ETag("mi");
+               return "&#x22EE;";
+       else LASSERT(false, return "&#x2026;");
+}
+}
+
+
+void InsetMathDots::mathmlize(MathMLStream & ms) const
+{
+       ms << MTagInline("mi") << from_ascii(symbolToXMLEntity(key_->name)) << ETagInline("mi");
 }
 
 
 void InsetMathDots::htmlize(HtmlStream & os) const
 {
-       // which symbols we support is decided by what is listed in
-       // lib/symbols as generating a dots inset
-       docstring const & n = key_->name;
-       std::string ent;
-       if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
-               ent = "&#x02026;";
-       else if (n == "adots" || n == "iddots")
-               ent = "&#x022F0;";
-       else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
-               ent = "&#x022EF;";
-       else if (n == "ddots")
-               ent = "&#x022F1;";
-       else if (n == "vdots")
-               ent = "&#x022EE;";
-       else
-               LASSERT(false, ent = "#x02026;");
-       os << from_ascii(ent);
+       os << from_ascii(symbolToXMLEntity(key_->name));
 }
 
 } // namespace lyx