]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathSupport.cpp
Move <algorithm> from DocIterator.h
[lyx.git] / src / mathed / MathSupport.cpp
index 12f8a842f6aa7fcc70973c92db30523ae73ac421..4f276856e58c8b008c9bb734962ecb62753d166b 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "InsetMathFont.h"
 #include "InsetMathSymbol.h"
-#include "Length.h"
 #include "MathData.h"
 #include "MathFactory.h"
 #include "MathParser.h"
@@ -31,6 +30,7 @@
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/lassert.h"
+#include "support/Length.h"
 #include "support/lyxlib.h"
 
 #include <map>
@@ -577,11 +577,9 @@ void mathed_string_dim(FontInfo const & font,
        frontend::FontMetrics const & fm = theFontMetrics(font);
        dim.asc = 0;
        dim.des = 0;
-       for (docstring::const_iterator it = s.begin();
-            it != s.end();
-            ++it) {
-               dim.asc = max(dim.asc, fm.ascent(*it));
-               dim.des = max(dim.des, fm.descent(*it));
+       for (char_type const c : s) {
+               dim.asc = max(dim.asc, fm.ascent(c));
+               dim.des = max(dim.des, fm.descent(c));
        }
        dim.wid = fm.width(s);
 }
@@ -680,9 +678,9 @@ docstring const &  mathedSymbol(MetricsBase & mb, latexkeys const * sym)
 }
 
 
-void mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
+int mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
 {
-       LASSERT((bool)sym, return);
+       LASSERT((bool)sym, return 0);
        //lyxerr << "metrics: symbol: '" << sym->name
        //      << "' in font: '" << sym->inset
        //      << "' drawn as: '" << sym->draw
@@ -692,8 +690,15 @@ void mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
                sym->extra == "mathalpha" &&
                mb.fontname == "mathit";
        std::string const font = italic_upcase_greek ? "cmm" : sym->inset;
-       Changer dummy = mb.changeFontSet(font);
+       bool const change_font = font != "cmr" ||
+                               (mb.fontname != "mathbb" &&
+                                mb.fontname != "mathds" &&
+                                mb.fontname != "mathfrak" &&
+                                mb.fontname != "mathcal" &&
+                                mb.fontname != "mathscr");
+       Changer dummy = change_font ? mb.changeFontSet(font) : Changer();
        mathed_string_dim(mb.font, mathedSymbol(mb, sym), dim);
+       return mathed_char_kerning(mb.font, mathedSymbol(mb, sym).back());
 }
 
 
@@ -709,8 +714,13 @@ void mathedSymbolDraw(PainterInfo & pi, int x, int y, latexkeys const * sym)
                sym->extra == "mathalpha" &&
                pi.base.fontname == "mathit";
        std::string const font = italic_upcase_greek ? "cmm" : sym->inset;
-
-       Changer dummy = pi.base.changeFontSet(font);
+       bool const change_font = font != "cmr" ||
+                               (pi.base.fontname != "mathbb" &&
+                                pi.base.fontname != "mathds" &&
+                                pi.base.fontname != "mathfrak" &&
+                                pi.base.fontname != "mathcal" &&
+                                pi.base.fontname != "mathscr");
+       Changer dummy = change_font ? pi.base.changeFontSet(font) : Changer();
        pi.draw(x, y, mathedSymbol(pi.base, sym));
 }