2001-08-17 11:08:55 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_deliminset.h"
|
|
|
|
#include "math_parser.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
#include "math_streamstr.h"
|
2001-11-09 08:35:57 +00:00
|
|
|
#include "math_extern.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-10-29 15:45:24 +00:00
|
|
|
|
2001-09-12 12:51:55 +00:00
|
|
|
MathDelimInset::MathDelimInset(string const & l, string const & r)
|
2001-08-03 17:10:22 +00:00
|
|
|
: MathNestInset(1), left_(l), right_(r)
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathDelimInset::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-02-20 10:49:48 +00:00
|
|
|
return new MathDelimInset(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathDelimInset::write(WriteStream & os) const
|
2001-08-09 15:19:31 +00:00
|
|
|
{
|
2002-02-14 12:38:02 +00:00
|
|
|
os << "\\left" << convertDelimToLatexName(left_) << cell(0)
|
|
|
|
<< "\\right" << convertDelimToLatexName(right_);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathDelimInset::normalize(NormalStream & os) const
|
2001-10-24 16:10:38 +00:00
|
|
|
{
|
2002-02-14 12:38:02 +00:00
|
|
|
os << "[delim " << convertDelimToLatexName(left_) << ' '
|
|
|
|
<< convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
|
2001-10-24 16:10:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
int MathDelimInset::dw() const
|
|
|
|
{
|
|
|
|
int w = height() / 5;
|
2002-02-14 18:21:28 +00:00
|
|
|
if (w > 8)
|
|
|
|
w = 8;
|
2001-08-15 06:53:25 +00:00
|
|
|
if (w < 4)
|
|
|
|
w = 4;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
void MathDelimInset::metrics(MathMetricsInfo const & mi) const
|
2001-08-15 06:53:25 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
xcell(0).metrics(mi);
|
2001-08-17 09:48:24 +00:00
|
|
|
int a, d, w;
|
2001-10-22 15:37:49 +00:00
|
|
|
mathed_char_dim(LM_TC_VAR, mi, 'I', a, d, w);
|
2001-08-17 09:48:24 +00:00
|
|
|
int h0 = (a + d) / 2;
|
|
|
|
int a0 = std::max(xcell(0).ascent(), a) - h0;
|
|
|
|
int d0 = std::max(xcell(0).descent(), d) + h0;
|
2001-11-08 12:06:56 +00:00
|
|
|
ascent_ = std::max(a0, d0) + h0;
|
|
|
|
descent_ = std::max(a0, d0) - h0;
|
2002-02-14 18:21:28 +00:00
|
|
|
width_ = xcell(0).width() + 2 * dw() + 8;
|
2001-08-15 06:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathDelimInset::draw(Painter & pain, int x, int y) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-08-15 07:02:16 +00:00
|
|
|
int const w = dw();
|
2001-10-12 14:05:04 +00:00
|
|
|
int const b = y - ascent_;
|
2002-02-14 18:21:28 +00:00
|
|
|
xcell(0).draw(pain, x + w + 4, y);
|
|
|
|
mathed_draw_deco(pain, x + 4, b, w, height(), left_);
|
|
|
|
mathed_draw_deco(pain, x + width() - w - 4, b, w, height(), right_);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
|
|
|
2001-11-09 10:44:24 +00:00
|
|
|
bool MathDelimInset::isParanthesis() const
|
|
|
|
{
|
|
|
|
return left_ == "(" && right_ == ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathDelimInset::isBrackets() const
|
|
|
|
{
|
|
|
|
return left_ == "[" && right_ == "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathDelimInset::isAbs() const
|
|
|
|
{
|
|
|
|
return left_ == "|" && right_ == "|";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathDelimInset::maplize(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2001-11-09 10:44:24 +00:00
|
|
|
if (isAbs()) {
|
2001-11-09 08:35:57 +00:00
|
|
|
bool mat =
|
|
|
|
cell(0).size() == 1 && cell(0).begin()->nucleus()
|
|
|
|
&& cell(0).begin()->nucleus()->asMatrixInset();
|
|
|
|
if (mat)
|
2001-11-07 17:30:26 +00:00
|
|
|
os << "linalg[det](" << cell(0) << ")";
|
2001-11-07 10:21:51 +00:00
|
|
|
else
|
2001-11-07 17:30:26 +00:00
|
|
|
os << "abs(" << cell(0) << ")";
|
2001-11-07 10:21:51 +00:00
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
else
|
2001-12-05 08:04:20 +00:00
|
|
|
os << left_ << cell(0) << right_;
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
2001-11-07 10:21:51 +00:00
|
|
|
|
2001-11-07 18:15:24 +00:00
|
|
|
|
|
|
|
void MathDelimInset::mathmlize(MathMLStream & os) const
|
|
|
|
{
|
2001-12-05 08:04:20 +00:00
|
|
|
os << "<fenced open=\"" << left_ << "\" close=\""
|
|
|
|
<< right_ << "\">" << cell(0) << "</fenced>";
|
2001-11-07 18:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathDelimInset::octavize(OctaveStream & os) const
|
|
|
|
{
|
2001-11-09 10:44:24 +00:00
|
|
|
if (isAbs())
|
2001-11-07 18:15:24 +00:00
|
|
|
os << "det(" << cell(0) << ")";
|
|
|
|
else
|
2001-12-05 08:04:20 +00:00
|
|
|
os << left_ << cell(0) << right_;
|
2001-11-07 18:15:24 +00:00
|
|
|
}
|