2 * \file InsetMathFont.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathFont.h"
15 #include "LaTeXFeatures.h"
17 #include "MathStream.h"
18 #include "MathParser.h"
19 #include "MetricsInfo.h"
26 InsetMathFont::InsetMathFont(Buffer * buf, latexkeys const * key)
27 : InsetMathNest(buf, 1), key_(key)
31 Inset * InsetMathFont::clone() const
33 return new InsetMathFont(*this);
37 InsetMath::mode_type InsetMathFont::currentMode() const
39 if (key_->extra == "mathmode")
41 if (key_->extra == "textmode")
43 return UNDECIDED_MODE;
47 bool InsetMathFont::lockedMode() const
49 if (key_->extra == "forcetext")
55 void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
57 FontSetChanger dummy(mi.base, key_->name);
58 cell(0).metrics(mi, dim);
63 void InsetMathFont::draw(PainterInfo & pi, int x, int y) const
65 FontSetChanger dummy(pi.base, key_->name.c_str());
66 cell(0).draw(pi, x + 1, y);
67 drawMarkers(pi, x, y);
68 setPosCache(pi, x, y);
72 void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
76 cell(0).metricsT(mi, dim);
80 void InsetMathFont::drawT(TextPainter & pain, int x, int y) const
82 cell(0).drawT(pain, x, y);
86 docstring InsetMathFont::name() const
92 void InsetMathFont::validate(LaTeXFeatures & features) const
94 InsetMathNest::validate(features);
95 // Make sure amssymb is put in preamble if Blackboard Bold or
97 if (key_->name == "mathfrak" || key_->name == "mathbb")
98 features.require("amssymb");
99 if (key_->name == "text" || key_->name == "textnormal"
100 || (key_->name.length() == 6 && key_->name.substr(0, 4) == "text"))
101 features.require("amstext");
102 if (key_->name == "textipa")
103 features.require("tipa");
104 if (key_->name == "ce" || key_->name == "cf")
105 features.require("mhchem");
109 // The fonts we want to support are listed in lib/symbols
110 void InsetMathFont::mathmlize(MathStream & os) const
112 // FIXME These are not quite right, because they do not nest
113 // correctly. A proper fix would presumably involve tracking
114 // the fonts already in effect.
116 if (key_->name == "mathnormal" || key_->name == "mathrm"
117 || key_->name == "text" || key_->name == "textnormal"
118 || key_->name == "textrm" || key_->name == "textup"
119 || key_->name == "textmd")
121 else if (key_->name == "frak" || key_->name == "mathfrak")
123 else if (key_->name == "mathbb" || key_->name == "mathbf"
124 || key_->name == "textbf")
126 else if (key_->name == "mathcal")
128 else if (key_->name == "mathit" || key_->name == "textsl"
129 || key_->name == "emph")
131 else if (key_->name == "mathsf" || key_->name == "textit"
132 || key_->name == "textsf")
133 variant = "sans-serif";
134 else if (key_->name == "mathtt" || key_->name == "texttt")
135 variant = "monospace";
136 // no support at present for textipa, textsc, noun
138 if (!variant.empty())
139 os << "<mstyle mathvariant='" << from_utf8(variant) << "'>"
140 << cell(0) << "</mstyle>";
144 void InsetMathFont::infoize(odocstream & os) const
146 os << "Font: " << key_->name;