2001-07-27 10:08:04 +00:00
|
|
|
#include "math_symbolinset.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-11-09 18:02:20 +00:00
|
|
|
#include "math_parser.h"
|
2001-11-09 14:23:44 +00:00
|
|
|
#include "debug.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
2001-07-27 10:08:04 +00:00
|
|
|
MathSymbolInset::MathSymbolInset(const latexkeys * l)
|
2001-10-31 10:54:34 +00:00
|
|
|
: sym_(l), h_(0)
|
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
2001-11-09 16:27:44 +00:00
|
|
|
MathSymbolInset::MathSymbolInset(const char * name)
|
|
|
|
: sym_(in_word_set(name)), h_(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-27 10:08:04 +00:00
|
|
|
MathInset * MathSymbolInset::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-07-27 10:08:04 +00:00
|
|
|
return new MathSymbolInset(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-30 22:42:26 +00:00
|
|
|
MathTextCodes MathSymbolInset::code() const
|
|
|
|
{
|
|
|
|
switch(sym_->token) {
|
2001-08-31 21:15:57 +00:00
|
|
|
case LM_TK_CMR:
|
|
|
|
return LM_TC_CMR;
|
2001-08-30 22:42:26 +00:00
|
|
|
case LM_TK_CMSY:
|
|
|
|
return LM_TC_CMSY;
|
|
|
|
case LM_TK_CMM:
|
|
|
|
return LM_TC_CMM;
|
|
|
|
case LM_TK_CMEX:
|
|
|
|
return LM_TC_CMEX;
|
|
|
|
case LM_TK_MSA:
|
|
|
|
return LM_TC_MSA;
|
|
|
|
case LM_TK_MSB:
|
|
|
|
return LM_TC_MSB;
|
|
|
|
default:
|
|
|
|
return LM_TC_SYMB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-31 21:15:57 +00:00
|
|
|
|
|
|
|
MathTextCodes MathSymbolInset::code2() const
|
|
|
|
{
|
|
|
|
if (sym_->token == LM_TK_CMEX)
|
|
|
|
return LM_TC_BOLDSYMB;
|
|
|
|
else
|
|
|
|
return LM_TC_SYMB;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 14:23:44 +00:00
|
|
|
string MathSymbolInset::name() const
|
|
|
|
{
|
|
|
|
return sym_->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
mi_ = mi;
|
2001-10-19 17:46:13 +00:00
|
|
|
MathTextCodes c = code();
|
|
|
|
if (sym_->latex_font_id > 0 && math_font_available(c)) {
|
2001-10-22 15:37:49 +00:00
|
|
|
mathed_char_dim(c, mi_, sym_->latex_font_id, ascent_, descent_, width_);
|
2001-10-19 17:46:13 +00:00
|
|
|
if (c == LM_TC_CMEX) {
|
|
|
|
h_ = 4 * descent_ / 5;
|
2001-08-30 22:42:26 +00:00
|
|
|
ascent_ += h_;
|
|
|
|
descent_ -= h_;
|
|
|
|
}
|
2001-10-31 10:54:34 +00:00
|
|
|
} else {
|
|
|
|
if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
|
|
|
|
mathed_char_dim(code2(), mi_, sym_->id, ascent_, descent_, width_);
|
|
|
|
else
|
|
|
|
mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
|
2001-08-30 22:42:26 +00:00
|
|
|
}
|
2001-10-31 10:54:34 +00:00
|
|
|
if (isRelOp())
|
2001-11-09 14:23:44 +00:00
|
|
|
width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathSymbolInset::draw(Painter & pain, int x, int y) const
|
2001-07-12 07:18:29 +00:00
|
|
|
{
|
2001-10-31 10:54:34 +00:00
|
|
|
if (isRelOp())
|
|
|
|
x += mathed_char_width(LM_TC_TEX, mi_, 'I') / 2;
|
2001-08-30 22:42:26 +00:00
|
|
|
MathTextCodes Code = code();
|
|
|
|
if (sym_->latex_font_id > 0 && math_font_available(Code))
|
2001-10-22 15:37:49 +00:00
|
|
|
drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);
|
2001-10-19 11:25:48 +00:00
|
|
|
else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
|
2001-10-22 15:37:49 +00:00
|
|
|
drawChar(pain, code2(), mi_, x, y, sym_->id);
|
2001-08-30 22:42:26 +00:00
|
|
|
else
|
2001-10-22 15:37:49 +00:00
|
|
|
drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-08-09 08:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool MathSymbolInset::isRelOp() const
|
2001-10-31 10:54:34 +00:00
|
|
|
{
|
2001-11-09 18:02:20 +00:00
|
|
|
return sym_->type == "mathrel";
|
2001-08-30 22:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathSymbolInset::isScriptable() const
|
2001-09-11 10:58:17 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
|
2001-09-11 10:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathSymbolInset::takesLimits() const
|
2001-08-30 22:42:26 +00:00
|
|
|
{
|
|
|
|
return sym_->token == LM_TK_CMEX;
|
2001-08-09 08:53:16 +00:00
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
|
|
|
2001-11-09 14:23:44 +00:00
|
|
|
void MathSymbolInset::normalize(NormalStream & os) const
|
|
|
|
{
|
|
|
|
os << "[symbol " << name().c_str() << "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathSymbolInset::maplize(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2001-11-09 14:23:44 +00:00
|
|
|
if (name() == "cdot")
|
2001-11-07 17:30:26 +00:00
|
|
|
os << '*';
|
|
|
|
else
|
2001-11-09 14:23:44 +00:00
|
|
|
os << name().c_str();
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 18:02:20 +00:00
|
|
|
char const * MathMLtype(string const & s)
|
|
|
|
{
|
|
|
|
if (s == "mathop")
|
|
|
|
return "mo";
|
|
|
|
return "mi";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathSymbolInset::mathmlize(MathMLStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2001-11-09 18:02:20 +00:00
|
|
|
char const * type = MathMLtype(sym_->type);
|
2001-11-09 18:55:03 +00:00
|
|
|
os << '<' << type << "> ";
|
|
|
|
if (sym_->xmlname == "x") // unknown so far
|
|
|
|
os << name().c_str();
|
|
|
|
else
|
|
|
|
os << sym_->xmlname.c_str();
|
|
|
|
os << " </" << type << '>';
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathSymbolInset::octavize(OctaveStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2001-11-09 14:23:44 +00:00
|
|
|
if (name() == "cdot")
|
2001-11-07 17:30:26 +00:00
|
|
|
os << '*';
|
|
|
|
else
|
2001-11-09 14:23:44 +00:00
|
|
|
os << name().c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathSymbolInset::write(WriteStream & os) const
|
|
|
|
{
|
|
|
|
os << '\\' << name().c_str() << ' ';
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
|
|
|