]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathFontOld.cpp
Fix wrong mode on output for macros that shadow global macros
[lyx.git] / src / mathed / InsetMathFontOld.cpp
index f4b87ba4c6229dad09254b55423ad550b318892a..11ba283fdf9efc51ed1ff593f82b4441cff257bd 100644 (file)
 #include "InsetMathFontOld.h"
 
 #include "MathData.h"
-#include "MathStream.h"
 #include "MathParser.h"
+#include "MathStream.h"
+#include "MathSupport.h"
 #include "MetricsInfo.h"
 
+#include "support/gettext.h"
+#include "support/lassert.h"
+#include "support/lstrings.h"
+
 #include <ostream>
 
+using namespace lyx::support;
 
 namespace lyx {
 
 InsetMathFontOld::InsetMathFontOld(Buffer * buf, latexkeys const * key)
-       : InsetMathNest(buf, 1), key_(key)
+       : InsetMathNest(buf, 1), key_(key), current_mode_(TEXT_MODE)
 {
        //lock(true);
 }
 
 
+std::string InsetMathFontOld::font() const
+{
+       LASSERT(isAscii(key_->name), return "mathnormal");
+       return to_ascii(key_->name);
+}
+
+
 Inset * InsetMathFontOld::clone() const
 {
        return new InsetMathFontOld(*this);
@@ -37,15 +50,35 @@ Inset * InsetMathFontOld::clone() const
 
 void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       FontSetChanger dummy(mi.base, key_->name.c_str());
+       current_mode_ = isTextFont(mi.base.fontname)
+                               ? TEXT_MODE : MATH_MODE;
+
+       std::string const fontname = current_mode_ == MATH_MODE
+               ? "math" + font() : "text" + font();// I doubt that this still works
+
+       // When \cal is used in text mode, the font is not changed
+       bool really_change_font = fontname != "textcal";
+
+       Changer dummy = really_change_font ? mi.base.changeFontSet(fontname)
+               : Changer();
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
 void InsetMathFontOld::draw(PainterInfo & pi, int x, int y) const
 {
-       FontSetChanger dummy(pi.base, key_->name.c_str());
+       current_mode_ = isTextFont(pi.base.fontname)
+                               ? TEXT_MODE : MATH_MODE;
+
+       std::string const fontname = current_mode_ == MATH_MODE
+               ? "math" + font() : "text" + font();// I doubt that this still works
+
+       // When \cal is used in text mode, the font is not changed
+       bool really_change_font = fontname != "textcal";
+
+       Changer dummy = really_change_font ? pi.base.changeFontSet(fontname)
+               : Changer();
        cell(0).draw(pi, x + 1, y);
        drawMarkers(pi, x, y);
 }
@@ -77,7 +110,7 @@ void InsetMathFontOld::normalize(NormalStream & os) const
 
 void InsetMathFontOld::infoize(odocstream & os) const
 {
-       os << "Font: " << key_->name;
+       os << bformat(_("Font: %1$s"), key_->name);
 }