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"
|
2002-03-19 16:55:58 +00:00
|
|
|
#include "textpainter.h"
|
2001-08-06 06:23:09 +00:00
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::ostream;
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
void MathCharInset::metrics(MathMetricsInfo const & mi) const
|
2001-08-06 17:20:26 +00:00
|
|
|
{
|
2002-03-19 16:55:58 +00:00
|
|
|
whichFont(font_, code_, mi);
|
|
|
|
mathed_char_dim(font_, char_, ascent_, descent_, width_);
|
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;
|
2002-03-19 16:55:58 +00:00
|
|
|
drawChar(pain, font_, x, y, char_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCharInset::metrics(TextMetricsInfo const &) const
|
|
|
|
{
|
|
|
|
width_ = 1;
|
|
|
|
ascent_ = 1;
|
|
|
|
descent_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCharInset::draw(TextPainter & pain, int x, int y) const
|
|
|
|
{
|
|
|
|
lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
|
|
|
|
pain.draw(x, y, char_);
|
2001-08-06 06:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
void MathCharInset::writeHeader(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
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
void MathCharInset::writeTrailer(ostream & os) const
|
2001-08-17 13:18:10 +00:00
|
|
|
{
|
2001-11-05 17:08:45 +00:00
|
|
|
if (math_font_name(code_))
|
2001-08-06 06:23:09 +00:00
|
|
|
os << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
void MathCharInset::writeRaw(ostream & os) const
|
2001-08-17 13:18:10 +00:00
|
|
|
{
|
|
|
|
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-02-15 16:06:22 +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:
|
2002-02-16 15:59:55 +00:00
|
|
|
if ((code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK))
|
2002-01-18 14:27:54 +00:00
|
|
|
features.require("amssymb");
|
|
|
|
}
|
2001-11-16 09:55:37 +00:00
|
|
|
|
2002-02-15 16:06:22 +00:00
|
|
|
|
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_;
|
|
|
|
}
|