2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathFont.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-05-30 07:09:54 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathFont.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathParser.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathFont::InsetMathFont(Buffer * buf, latexkeys const * key)
|
|
|
|
: InsetMathNest(buf, 1), key_(key)
|
2002-08-01 15:53:46 +00:00
|
|
|
{}
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathFont::clone() const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathFont(*this);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMath::mode_type InsetMathFont::currentMode() const
|
2002-07-18 11:02:33 +00:00
|
|
|
{
|
2002-08-01 11:48:53 +00:00
|
|
|
if (key_->extra == "mathmode")
|
|
|
|
return MATH_MODE;
|
|
|
|
if (key_->extra == "textmode")
|
|
|
|
return TEXT_MODE;
|
|
|
|
return UNDECIDED_MODE;
|
2002-07-18 11:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-03 00:05:58 +00:00
|
|
|
bool InsetMathFont::lockedMode() const
|
|
|
|
{
|
|
|
|
if (key_->extra == "forcetext")
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
FontSetChanger dummy(mi.base, key_->name);
|
2004-01-30 11:41:12 +00:00
|
|
|
cell(0).metrics(mi, dim);
|
|
|
|
metricsMarkers(dim);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFont::draw(PainterInfo & pi, int x, int y) const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
FontSetChanger dummy(pi.base, key_->name.c_str());
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).draw(pi, x + 1, y);
|
2002-06-24 15:37:14 +00:00
|
|
|
drawMarkers(pi, x, y);
|
2005-04-03 07:48:20 +00:00
|
|
|
setPosCache(pi, x, y);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
// FIXME: BROKEN!
|
|
|
|
Dimension dim;
|
|
|
|
cell(0).metricsT(mi, dim);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFont::drawT(TextPainter & pain, int x, int y) const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).drawT(pain, x, y);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring InsetMathFont::name() const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2002-08-01 15:53:46 +00:00
|
|
|
return key_->name;
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFont::validate(LaTeXFeatures & features) const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathNest::validate(features);
|
2010-03-31 18:57:47 +00:00
|
|
|
if (features.runparams().isLaTeX()) {
|
|
|
|
// Make sure amssymb is put in preamble if Blackboard Bold or
|
|
|
|
// Fraktur used:
|
|
|
|
if (key_->name == "mathfrak" || key_->name == "mathbb")
|
|
|
|
features.require("amssymb");
|
|
|
|
if (key_->name == "text" || key_->name == "textnormal"
|
|
|
|
|| (key_->name.length() == 6 && key_->name.substr(0, 4) == "text"))
|
|
|
|
features.require("amstext");
|
|
|
|
if (key_->name == "textipa")
|
|
|
|
features.require("tipa");
|
|
|
|
if (key_->name == "ce" || key_->name == "cf")
|
|
|
|
features.require("mhchem");
|
|
|
|
} else if (features.runparams().math_flavor == OutputParams::MathAsHTML) {
|
|
|
|
features.addPreambleSnippet("<style type=\"text/css\">\n"
|
|
|
|
"span.normal{font: normal normal normal inherit serif;}\n"
|
|
|
|
"span.fraktur{font: normal normal normal inherit cursive;}\n"
|
|
|
|
"span.bold{font: normal normal bold inherit serif;}\n"
|
|
|
|
"span.script{font: normal normal normal inherit cursive;}\n"
|
|
|
|
"span.italic{font: italic normal normal inherit serif;}\n"
|
|
|
|
"span.sans{font: normal normal normal inherit sans-serif;}\n"
|
|
|
|
"span.monospace{font: normal normal normal inherit monospace;}\n"
|
|
|
|
"span.noun{font: normal small-caps normal inherit normal;}\n"
|
|
|
|
"</style>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The fonts we want to support are listed in lib/symbols
|
|
|
|
void InsetMathFont::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
// FIXME These are not quite right, because they do not nest
|
|
|
|
// correctly. A proper fix would presumably involve tracking
|
|
|
|
// the fonts already in effect.
|
|
|
|
std::string variant;
|
|
|
|
docstring const & tag = key_->name;
|
|
|
|
if (tag == "mathnormal" || tag == "mathrm"
|
|
|
|
|| tag == "text" || tag == "textnormal"
|
|
|
|
|| tag == "textrm" || tag == "textup"
|
|
|
|
|| tag == "textmd")
|
|
|
|
variant = "normal";
|
|
|
|
else if (tag == "frak" || tag == "mathfrak")
|
|
|
|
variant = "fraktur";
|
|
|
|
else if (tag == "mathbb" || tag == "mathbf"
|
|
|
|
|| tag == "textbf")
|
|
|
|
variant = "bold";
|
|
|
|
else if (tag == "mathcal")
|
|
|
|
variant == "script";
|
|
|
|
else if (tag == "mathit" || tag == "textsl"
|
|
|
|
|| tag == "emph" || tag == "textit")
|
|
|
|
variant = "italic";
|
|
|
|
else if (tag == "mathsf" || tag == "textsf")
|
|
|
|
variant = "sans";
|
|
|
|
else if (tag == "mathtt" || tag == "texttt")
|
|
|
|
variant = "monospace";
|
|
|
|
else if (tag == "textipa" || tag == "textsc" || tag == "noun")
|
|
|
|
variant = "noun";
|
|
|
|
|
|
|
|
docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4);
|
|
|
|
bool const textmode = (beg == "text");
|
|
|
|
if (!variant.empty()) {
|
|
|
|
SetHTMLMode sm(os, textmode, "class='" + variant + "'");
|
|
|
|
os << cell(0);
|
|
|
|
} else
|
|
|
|
os << cell(0);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 16:59:56 +00:00
|
|
|
// The fonts we want to support are listed in lib/symbols
|
|
|
|
void InsetMathFont::mathmlize(MathStream & os) const
|
|
|
|
{
|
|
|
|
// FIXME These are not quite right, because they do not nest
|
|
|
|
// correctly. A proper fix would presumably involve tracking
|
|
|
|
// the fonts already in effect.
|
|
|
|
std::string variant;
|
2009-12-31 18:38:01 +00:00
|
|
|
docstring const & tag = key_->name;
|
|
|
|
if (tag == "mathnormal" || tag == "mathrm"
|
|
|
|
|| tag == "text" || tag == "textnormal"
|
|
|
|
|| tag == "textrm" || tag == "textup"
|
|
|
|
|| tag == "textmd")
|
2009-12-31 16:59:56 +00:00
|
|
|
variant = "normal";
|
2009-12-31 18:38:01 +00:00
|
|
|
else if (tag == "frak" || tag == "mathfrak")
|
2009-12-31 16:59:56 +00:00
|
|
|
variant = "fraktur";
|
2009-12-31 18:38:01 +00:00
|
|
|
else if (tag == "mathbb" || tag == "mathbf"
|
|
|
|
|| tag == "textbf")
|
2009-12-31 16:59:56 +00:00
|
|
|
variant = "bold";
|
2009-12-31 18:38:01 +00:00
|
|
|
else if (tag == "mathcal")
|
2009-12-31 16:59:56 +00:00
|
|
|
variant == "script";
|
2009-12-31 18:38:01 +00:00
|
|
|
else if (tag == "mathit" || tag == "textsl"
|
2009-12-31 19:35:56 +00:00
|
|
|
|| tag == "emph" || tag == "textit")
|
2009-12-31 16:59:56 +00:00
|
|
|
variant = "italic";
|
2009-12-31 19:35:56 +00:00
|
|
|
else if (tag == "mathsf" || tag == "textsf")
|
2009-12-31 16:59:56 +00:00
|
|
|
variant = "sans-serif";
|
2009-12-31 18:38:01 +00:00
|
|
|
else if (tag == "mathtt" || tag == "texttt")
|
2009-12-31 16:59:56 +00:00
|
|
|
variant = "monospace";
|
|
|
|
// no support at present for textipa, textsc, noun
|
|
|
|
|
2009-12-31 18:38:01 +00:00
|
|
|
docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4);
|
|
|
|
bool const textmode = (beg == "text");
|
|
|
|
if (!variant.empty()) {
|
2010-03-31 18:57:47 +00:00
|
|
|
std::string const attrs = "mathvariant='" + variant + "'";
|
2009-12-31 19:35:56 +00:00
|
|
|
SetMode sm(os, textmode, attrs);
|
|
|
|
os << cell(0);
|
|
|
|
} else
|
2009-12-31 18:38:01 +00:00
|
|
|
os << cell(0);
|
2009-12-31 16:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathFont::infoize(odocstream & os) const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2002-07-17 10:25:33 +00:00
|
|
|
os << "Font: " << key_->name;
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|