]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathSymbol.cpp
Fix bug 5802 (http://bugzilla.lyx.org/show_bug.cgi?id=5802)
[lyx.git] / src / mathed / InsetMathSymbol.cpp
index 52994700c57f8d44b858deb83f748c88d2eeb94d..8a1ba2fd1b4656d763b9d3b88d8ec95ace61058b 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 #include <config.h>
 
 #include "InsetMathSymbol.h"
+
 #include "Dimension.h"
-#include "MathStream.h"
+#include "LaTeXFeatures.h"
+#include "MathAtom.h"
+#include "MathParser.h"
 #include "MathStream.h"
 #include "MathSupport.h"
-#include "MathParser.h"
-#include "MathAtom.h"
-#include "LaTeXFeatures.h"
-#include "debug.h"
 
+#include "support/debug.h"
+#include "support/docstream.h"
 #include "support/textutils.h"
 
-namespace lyx {
-
-using std::string;
-using std::auto_ptr;
 
+namespace lyx {
 
 InsetMathSymbol::InsetMathSymbol(latexkeys const * l)
-       : sym_(l), h_(0), scriptable_(false), font_cache_(Font::ALL_IGNORE)
+       : sym_(l), h_(0), scriptable_(false)
 {}
 
 
 InsetMathSymbol::InsetMathSymbol(char const * name)
-       : sym_(in_word_set(from_ascii(name))), h_(0), scriptable_(false),
-       font_cache_(Font::ALL_IGNORE)
+       : sym_(in_word_set(from_ascii(name))), h_(0), scriptable_(false)
 {}
 
 
 InsetMathSymbol::InsetMathSymbol(docstring const & name)
-       : sym_(in_word_set(name)), h_(0), scriptable_(false), font_cache_(Font::ALL_IGNORE)
+       : sym_(in_word_set(name)), h_(0), scriptable_(false)
 {}
 
 
-auto_ptr<Inset> InsetMathSymbol::doClone() const
+Inset * InsetMathSymbol::clone() const
 {
-       return auto_ptr<Inset>(new InsetMathSymbol(*this));
+       return new InsetMathSymbol(*this);
 }
 
 
@@ -56,45 +53,35 @@ docstring InsetMathSymbol::name() const
 }
 
 
-bool InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        //lyxerr << "metrics: symbol: '" << sym_->name
        //      << "' in font: '" << sym_->inset
        //      << "' drawn as: '" << sym_->draw
-       //      << "'" << std::endl;
-
-       bool dim_unchanged = (mi.base.font == font_cache_);
-       if (dim_unchanged)
-               dim = dim_;
-       else {
-               font_cache_ = mi.base.font;
-               int const em = mathed_char_width(mi.base.font, 'M');
-               FontSetChanger dummy(mi.base, sym_->inset);
-               mathed_string_dim(mi.base.font, sym_->draw, dim);
-               docstring::const_reverse_iterator rit = sym_->draw.rbegin();
-               kerning_ = mathed_char_kerning(mi.base.font, *rit);
-               // correct height for broken cmex and wasy font
-               if (sym_->inset == "cmex" || sym_->inset == "wasy") {
-                       h_ = 4 * dim.des / 5;
-                       dim.asc += h_;
-                       dim.des -= h_;
-               }
-               // seperate things a bit
-               if (isRelOp())
-                       dim.wid += static_cast<int>(0.5 * em + 0.5);
-               else
-                       dim.wid += static_cast<int>(0.1667 * em + 0.5);
-
-               dim_ = dim;
+       //      << "'" << endl;
+
+       int const em = mathed_char_width(mi.base.font, 'M');
+       FontSetChanger dummy(mi.base, sym_->inset);
+       mathed_string_dim(mi.base.font, sym_->draw, dim);
+       docstring::const_reverse_iterator rit = sym_->draw.rbegin();
+       kerning_ = mathed_char_kerning(mi.base.font, *rit);
+       // correct height for broken cmex and wasy font
+       if (sym_->inset == "cmex" || sym_->inset == "wasy") {
+               h_ = 4 * dim.des / 5;
+               dim.asc += h_;
+               dim.des -= h_;
        }
+       // seperate things a bit
+       if (isRelOp())
+               dim.wid += static_cast<int>(0.5 * em + 0.5);
+       else
+               dim.wid += static_cast<int>(0.1667 * em + 0.5);
 
        scriptable_ = false;
        if (mi.base.style == LM_ST_DISPLAY)
                if (sym_->inset == "cmex" || sym_->inset == "esint" ||
                    sym_->extra == "funclim")
                        scriptable_ = true;
-
-       return dim_unchanged;
 }
 
 
@@ -103,7 +90,7 @@ void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
        //lyxerr << "metrics: symbol: '" << sym_->name
        //      << "' in font: '" << sym_->inset
        //      << "' drawn as: '" << sym_->draw
-       //      << "'" << std::endl;
+       //      << "'" << endl;
        int const em = mathed_char_width(pi.base.font, 'M');
        if (isRelOp())
                x += static_cast<int>(0.25*em+0.5);
@@ -219,6 +206,7 @@ void InsetMathSymbol::octave(OctaveStream & os) const
 
 void InsetMathSymbol::write(WriteStream & os) const
 {
+       MathEnsurer ensurer(os);
        os << '\\' << name();
 
        // $,#, etc. In theory the restriction based on catcodes, but then
@@ -233,7 +221,7 @@ void InsetMathSymbol::write(WriteStream & os) const
 
 void InsetMathSymbol::infoize2(odocstream & os) const
 {
-       os << "Symbol: " << name();
+       os << from_ascii("Symbol: ") << name();
 }