#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))
{}
}
+/// 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;
}
}
-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() << ']';
}
-void InsetMathSymbol::mathmlize(MathStream & os) const
+void InsetMathSymbol::mathmlize(MathMLStream & ms) const
{
// FIXME We may need to do more interesting things
// with MathMLtype.
- char const * type = sym_->MathMLtype();
- os << '<' << type << "> ";
- if (sym_->xmlname == "x")
+ docstring tag = from_ascii(ms.namespacedTag(sym_->MathMLtype()));
+ ms << '<' << tag << ">";
+ if ((ms.xmlMode() && sym_->xmlname == "x") || (!ms.xmlMode() && sym_->htmlname == "x"))
// unknown so far
- os << name();
+ ms << name();
+ else if (ms.xmlMode())
+ ms << sym_->xmlname;
else
- os << sym_->xmlname;
- os << " </" << type << '>';
+ ms << sym_->htmlname;
+ ms << "</" << tag << '>';
}
char const * type = sym_->MathMLtype();
bool op = (std::string(type) == "mo");
- if (sym_->xmlname == "x")
+ if (sym_->htmlname == "x")
// unknown so far
os << ' ' << name() << ' ';
else if (op && spacing)
- os << ' ' << sym_->xmlname << ' ';
+ os << ' ' << sym_->htmlname << ' ';
else
- os << sym_->xmlname;
+ os << sym_->htmlname;
}
}
-void InsetMathSymbol::write(WriteStream & os) const
+void InsetMathSymbol::write(TeXMathStream & os) const
{
unique_ptr<MathEnsurer> ensurer;
if (currentMode() != TEXT_MODE)
return;
os.pendingSpace(true);
+ writeLimits(os);
}