2001-07-27 10:08:04 +00:00
|
|
|
#include "math_symbolinset.h"
|
2001-08-09 09:19:18 +00:00
|
|
|
#include "math_parser.h"
|
|
|
|
#include "support.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
2001-02-14 15:00:50 +00:00
|
|
|
using std::ostream;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-07-27 10:08:04 +00:00
|
|
|
MathSymbolInset::MathSymbolInset(const latexkeys * l)
|
2001-08-30 22:42:26 +00:00
|
|
|
: sym_(l), h_(0) {}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
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-07-27 10:08:04 +00:00
|
|
|
void MathSymbolInset::write(ostream & os, bool /* fragile */) const
|
2001-02-28 11:56:36 +00:00
|
|
|
{
|
2001-07-26 15:28:45 +00:00
|
|
|
os << '\\' << sym_->name << ' ';
|
2001-02-28 11:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 10:08:04 +00:00
|
|
|
void MathSymbolInset::writeNormal(ostream & os) const
|
2001-04-25 15:43:57 +00:00
|
|
|
{
|
2001-08-16 12:34:48 +00:00
|
|
|
os << "[" << sym_->name << "] ";
|
2001-04-25 15:43:57 +00:00
|
|
|
}
|
|
|
|
|
2001-07-12 07:18:29 +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-08-06 17:20:26 +00:00
|
|
|
void MathSymbolInset::metrics(MathStyles st) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-08-30 22:42:26 +00:00
|
|
|
size_ = st;
|
|
|
|
MathTextCodes Code = code();
|
|
|
|
if (sym_->latex_font_id > 0 && math_font_available(Code)) {
|
|
|
|
mathed_char_dim(Code, size_, sym_->latex_font_id,
|
|
|
|
ascent_, descent_, width_);
|
|
|
|
if (Code == LM_TC_CMEX) {
|
|
|
|
h_ = 4*descent_/5;
|
|
|
|
ascent_ += h_;
|
|
|
|
descent_ -= h_;
|
|
|
|
}
|
|
|
|
} else if (sym_->id > 0 && sym_->id < 255 &&
|
|
|
|
math_font_available(LM_TC_SYMB)) {
|
2001-08-31 21:15:57 +00:00
|
|
|
mathed_char_dim(code2(), size_, sym_->id,
|
2001-08-30 22:42:26 +00:00
|
|
|
ascent_, descent_, width_);
|
|
|
|
} else {
|
|
|
|
mathed_string_dim(LM_TC_TEX, size_, sym_->name, ascent_, descent_, width_);
|
|
|
|
}
|
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-06-25 00:06:33 +00:00
|
|
|
xo(x);
|
|
|
|
yo(y);
|
2001-08-30 22:42:26 +00:00
|
|
|
MathTextCodes Code = code();
|
|
|
|
if (sym_->latex_font_id > 0 && math_font_available(Code))
|
|
|
|
drawChar(pain, Code, size_, x, y - h_, sym_->latex_font_id);
|
|
|
|
else if (sym_->id > 0 && sym_->id < 255 &&
|
2001-08-31 21:15:57 +00:00
|
|
|
math_font_available(LM_TC_SYMB))
|
|
|
|
drawChar(pain, code2(), size_, x, y, sym_->id);
|
2001-08-30 22:42:26 +00:00
|
|
|
else
|
|
|
|
drawStr(pain, LM_TC_TEX, size_, 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-08-30 22:42:26 +00:00
|
|
|
return sym_->type == LMB_RELATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathSymbolInset::isScriptable() const
|
|
|
|
{
|
|
|
|
return sym_->token == LM_TK_CMEX;
|
2001-08-09 08:53:16 +00:00
|
|
|
}
|