2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathSize.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.
|
|
|
|
*/
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathSize.h"
|
2007-11-06 21:45:24 +00:00
|
|
|
|
2010-03-31 20:37:23 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathParser.h"
|
|
|
|
#include "MathStream.h"
|
2010-01-21 20:48:12 +00:00
|
|
|
#include "output_xhtml.h"
|
2004-11-07 13:27:20 +00:00
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
#include "support/convert.h"
|
2014-11-14 17:18:30 +00:00
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "support/lstrings.h"
|
2007-11-06 21:45:24 +00:00
|
|
|
|
2010-01-21 20:48:12 +00:00
|
|
|
#include <string>
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2014-11-14 17:18:30 +00:00
|
|
|
using namespace lyx::support;
|
2010-01-21 20:48:12 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathSize::InsetMathSize(Buffer * buf, latexkeys const * l)
|
2016-11-19 20:25:34 +00:00
|
|
|
: InsetMathNest(buf, 1), key_(l),
|
|
|
|
style_(MathStyle(convert<int>(l->extra)))
|
2001-08-08 17:26:30 +00:00
|
|
|
{}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-06-27 15:33:55 +00:00
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathSize::clone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathSize(*this);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer dummy2 = mi.base.changeEnsureMath();
|
2016-11-19 20:25:34 +00:00
|
|
|
Changer dummy = mi.base.font.changeStyle(style_);
|
2004-01-30 11:41:12 +00:00
|
|
|
cell(0).metrics(mi, dim);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSize::draw(PainterInfo & pi, int x, int y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer dummy2 = pi.base.changeEnsureMath();
|
2016-11-19 20:25:34 +00:00
|
|
|
Changer dummy = pi.base.font.changeStyle(style_);
|
2017-01-06 08:52:10 +00:00
|
|
|
cell(0).draw(pi, x, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSize::write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2001-12-05 08:04:20 +00:00
|
|
|
os << "{\\" << key_->name << ' ' << cell(0) << '}';
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-21 20:48:12 +00:00
|
|
|
// From the MathML documentation:
|
|
|
|
// MathML uses two attributes, displaystyle and scriptlevel, to control
|
|
|
|
// orthogonal presentation features that TeX encodes into one "style"
|
|
|
|
// attribute with values \displaystyle, \textstyle, \scriptstyle, and
|
|
|
|
// \scriptscriptstyle. The corresponding values of displaystyle and scriptlevel
|
|
|
|
// for those TeX styles would be "true" and "0", "false" and "0", "false" and "1",
|
|
|
|
// and "false" and "2", respectively.
|
|
|
|
void InsetMathSize::mathmlize(MathStream & ms) const
|
|
|
|
{
|
|
|
|
string const & name = to_utf8(key_->name);
|
|
|
|
bool dispstyle = (name == "displaystyle");
|
|
|
|
int scriptlevel = 0;
|
|
|
|
if (name == "scriptstyle")
|
|
|
|
scriptlevel = 1;
|
|
|
|
else if (name == "scriptscriptstyle")
|
|
|
|
scriptlevel = 2;
|
|
|
|
stringstream attrs;
|
|
|
|
attrs << "displaystyle='" << (dispstyle ? "true" : "false")
|
|
|
|
<< "' scriptlevel='" << scriptlevel << "'";
|
2016-06-11 04:48:55 +00:00
|
|
|
ms << MTag("mstyle", attrs.str()) << cell(0) << ETag("mstyle");
|
2010-01-21 20:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-31 20:37:23 +00:00
|
|
|
void InsetMathSize::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
string const & name = to_utf8(key_->name);
|
|
|
|
os << MTag("span", "class='" + name + "'")
|
|
|
|
<< cell(0) << ETag("span");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSize::normalize(NormalStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '[' << key_->name << ' ' << cell(0) << ']';
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2002-07-10 06:52:05 +00:00
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathSize::infoize(odocstream & os) const
|
2002-07-10 06:52:05 +00:00
|
|
|
{
|
2014-11-14 17:18:30 +00:00
|
|
|
os << bformat(_("Size: %1$s"), key_->name);
|
2002-07-10 06:52:05 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2010-03-31 20:37:23 +00:00
|
|
|
void InsetMathSize::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
2011-12-06 22:17:13 +00:00
|
|
|
features.addCSSSnippet(
|
2010-03-31 20:37:23 +00:00
|
|
|
"span.displaystyle, span.textstyle{font-size: normal;}\n"
|
|
|
|
"span.scriptstyle {font-size: small;}\n"
|
2011-12-06 22:17:13 +00:00
|
|
|
"span.scriptscriptstyle {font-size: x-small;}");
|
2010-03-31 21:24:16 +00:00
|
|
|
InsetMathNest::validate(features);
|
2010-03-31 20:37:23 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|