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"
|
|
|
|
#include "mathed/support.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
|
|
|
|
2001-08-17 11:08:55 +00:00
|
|
|
using std::max;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-08-09 15:19:31 +00:00
|
|
|
MathDelimInset::MathDelimInset(latexkeys const * l, latexkeys 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-08-09 15:19:31 +00:00
|
|
|
string MathDelimInset::latexName(latexkeys const * l)
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-08-09 15:19:31 +00:00
|
|
|
//static const string vdelim("(){}[]./|");
|
|
|
|
string name = l->name;
|
|
|
|
if (name == "(")
|
|
|
|
return name;
|
|
|
|
if (name == "[")
|
|
|
|
return name;
|
|
|
|
if (name == ".")
|
|
|
|
return name;
|
|
|
|
if (name == ")")
|
|
|
|
return name;
|
|
|
|
if (name == "]")
|
|
|
|
return name;
|
|
|
|
if (name == "/")
|
|
|
|
return name;
|
|
|
|
if (name == "|")
|
|
|
|
return name;
|
|
|
|
return "\\" + name + " ";
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
2001-08-09 15:19:31 +00:00
|
|
|
void MathDelimInset::write(std::ostream & os, bool fragile) const
|
|
|
|
{
|
|
|
|
os << "\\left" << latexName(left_);
|
|
|
|
cell(0).write(os, fragile);
|
|
|
|
os << "\\right" << latexName(right_);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
int MathDelimInset::dw() const
|
|
|
|
{
|
|
|
|
int w = height() / 5;
|
|
|
|
if (w > 15)
|
|
|
|
w = 15;
|
|
|
|
if (w < 4)
|
|
|
|
w = 4;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathDelimInset::metrics(MathStyles st) const
|
|
|
|
{
|
|
|
|
xcell(0).metrics(st);
|
|
|
|
size_ = st;
|
2001-08-17 09:48:24 +00:00
|
|
|
int a, d, w;
|
|
|
|
mathed_char_dim(LM_TC_VAR, st,'I', a, d, w);
|
|
|
|
int h0 = (a + d) / 2;
|
|
|
|
int a0 = std::max(xcell(0).ascent(), a) - h0;
|
|
|
|
int d0 = std::max(xcell(0).descent(), d) + h0;
|
|
|
|
ascent_ = max(a0, d0) + h0;
|
|
|
|
descent_ = max(a0, d0) - h0;
|
2001-08-15 06:53:25 +00:00
|
|
|
width_ = xcell(0).width() + 2 * dw() + 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-02-15 12:22:01 +00:00
|
|
|
xo(x);
|
|
|
|
yo(y);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-15 07:02:16 +00:00
|
|
|
int const w = dw();
|
|
|
|
int const b = y - ascent_ - 2;
|
2001-08-15 06:53:25 +00:00
|
|
|
xcell(0).draw(pain, x + w + 2, y);
|
2001-09-03 15:22:55 +00:00
|
|
|
mathed_draw_deco(pain, x + 1, b, w, height() + 4, left_->name);
|
|
|
|
mathed_draw_deco(pain, x + width() - w - 1, b, w, height() + 4, right_->name);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|