2001-12-18 03:16:46 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-08-06 06:23:09 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
#include <cctype>
|
|
|
|
|
2001-08-06 06:23:09 +00:00
|
|
|
#include "math_charinset.h"
|
|
|
|
#include "LColor.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "support/LOstream.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-08-06 06:23:09 +00:00
|
|
|
#include "math_parser.h"
|
|
|
|
#include "debug.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2002-01-18 14:27:54 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2001-08-06 06:23:09 +00:00
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
MathCharInset::MathCharInset(char c)
|
2001-08-30 08:55:13 +00:00
|
|
|
: char_(c), code_(nativeCode(c))
|
2001-08-17 09:48:24 +00:00
|
|
|
{
|
2001-08-17 15:47:02 +00:00
|
|
|
//lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
|
2001-08-17 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 06:23:09 +00:00
|
|
|
MathCharInset::MathCharInset(char c, MathTextCodes t)
|
2001-08-30 08:55:13 +00:00
|
|
|
: char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
|
2001-08-17 15:47:02 +00:00
|
|
|
{
|
|
|
|
//lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
|
|
|
|
}
|
2001-08-06 06:23:09 +00:00
|
|
|
|
|
|
|
|
2002-01-03 13:52:13 +00:00
|
|
|
MathTextCodes MathCharInset::nativeCode(char c)
|
2001-08-17 09:48:24 +00:00
|
|
|
{
|
|
|
|
if (isalpha(c))
|
|
|
|
return LM_TC_VAR;
|
2001-08-28 13:34:04 +00:00
|
|
|
//if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
|
2001-08-17 15:47:02 +00:00
|
|
|
return LM_TC_CONST;
|
2001-08-17 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 06:23:09 +00:00
|
|
|
MathInset * MathCharInset::clone() const
|
|
|
|
{
|
|
|
|
return new MathCharInset(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCharInset::ascent() const
|
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
return mathed_char_ascent(code_, mi_, char_);
|
2001-08-06 06:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCharInset::descent() const
|
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
return mathed_char_descent(code_, mi_, char_);
|
2001-08-06 06:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCharInset::width() const
|
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
return mathed_char_width(code_, mi_, char_);
|
2001-08-06 06:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
void MathCharInset::metrics(MathMetricsInfo const & mi) const
|
2001-08-06 17:20:26 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
mi_ = mi;
|
2001-08-06 17:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCharInset::draw(Painter & pain, int x, int y) const
|
2001-08-06 06:23:09 +00:00
|
|
|
{
|
2001-08-17 15:47:02 +00:00
|
|
|
//lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
|
2001-10-22 15:37:49 +00:00
|
|
|
drawChar(pain, code_, mi_, x, y, char_);
|
2001-08-06 06:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-17 13:18:10 +00:00
|
|
|
void MathCharInset::writeHeader(std::ostream & os) const
|
2001-08-06 06:23:09 +00:00
|
|
|
{
|
2001-11-05 17:08:45 +00:00
|
|
|
if (math_font_name(code_))
|
|
|
|
os << '\\' << math_font_name(code_) << '{';
|
2001-08-17 13:18:10 +00:00
|
|
|
}
|
2001-08-08 15:35:49 +00:00
|
|
|
|
2001-08-06 06:23:09 +00:00
|
|
|
|
2001-08-17 13:18:10 +00:00
|
|
|
void MathCharInset::writeTrailer(std::ostream & os) const
|
|
|
|
{
|
2001-11-05 17:08:45 +00:00
|
|
|
if (math_font_name(code_))
|
2001-08-06 06:23:09 +00:00
|
|
|
os << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-17 13:18:10 +00:00
|
|
|
void MathCharInset::writeRaw(std::ostream & os) const
|
|
|
|
{
|
|
|
|
os << char_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathCharInset::write(WriteStream & os) const
|
2001-08-17 13:18:10 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
writeHeader(os.os());
|
|
|
|
writeRaw(os.os());
|
|
|
|
writeTrailer(os.os());
|
2001-08-17 13:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathCharInset::normalize(NormalStream & os) const
|
2001-08-06 06:23:09 +00:00
|
|
|
{
|
2001-10-24 16:10:38 +00:00
|
|
|
os << "[char " << char_ << " " << "mathalpha" << "]";
|
2001-08-06 06:23:09 +00:00
|
|
|
}
|
2001-08-09 08:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool MathCharInset::isRelOp() const
|
|
|
|
{
|
|
|
|
return char_ == '=' || char_ == '<' || char_ == '>';
|
|
|
|
}
|
2001-08-10 13:17:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathCharInset::handleFont(MathTextCodes t)
|
|
|
|
{
|
|
|
|
code_ = (code_ == t) ? LM_TC_VAR : t;
|
|
|
|
}
|
2001-11-16 09:55:37 +00:00
|
|
|
|
2002-01-18 14:27:54 +00:00
|
|
|
void MathCharInset::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
// Make sure amssymb is put in preamble if Blackboard Bold or
|
|
|
|
// Fraktur used:
|
|
|
|
if ( (code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK) )
|
|
|
|
features.require("amssymb");
|
|
|
|
}
|
2001-11-16 09:55:37 +00:00
|
|
|
|
|
|
|
bool MathCharInset::match(MathInset * p) const
|
|
|
|
{
|
|
|
|
MathCharInset const * q = p->asCharInset();
|
|
|
|
return q && char_ == q->char_ && code_ == q->code_;
|
|
|
|
}
|