2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathBig.C
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2002-02-14 12:38:02 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathBig.h"
|
|
|
|
|
#include "MathSupport.h"
|
|
|
|
|
#include "MathMLStream.h"
|
|
|
|
|
#include "MathStream.h"
|
2002-02-14 12:38:02 +00:00
|
|
|
|
|
2006-04-20 09:55:45 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
|
|
|
|
|
2002-02-14 12:38:02 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathBig::InsetMathBig(string const & name, string const & delim)
|
2002-02-14 12:38:02 +00:00
|
|
|
|
: name_(name), delim_(delim)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
string InsetMathBig::name() const
|
2006-04-20 09:55:45 +00:00
|
|
|
|
{
|
|
|
|
|
return name_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetMathBig::doClone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetMathBig(*this));
|
2002-02-14 12:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathBig::size_type InsetMathBig::size() const
|
2002-02-14 12:38:02 +00:00
|
|
|
|
{
|
2006-04-20 09:55:45 +00:00
|
|
|
|
// order: big Big bigg Bigg biggg Biggg
|
|
|
|
|
// 0 1 2 3 4 5
|
|
|
|
|
return name_[0] == 'B' ?
|
|
|
|
|
2 * (name_.size() - 4) + 1:
|
|
|
|
|
2 * (name_.size() - 4);
|
2002-02-14 12:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
double InsetMathBig::increase() const
|
2002-02-14 12:38:02 +00:00
|
|
|
|
{
|
2006-04-20 09:55:45 +00:00
|
|
|
|
// The formula used in amsmath.sty is
|
|
|
|
|
// 1.2 * (1.0 + size() * 0.5) - 1.0.
|
|
|
|
|
// We use a smaller step and a bigger offset because our base size
|
|
|
|
|
// is different.
|
|
|
|
|
return (size() + 1) * 0.3;
|
2002-02-14 12:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-02-14 12:38:02 +00:00
|
|
|
|
{
|
2002-07-11 11:27:24 +00:00
|
|
|
|
double const h = mathed_char_ascent(mi.base.font, 'I');
|
|
|
|
|
double const f = increase();
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid = 6;
|
|
|
|
|
dim_.asc = int(h + f * h);
|
|
|
|
|
dim_.des = int(f * h);
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim = dim_;
|
2002-02-14 12:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2006-04-20 09:55:45 +00:00
|
|
|
|
// mathed_draw_deco does not use the leading backslash, so remove it.
|
|
|
|
|
// Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
|
|
|
|
|
// would treat it as |.
|
|
|
|
|
string const delim = (delim_ == "\\|") ?
|
|
|
|
|
"Vert" :
|
|
|
|
|
lyx::support::ltrim(delim_, "\\");
|
|
|
|
|
mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(),
|
|
|
|
|
delim);
|
|
|
|
|
setPosCache(pi, x, y);
|
2002-02-14 12:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathBig::write(WriteStream & os) const
|
2002-02-14 12:38:02 +00:00
|
|
|
|
{
|
|
|
|
|
os << '\\' << name_ << ' ' << delim_;
|
2006-04-20 09:55:45 +00:00
|
|
|
|
if (delim_[0] == '\\')
|
|
|
|
|
os.pendingSpace(true);
|
2002-02-14 12:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathBig::normalize(NormalStream & os) const
|
2002-02-14 12:38:02 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << name_ << ' ' << delim_ << ']';
|
2002-02-14 12:38:02 +00:00
|
|
|
|
}
|
2006-04-20 09:55:45 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathBig::infoize2(std::ostream & os) const
|
2006-04-27 07:55:25 +00:00
|
|
|
|
{
|
|
|
|
|
os << name_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathBig::isBigInsetDelim(string const & delim)
|
2006-04-20 09:55:45 +00:00
|
|
|
|
{
|
|
|
|
|
// mathed_draw_deco must handle these
|
|
|
|
|
static char const * const delimiters[] = {
|
|
|
|
|
"(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
|
|
|
|
|
"|", "/", "\\|", "\\vert", "\\Vert", "'", "\\backslash",
|
|
|
|
|
"\\langle", "\\lceil", "\\lfloor",
|
|
|
|
|
"\\rangle", "\\rceil", "\\rfloor",
|
|
|
|
|
"\\downarrow", "\\Downarrow",
|
|
|
|
|
"\\uparrow", "\\Uparrow",
|
|
|
|
|
"\\updownarrow", "\\Updownarrow", ""
|
|
|
|
|
};
|
|
|
|
|
return (lyx::support::findToken(delimiters, delim) >= 0);
|
|
|
|
|
}
|