2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathBig.cpp
|
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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
2010-03-30 02:04:07 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathSupport.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "MetricsInfo.h"
|
2002-02-14 12:38:02 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
|
|
|
|
2007-11-06 09:30:33 +00:00
|
|
|
#include "support/docstream.h"
|
2006-04-20 09:55:45 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2002-02-14 12:38:02 +00:00
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
|
2002-02-14 12:38:02 +00:00
|
|
|
: name_(name), delim_(delim)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring InsetMathBig::name() const
|
2006-04-20 09:55:45 +00:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathBig::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return 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
|
2010-06-06 00:42:33 +00:00
|
|
|
char_type const c = name_[name_.size() - 1];
|
|
|
|
int const base_size = (c == 'l' || c == 'm' || c == 'r') ? 4 : 3;
|
2006-04-20 09:55:45 +00:00
|
|
|
return name_[0] == 'B' ?
|
2010-06-06 00:42:33 +00:00
|
|
|
2 * (name_.size() - base_size) + 1:
|
|
|
|
2 * (name_.size() - base_size);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-02-14 12:38:02 +00:00
|
|
|
{
|
2006-10-11 17:24:46 +00:00
|
|
|
double const h = theFontMetrics(mi.base.font).ascent('I');
|
2002-07-11 11:27:24 +00:00
|
|
|
double const f = increase();
|
2006-11-28 15:15:49 +00:00
|
|
|
dim.wid = 6;
|
|
|
|
dim.asc = int(h + f * h);
|
|
|
|
dim.des = int(f * h);
|
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
|
|
|
{
|
2007-09-25 07:41:03 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2007-04-11 00:27:35 +00:00
|
|
|
// mathed_draw_deco does not use the leading backslash, so remove it
|
|
|
|
// (but don't use ltrim if this is the backslash delimiter).
|
2006-04-20 09:55:45 +00:00
|
|
|
// Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
|
|
|
|
// would treat it as |.
|
2007-04-11 00:27:35 +00:00
|
|
|
docstring const delim = (delim_ == "\\|") ? from_ascii("Vert") :
|
|
|
|
(delim_ == "\\\\") ? from_ascii("\\") : support::ltrim(delim_, "\\");
|
2007-09-25 07:41:03 +00:00
|
|
|
mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(),
|
2007-05-28 22:27:45 +00:00
|
|
|
delim);
|
2006-04-20 09:55:45 +00:00
|
|
|
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
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2006-10-20 10:43:53 +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
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
os << '[' << name_ << ' ' << delim_ << ']';
|
2002-02-14 12:38:02 +00:00
|
|
|
}
|
2006-04-20 09:55:45 +00:00
|
|
|
|
|
|
|
|
2009-12-31 15:46:39 +00:00
|
|
|
void InsetMathBig::mathmlize(MathStream & os) const
|
2009-12-31 04:16:45 +00:00
|
|
|
{
|
|
|
|
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>";
|
|
|
|
if (delim_ == "(" || delim_ == ")"
|
|
|
|
|| delim_ == "[" || delim_ == "]"
|
|
|
|
|| delim_ == "|" || delim_ == "/")
|
|
|
|
os << delim_;
|
|
|
|
else if (delim_ == "\\{" || delim_ == "\\lbrace")
|
|
|
|
os << "{";
|
|
|
|
else if (delim_ == "\\}" || delim_ == "\\rbrace")
|
|
|
|
os << "}";
|
|
|
|
else if (delim_ == "\\slash")
|
|
|
|
os << "/";
|
|
|
|
else if (delim_ == "\\|" || delim_ == "\\vert")
|
|
|
|
os << "|";
|
|
|
|
else if (delim_ == "\\Vert")
|
|
|
|
os << "∥";
|
|
|
|
else if (delim_ == "\\\\" || delim_ == "\\backslash")
|
|
|
|
os <<" \\";
|
|
|
|
else if (delim_ == "\\langle")
|
|
|
|
os << "<";
|
|
|
|
else if (delim_ == "\\rangle")
|
|
|
|
os << ">";
|
|
|
|
else if (delim_ == "\\lceil")
|
|
|
|
os << "⌈";
|
|
|
|
else if (delim_ == "\\rceil")
|
|
|
|
os << "⌉";
|
|
|
|
else if (delim_ == "\\lfloor")
|
|
|
|
os << "⌊";
|
|
|
|
else if (delim_ == "\\rfloor")
|
|
|
|
os << "⌋";
|
|
|
|
else if (delim_ == "\\downarrow")
|
|
|
|
os << "↓";
|
|
|
|
else if (delim_ == "\\uparrow")
|
|
|
|
os << "↑";
|
|
|
|
else if (delim_ == "\\Downarrow")
|
|
|
|
os << "⇓";
|
|
|
|
else if (delim_ == "\\Uparrow")
|
|
|
|
os << "⇑";
|
|
|
|
else if (delim_ == "\\updownarrow")
|
|
|
|
os << "↕";
|
|
|
|
else if (delim_ == "\\Updownarrow")
|
|
|
|
os << "⇕";
|
|
|
|
os << "</mo>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 02:04:07 +00:00
|
|
|
void InsetMathBig::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
switch (size()) {
|
|
|
|
case 0: case 1: name = "big"; break;
|
|
|
|
case 2: case 3: name = "bigg"; break;
|
|
|
|
case 4: case 5: name = "biggg"; break;
|
|
|
|
default: name = "big"; break;
|
|
|
|
}
|
|
|
|
os << MTag("span", "class='" + name + "symbol'");
|
|
|
|
if (delim_ == "(" || delim_ == ")"
|
|
|
|
|| delim_ == "[" || delim_ == "]"
|
|
|
|
|| delim_ == "|" || delim_ == "/")
|
|
|
|
os << delim_;
|
|
|
|
else if (delim_ == "\\{" || delim_ == "\\lbrace")
|
|
|
|
os << "{";
|
|
|
|
else if (delim_ == "\\}" || delim_ == "\\rbrace")
|
|
|
|
os << "}";
|
|
|
|
else if (delim_ == "\\slash")
|
|
|
|
os << "/";
|
|
|
|
else if (delim_ == "\\|" || delim_ == "\\vert")
|
|
|
|
os << "|";
|
|
|
|
else if (delim_ == "\\Vert")
|
|
|
|
os << "∥";
|
|
|
|
else if (delim_ == "\\\\" || delim_ == "\\backslash")
|
|
|
|
os <<" \\";
|
|
|
|
else if (delim_ == "\\langle")
|
|
|
|
os << "<";
|
|
|
|
else if (delim_ == "\\rangle")
|
|
|
|
os << ">";
|
|
|
|
else if (delim_ == "\\lceil")
|
|
|
|
os << "⌈";
|
|
|
|
else if (delim_ == "\\rceil")
|
|
|
|
os << "⌉";
|
|
|
|
else if (delim_ == "\\lfloor")
|
|
|
|
os << "⌊";
|
|
|
|
else if (delim_ == "\\rfloor")
|
|
|
|
os << "⌋";
|
|
|
|
else if (delim_ == "\\downarrow")
|
|
|
|
os << "↓";
|
|
|
|
else if (delim_ == "\\uparrow")
|
|
|
|
os << "↑";
|
|
|
|
else if (delim_ == "\\Downarrow")
|
|
|
|
os << "⇓";
|
|
|
|
else if (delim_ == "\\Uparrow")
|
|
|
|
os << "⇑";
|
|
|
|
else if (delim_ == "\\updownarrow")
|
|
|
|
os << "↕";
|
|
|
|
else if (delim_ == "\\Updownarrow")
|
|
|
|
os << "⇕";
|
|
|
|
os << ETag("span");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathBig::infoize2(odocstream & os) const
|
2006-04-27 07:55:25 +00:00
|
|
|
{
|
|
|
|
os << name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
bool InsetMathBig::isBigInsetDelim(docstring const & delim)
|
2006-04-20 09:55:45 +00:00
|
|
|
{
|
|
|
|
// mathed_draw_deco must handle these
|
|
|
|
static char const * const delimiters[] = {
|
|
|
|
"(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
|
2007-04-11 00:27:35 +00:00
|
|
|
"|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
|
2010-06-06 18:11:15 +00:00
|
|
|
"<", ">", "\\\\", "\\backslash",
|
2006-04-20 09:55:45 +00:00
|
|
|
"\\langle", "\\lceil", "\\lfloor",
|
|
|
|
"\\rangle", "\\rceil", "\\rfloor",
|
|
|
|
"\\downarrow", "\\Downarrow",
|
|
|
|
"\\uparrow", "\\Uparrow",
|
|
|
|
"\\updownarrow", "\\Updownarrow", ""
|
|
|
|
};
|
2006-10-22 10:15:23 +00:00
|
|
|
return support::findToken(delimiters, to_utf8(delim)) >= 0;
|
2006-04-20 09:55:45 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2010-03-30 02:04:07 +00:00
|
|
|
void InsetMathBig::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2010-03-31 18:24:52 +00:00
|
|
|
if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
2011-12-06 22:17:13 +00:00
|
|
|
features.addCSSSnippet(
|
2010-03-30 02:04:07 +00:00
|
|
|
"span.bigsymbol{font-size: 150%;}\n"
|
|
|
|
"span.biggsymbol{font-size: 200%;}\n"
|
2011-12-06 22:17:13 +00:00
|
|
|
"span.bigggsymbol{font-size: 225%;}");
|
2010-03-30 02:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|