]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathSymbol.cpp
Substack should not be allowed to change columns
[lyx.git] / src / mathed / InsetMathSymbol.cpp
index 8e98db747ed19a5536a9845c88f2991124788195..291dabb3b9d037e85d1ce57b8ea69dfb7295abc6 100644 (file)
 
 #include "support/debug.h"
 #include "support/docstream.h"
-#include "support/lyxlib.h"
 #include "support/textutils.h"
 #include "support/unique_ptr.h"
 
+using namespace std;
 
 namespace lyx {
 
 InsetMathSymbol::InsetMathSymbol(latexkeys const * l)
-       : sym_(l), h_(0), kerning_(0), scriptable_(false)
+       : sym_(l)
 {}
 
 
 InsetMathSymbol::InsetMathSymbol(char const * name)
-       : sym_(in_word_set(from_ascii(name))), h_(0),
-         kerning_(0), scriptable_(false)
+       : sym_(in_word_set(from_ascii(name)))
 {}
 
 
 InsetMathSymbol::InsetMathSymbol(docstring const & name)
-       : sym_(in_word_set(name)), h_(0), kerning_(0), scriptable_(false)
+       : sym_(in_word_set(name))
 {}
 
 
@@ -58,25 +57,37 @@ docstring InsetMathSymbol::name() const
 }
 
 
+/// The default limits value
+Limits InsetMathSymbol::defaultLimits(bool display) const
+{
+       if (allowsLimitsChange() && sym_->extra != "func" && display)
+               return LIMITS;
+       else
+               return NO_LIMITS;
+}
+
+
 void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        // set dim
-       mathedSymbolDim(mi.base, dim, sym_);
-       // set kerning_
-       kerning_ = mathed_char_kerning(mi.base.font, *sym_->draw.rbegin());
-       // correct height for broken cmex and wasy font
-       if (sym_->inset == "cmex" || sym_->inset == "wasy") {
-               h_ = 4 * dim.des / 5;
+       // FIXME: this should depend on BufferView
+       // set negative kerning_ so that a subscript is moved leftward
+       kerning_ = -mathedSymbolDim(mi.base, dim, sym_);
+       if (sym_->draw != sym_->name) {
+               // align character vertically
+               // FIXME: this should depend on BufferView
+               h_ = 0;
+               if (mathClass() == MC_OP) {
+                       // center the symbol around the fraction axis
+                       // See rule 13 of Appendix G of the TeXbook.
+                       h_ = axis_height(mi.base) + (dim.des - dim.asc) / 2;
+               } else if (sym_->inset == "wasy") {
+                       // correct height for broken wasy font
+                       h_ = 4 * dim.des / 5;
+               }
                dim.asc += h_;
                dim.des -= h_;
        }
-       // set scriptable_
-       scriptable_ = false;
-       if (mi.base.font.style() == DISPLAY_STYLE)
-               if (sym_->inset == "cmex" || sym_->inset == "esint" ||
-                   sym_->extra == "funclim" ||
-                   (sym_->inset == "stmry" && sym_->extra == "mathop"))
-                       scriptable_ = true;
 }
 
 
@@ -107,23 +118,6 @@ MathClass InsetMathSymbol::mathClass() const
 }
 
 
-bool InsetMathSymbol::isScriptable() const
-{
-       return scriptable_;
-}
-
-
-bool InsetMathSymbol::takesLimits() const
-{
-       return
-               sym_->inset == "cmex" ||
-               sym_->inset == "lyxboldsymb" ||
-               sym_->inset == "esint" ||
-               sym_->extra == "funclim" ||
-               (sym_->inset == "stmry" && sym_->extra == "mathop");
-}
-
-
 void InsetMathSymbol::normalize(NormalStream & os) const
 {
        os << "[symbol " << name() << ']';
@@ -162,7 +156,7 @@ void InsetMathSymbol::mathematica(MathematicaStream & os) const
 }
 
 
-void InsetMathSymbol::mathmlize(MathStream & ms) const
+void InsetMathSymbol::mathmlize(MathMLStream & ms) const
 {
        // FIXME We may need to do more interesting things
        // with MathMLtype.
@@ -211,7 +205,7 @@ void InsetMathSymbol::octave(OctaveStream & os) const
 }
 
 
-void InsetMathSymbol::write(WriteStream & os) const
+void InsetMathSymbol::write(TeXMathStream & os) const
 {
        unique_ptr<MathEnsurer> ensurer;
        if (currentMode() != TEXT_MODE)
@@ -227,6 +221,7 @@ void InsetMathSymbol::write(WriteStream & os) const
                return;
 
        os.pendingSpace(true);
+       writeLimits(os);
 }